From a2ed259501f58008af4c61321549c83b9b5358e7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 24 Feb 2018 07:49:03 +0900 Subject: [PATCH] :v: --- src/api/endpoints/i/update_home.ts | 9 ++++++ src/api/endpoints/i/update_mobile_home.ts | 9 ++++++ src/web/app/common/define-widget.ts | 24 ++++++++++++--- src/web/app/desktop/views/components/home.vue | 30 ++++++++++++++++++- src/web/app/desktop/views/components/index.ts | 2 ++ src/web/app/mobile/views/pages/home.vue | 18 ++++++++++- 6 files changed, 86 insertions(+), 6 deletions(-) diff --git a/src/api/endpoints/i/update_home.ts b/src/api/endpoints/i/update_home.ts index 5dfb7d7915..394686cbd1 100644 --- a/src/api/endpoints/i/update_home.ts +++ b/src/api/endpoints/i/update_home.ts @@ -3,6 +3,7 @@ */ import $ from 'cafy'; import User from '../../models/user'; +import event from '../../event'; module.exports = async (params, user) => new Promise(async (res, rej) => { // Get 'home' parameter @@ -30,6 +31,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { }); res(); + + event(user._id, 'home_updated', { + home + }); } else { if (id == null && data == null) return rej('you need to set id and data params if home param unset'); @@ -47,5 +52,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { }); res(); + + event(user._id, 'home_updated', { + id, data + }); } }); diff --git a/src/api/endpoints/i/update_mobile_home.ts b/src/api/endpoints/i/update_mobile_home.ts index a87d89cad7..70181431a2 100644 --- a/src/api/endpoints/i/update_mobile_home.ts +++ b/src/api/endpoints/i/update_mobile_home.ts @@ -3,6 +3,7 @@ */ import $ from 'cafy'; import User from '../../models/user'; +import event from '../../event'; module.exports = async (params, user) => new Promise(async (res, rej) => { // Get 'home' parameter @@ -29,6 +30,10 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { }); res(); + + event(user._id, 'mobile_home_updated', { + home + }); } else { if (id == null && data == null) return rej('you need to set id and data params if home param unset'); @@ -46,5 +51,9 @@ module.exports = async (params, user) => new Promise(async (res, rej) => { }); res(); + + event(user._id, 'mobile_home_updated', { + id, data + }); } }); diff --git a/src/web/app/common/define-widget.ts b/src/web/app/common/define-widget.ts index 21821629ad..844603daa3 100644 --- a/src/web/app/common/define-widget.ts +++ b/src/web/app/common/define-widget.ts @@ -21,7 +21,9 @@ export default function(data: { }, data() { return { - props: data.props ? data.props() : {} as T + props: data.props ? data.props() : {} as T, + bakedOldProps: null, + preventSave: false }; }, created() { @@ -33,26 +35,40 @@ export default function(data: { }); } + this.bakeProps(); + this.$watch('props', newProps => { - const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id); + if (this.preventSave) { + this.preventSave = false; + return; + } + if (this.bakedOldProps == JSON.stringify(newProps)) return; + + this.bakeProps(); + if (this.isMobile) { (this as any).api('i/update_mobile_home', { id: this.id, data: newProps }).then(() => { - w.data = newProps; + (this as any).os.i.client_settings.mobile_home.find(w => w.id == this.id).data = newProps; }); } else { (this as any).api('i/update_home', { id: this.id, data: newProps }).then(() => { - w.data = newProps; + (this as any).os.i.client_settings.home.find(w => w.id == this.id).data = newProps; }); } }, { deep: true }); + }, + methods: { + bakeProps() { + this.bakedOldProps = JSON.stringify(this.props); + } } }); } diff --git a/src/web/app/desktop/views/components/home.vue b/src/web/app/desktop/views/components/home.vue index 8a61c378ed..d64d836982 100644 --- a/src/web/app/desktop/views/components/home.vue +++ b/src/web/app/desktop/views/components/home.vue @@ -60,7 +60,7 @@ @@ -124,12 +124,14 @@ export default Vue.extend({ this.connectionId = (this as any).os.stream.use(); this.connection.on('post', this.onStreamPost); + this.connection.on('mobile_home_updated', this.onHomeUpdated); document.addEventListener('visibilitychange', this.onVisibilitychange, false); Progress.start(); }, beforeDestroy() { this.connection.off('post', this.onStreamPost); + this.connection.off('mobile_home_updated', this.onHomeUpdated); (this as any).os.stream.dispose(this.connectionId); document.removeEventListener('visibilitychange', this.onVisibilitychange); }, @@ -152,6 +154,20 @@ export default Vue.extend({ document.title = 'Misskey'; } }, + onHomeUpdated(data) { + if (data.home) { + (this as any).os.i.client_settings.mobile_home = data.home; + this.widgets = data.home; + } else { + const w = (this as any).os.i.client_settings.mobile_home.find(w => w.id == data.id); + if (w != null) { + w.data = data.data; + this.$refs[w.id][0].preventSave = true; + this.$refs[w.id][0].props = w.data; + this.widgets = (this as any).os.i.client_settings.mobile_home; + } + } + }, hint() { alert('ウィジェットを追加/削除したり並べ替えたりできます。ウィジェットを移動するには「三」をドラッグします。ウィジェットを削除するには「x」をタップします。いくつかのウィジェットはタップすることで表示を変更できます。'); },