From be99dc09022d5bb068292936d3f6be3db1969493 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Nov 2017 04:39:07 +0900 Subject: [PATCH] #907 --- src/web/app/desktop/mixins/index.js | 1 + src/web/app/desktop/mixins/widget.js | 27 ++++++++++++ .../desktop/tags/home-widgets/activity.tag | 26 +++++------- .../app/desktop/tags/home-widgets/channel.tag | 31 ++++---------- .../app/desktop/tags/home-widgets/server.tag | 36 +++++++--------- .../desktop/tags/home-widgets/slideshow.tag | 42 +++++++------------ 6 files changed, 75 insertions(+), 88 deletions(-) create mode 100644 src/web/app/desktop/mixins/widget.js diff --git a/src/web/app/desktop/mixins/index.js b/src/web/app/desktop/mixins/index.js index a7a3eb948..e0c94ec5e 100644 --- a/src/web/app/desktop/mixins/index.js +++ b/src/web/app/desktop/mixins/index.js @@ -1 +1,2 @@ require('./user-preview'); +require('./widget'); diff --git a/src/web/app/desktop/mixins/widget.js b/src/web/app/desktop/mixins/widget.js new file mode 100644 index 000000000..d21811fa2 --- /dev/null +++ b/src/web/app/desktop/mixins/widget.js @@ -0,0 +1,27 @@ +import * as riot from 'riot'; + +// ミックスインにオプションを渡せないのアレ +// SEE: https://github.com/riot/riot/issues/2434 + +riot.mixin('widget', { + init: function() { + this.mixin('i'); + this.mixin('api'); + + this.id = this.opts.id; + + Object.keys(this.data).forEach(prop => { + this.data[prop] = this.opts.data.hasOwnProperty(prop) ? this.opts.data[prop] : this.data[prop]; + }); + }, + + save: function() { + this.api('i/update_home', { + id: this.id, + data: this.data + }).then(() => { + this.I.client_settings.home.find(w => w.id == this.id).data = this.data; + this.I.update(); + }); + } +}); diff --git a/src/web/app/desktop/tags/home-widgets/activity.tag b/src/web/app/desktop/tags/home-widgets/activity.tag index 00cf4ea20..9c4eeb615 100644 --- a/src/web/app/desktop/tags/home-widgets/activity.tag +++ b/src/web/app/desktop/tags/home-widgets/activity.tag @@ -2,8 +2,8 @@

%i18n:desktop.tags.mk-activity-home-widget.title%

%i18n:common.loading%

- - + + diff --git a/src/web/app/desktop/tags/home-widgets/channel.tag b/src/web/app/desktop/tags/home-widgets/channel.tag index 2c2b6e7fe..e663dd315 100644 --- a/src/web/app/desktop/tags/home-widgets/channel.tag +++ b/src/web/app/desktop/tags/home-widgets/channel.tag @@ -44,28 +44,25 @@ @@ -139,10 +128,6 @@ this.channel = null; this.posts = []; - this.on('mount', () => { - - }); - this.on('unmount', () => { if (this.connection) { this.connection.off('post', this.onPost); diff --git a/src/web/app/desktop/tags/home-widgets/server.tag b/src/web/app/desktop/tags/home-widgets/server.tag index f4e38aea5..5fcaa9b7d 100644 --- a/src/web/app/desktop/tags/home-widgets/server.tag +++ b/src/web/app/desktop/tags/home-widgets/server.tag @@ -2,12 +2,12 @@

%i18n:desktop.tags.mk-server-home-widget.title%

%i18n:common.loading%

- - - - - - + + + + + +