From 6959f8663215cc0b4642b26c21db52a938cb3ced Mon Sep 17 00:00:00 2001 From: kwicxy Date: Thu, 29 May 2025 22:46:02 +0800 Subject: [PATCH] feat: Using `localStorage` to remember user's theme setting. --- dashboard/src/config.ts | 11 ++++++++++- dashboard/src/plugins/vuetify.ts | 2 +- dashboard/src/stores/customizer.ts | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dashboard/src/config.ts b/dashboard/src/config.ts index d7739aea..9f70123a 100644 --- a/dashboard/src/config.ts +++ b/dashboard/src/config.ts @@ -7,12 +7,21 @@ export type ConfigProps = { inputBg: boolean; }; +function checkUITheme() { + const theme = localStorage.getItem("uiTheme"); + console.log('memorized theme: ', theme); + if (!theme || !(['PurpleTheme', 'PurpleThemeDark'].includes(theme))) { + localStorage.setItem("uiTheme", "PurpleTheme"); + return 'PurpleTheme'; + } else return theme; +} + const config: ConfigProps = { Sidebar_drawer: true, Customizer_drawer: false, mini_sidebar: false, fontTheme: 'Roboto', - uiTheme: 'PurpleTheme', + uiTheme: checkUITheme(), inputBg: false }; diff --git a/dashboard/src/plugins/vuetify.ts b/dashboard/src/plugins/vuetify.ts index 1ff7767f..0f004ad6 100644 --- a/dashboard/src/plugins/vuetify.ts +++ b/dashboard/src/plugins/vuetify.ts @@ -3,7 +3,7 @@ import '@mdi/font/css/materialdesignicons.css'; import * as components from 'vuetify/components'; import * as directives from 'vuetify/directives'; import { PurpleTheme } from '@/theme/LightTheme'; -import {PurpleThemeDark} from "@/theme/DarkTheme"; +import { PurpleThemeDark } from "@/theme/DarkTheme"; export default createVuetify({ components, diff --git a/dashboard/src/stores/customizer.ts b/dashboard/src/stores/customizer.ts index 0b9d808f..4c6cc721 100644 --- a/dashboard/src/stores/customizer.ts +++ b/dashboard/src/stores/customizer.ts @@ -25,6 +25,7 @@ export const useCustomizerStore = defineStore({ }, SET_UI_THEME(payload: string) { this.uiTheme = payload; + localStorage.setItem("uiTheme", payload); }, } });