Skip to content

Commit

Permalink
🐛 Fixes applying local themes to multi-pages (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Jun 30, 2022
1 parent a2442c7 commit ebf9c1f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/Settings/ThemeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export default {
* Updates store, which will in turn update theme through watcher
*/
themeChanged() {
this.$store.commit(Keys.SET_THEME, this.selectedTheme);
const pageId = this.$store.state.currentConfigInfo?.pageId || null;
this.$store.commit(Keys.SET_THEME, { theme: this.selectedTheme, pageId });
this.updateTheme(this.selectedTheme);
},
/* Returns the initial theme */
Expand Down
12 changes: 11 additions & 1 deletion src/mixins/HomeMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const HomeMixin = {
watch: {
async $route() {
await this.getConfigForRoute();
this.setTheme();
},
},
methods: {
Expand All @@ -52,8 +53,17 @@ const HomeMixin = {
this.$store.commit(Keys.USE_MAIN_CONFIG);
}
},
/* TEMPORARY: If on sub-page, check if custom theme is set and return it */
getSubPageTheme() {
if (!this.pageId || this.pageId === 'home') {
return null;
} else {
const themeStoreKey = `${localStorageKeys.THEME}-${this.pageId}`;
return localStorage[themeStoreKey] || null;
}
},
setTheme() {
const theme = GetTheme();
const theme = this.getSubPageTheme() || GetTheme();
ApplyLocalTheme(theme);
ApplyCustomVariables(theme);
},
Expand Down
15 changes: 12 additions & 3 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ const store = new Vuex.Store({
return state.remoteConfig.pages || [];
},
theme(state) {
return localStorage[localStorageKeys.THEME] || state.config.appConfig.theme;
let localTheme = null;
if (state.currentConfigInfo?.pageId) {
const themeStoreKey = `${localStorageKeys.THEME}-${state.currentConfigInfo?.pageId}`;
localTheme = localStorage[themeStoreKey];
} else {
localTheme = localStorage[localStorageKeys.THEME];
}
return localTheme || state.config.appConfig.theme;
},
webSearch(state, getters) {
return getters.appConfig.webSearch || {};
Expand Down Expand Up @@ -268,11 +275,13 @@ const store = new Vuex.Store({
config.sections = applyItemId(config.sections);
state.config = config;
},
[SET_THEME](state, theme) {
[SET_THEME](state, themOps) {
const { theme, pageId } = themOps;
const newConfig = { ...state.config };
newConfig.appConfig.theme = theme;
state.config = newConfig;
localStorage.setItem(localStorageKeys.THEME, theme);
const themeStoreKey = pageId ? `${localStorageKeys.THEME}-${pageId}` : localStorageKeys.THEME;
localStorage.setItem(themeStoreKey, theme);
InfoHandler('Theme updated', InfoKeys.VISUAL);
},
[SET_CUSTOM_COLORS](state, customColors) {
Expand Down

0 comments on commit ebf9c1f

Please sign in to comment.