From 89461c598f4746287d13dad6fa6d1215cb43c030 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 24 May 2018 05:28:46 +0900 Subject: [PATCH] Refactor --- src/client/app/boot.js | 20 +++-- .../app/desktop/views/components/settings.vue | 13 ++- .../views/components/ui.header.account.vue | 7 +- .../views/components/user-lists-window.vue | 2 +- .../app/desktop/views/pages/welcome.vue | 5 +- .../app/desktop/views/widgets/polls.vue | 2 +- src/client/app/init.ts | 79 +++++++++---------- .../app/mobile/views/components/ui.nav.vue | 7 +- src/client/app/mobile/views/pages/home.vue | 2 +- .../app/mobile/views/pages/settings.vue | 12 ++- src/client/app/mobile/views/pages/user.vue | 2 +- src/client/app/store.ts | 1 + 12 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/client/app/boot.js b/src/client/app/boot.js index da1b64823..7b884c8a5 100644 --- a/src/client/app/boot.js +++ b/src/client/app/boot.js @@ -18,6 +18,14 @@ return; } + //#region Load settings + let settings = null; + const vuex = localStorage.getItem('vuex'); + if (vuex) { + settings = JSON.parse(vuex); + } + //#endregion + // Get the current url information const url = new URL(location.href); @@ -35,10 +43,8 @@ // The default language is English if (!LANGS.includes(lang)) lang = 'en'; - const vuex = localStorage.getItem('vuex'); - if (vuex) { - const data = JSON.parse(vuex); - if (data.device.lang) lang = data.device.lang; + if (settings) { + if (settings.device.lang) lang = settings.device.lang; } //#endregion @@ -68,8 +74,10 @@ } // Dark/Light - if (localStorage.getItem('darkmode') == 'true') { - document.documentElement.setAttribute('data-darkmode', 'true'); + if (settings) { + if (settings.device.darkmode) { + document.documentElement.setAttribute('data-darkmode', 'true'); + } } // Script version diff --git a/src/client/app/desktop/views/components/settings.vue b/src/client/app/desktop/views/components/settings.vue index 3fe09b9ac..dac5fe67c 100644 --- a/src/client/app/desktop/views/components/settings.vue +++ b/src/client/app/desktop/views/components/settings.vue @@ -227,8 +227,7 @@ export default Vue.extend({ version, langs, latestVersion: undefined, - checkingForUpdate: false, - darkmode: localStorage.getItem('darkmode') == 'true' + checkingForUpdate: false }; }, computed: { @@ -246,6 +245,11 @@ export default Vue.extend({ set(value) { this.$store.commit('device/set', { key: 'autoPopout', value }); } }, + darkmode: { + get() { return this.$store.state.device.darkmode; }, + set(value) { this.$store.commit('device/set', { key: 'darkmode', value }); } + }, + enableSounds: { get() { return this.$store.state.device.enableSounds; }, set(value) { this.$store.commit('device/set', { key: 'enableSounds', value }); } @@ -276,11 +280,6 @@ export default Vue.extend({ set(value) { this.$store.commit('device/set', { key: 'enableExperimentalFeatures', value }); } } }, - watch: { - darkmode() { - (this as any)._updateDarkmode_(this.darkmode); - } - }, created() { (this as any).os.getMeta().then(meta => { this.meta = meta; diff --git a/src/client/app/desktop/views/components/ui.header.account.vue b/src/client/app/desktop/views/components/ui.header.account.vue index fd15ea600..f3f653949 100644 --- a/src/client/app/desktop/views/components/ui.header.account.vue +++ b/src/client/app/desktop/views/components/ui.header.account.vue @@ -35,7 +35,7 @@ @@ -99,7 +99,10 @@ export default Vue.extend({ (this as any).os.signout(); }, dark() { - (this as any)._updateDarkmode_(!(this as any)._darkmode_); + this.$store.commit('device/set', { + key: 'darkmode', + value: !this.$store.state.device.darkmode + }); } } }); diff --git a/src/client/app/desktop/views/components/user-lists-window.vue b/src/client/app/desktop/views/components/user-lists-window.vue index 585c0a864..454c725d2 100644 --- a/src/client/app/desktop/views/components/user-lists-window.vue +++ b/src/client/app/desktop/views/components/user-lists-window.vue @@ -2,7 +2,7 @@ %fa:list% リスト -
+
{{ list.title }}
diff --git a/src/client/app/desktop/views/pages/welcome.vue b/src/client/app/desktop/views/pages/welcome.vue index afa0a4810..83c668a9c 100644 --- a/src/client/app/desktop/views/pages/welcome.vue +++ b/src/client/app/desktop/views/pages/welcome.vue @@ -1,11 +1,11 @@ -
+