From d26cf165631e709c2c5a1035d4a68906c040f69c Mon Sep 17 00:00:00 2001 From: Michele Dalle Rive Date: Mon, 12 Dec 2022 14:15:23 +0100 Subject: [PATCH] Frontend: Added persistent themes. --- client/src/App.vue | 5 +++-- client/src/components/AppSettings.vue | 1 + client/src/store/index.js | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/client/src/App.vue b/client/src/App.vue index 71862496..dbd0e3b7 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -39,8 +39,9 @@ export default { this.$vuetify.theme.themes.light = themes[theme]; }, }, - created() { - this.setTheme('blue'); + async created() { + await this.$store.restored; + this.setTheme(this.$store.getters.theme || 'blue'); }, }; diff --git a/client/src/components/AppSettings.vue b/client/src/components/AppSettings.vue index 3c3d7f93..bd617f46 100644 --- a/client/src/components/AppSettings.vue +++ b/client/src/components/AppSettings.vue @@ -68,6 +68,7 @@ export default { methods: { setTheme(theme) { this.$vuetify.theme.themes.light = themesObject[theme]; + this.$store.commit('setTheme', { theme }); }, }, }; diff --git a/client/src/store/index.js b/client/src/store/index.js index 13f6e69c..c3d79514 100644 --- a/client/src/store/index.js +++ b/client/src/store/index.js @@ -10,6 +10,7 @@ const vuexLocal = new VuexPersistence({ // Only save the state of the module 'auth' isLoggedIn: state.isLoggedIn, user: state.user, + theme: state.theme, }), asyncStorage: true, }); @@ -22,6 +23,7 @@ export default new Vuex.Store({ user: null, socket: null, activeChat: null, + theme: null, }, getters: { isLoggedIn: (state) => state.isLoggedIn, @@ -29,6 +31,7 @@ export default new Vuex.Store({ socket: (state) => state.socket, activeChat: (state) => state.activeChat, isMobile: () => window.innerWidth < 600, + theme: (state) => state.theme, }, mutations: { login(state, { user }) { @@ -48,6 +51,9 @@ export default new Vuex.Store({ setActiveChat(state, { chat }) { state.activeChat = chat; }, + setTheme(state, { theme }) { + state.theme = theme; + }, }, actions: { login({ commit }, { username, password }) {