Skip to content

Commit 30f2d29

Browse files
committed
Remember dark mode choice
1 parent c25e842 commit 30f2d29

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

frontend/src/App.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import StoreUpdateCountStatus from "@/components/StoreUpdateCountStatus.vue";
66
import ManualControlView from "@/views/ManualControlView.vue";
77
import ProtocolList from "@/components/protocol/ProtocolList.vue";
88
import {useQuasar} from "quasar";
9+
import {useUiStateStore} from "@/store/uiState";
10+
11+
const uiState = useUiStateStore()
912
1013
const leftDrawerOpen = ref(false)
1114
const toggleLeftDrawer = () => {
@@ -19,6 +22,11 @@ const $q = useQuasar()
1922
const darkMode = computed(() => $q.dark.isActive)
2023
const toggleDarkMode = () => {
2124
$q.dark.toggle()
25+
uiState.darkMode = $q.dark.isActive
26+
}
27+
28+
if (uiState.darkMode !== undefined) {
29+
$q.dark.set(uiState.darkMode)
2230
}
2331
2432
const dev = computed(() => {

frontend/src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {createApp} from 'vue'
22
import App from './App.vue'
3+
import {subscribeToLocalStorage} from "@/store/uiState";
34

45
import {createPinia} from "pinia";
56
import router from './router'
@@ -28,3 +29,5 @@ createApp(App)
2829
}
2930
})
3031
.mount('#app')
32+
33+
subscribeToLocalStorage()

frontend/src/store/uiState/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface UiState {
77
teamDetailsFoulsExpanded: boolean,
88
teamDetailsYellowCardsExpanded: boolean,
99
teamDetailsRedCardsExpanded: boolean,
10+
darkMode?: boolean,
1011
}
1112

1213
export const useUiStateStore = defineStore('uiState', {
@@ -16,6 +17,7 @@ export const useUiStateStore = defineStore('uiState', {
1617
teamDetailsFoulsExpanded: true,
1718
teamDetailsYellowCardsExpanded: true,
1819
teamDetailsRedCardsExpanded: true,
20+
darkMode: undefined,
1921
}
2022
const storedData = localStorage.getItem('ui-state')
2123
if (storedData) {
@@ -25,6 +27,8 @@ export const useUiStateStore = defineStore('uiState', {
2527
},
2628
})
2729

28-
useUiStateStore().$subscribe((mutation: SubscriptionCallbackMutation<UiState>, state: UnwrapRef<UiState>) => {
29-
localStorage.setItem('ui-state', JSON.stringify(state))
30-
})
30+
export function subscribeToLocalStorage() {
31+
useUiStateStore().$subscribe((mutation: SubscriptionCallbackMutation<UiState>, state: UnwrapRef<UiState>) => {
32+
localStorage.setItem('ui-state', JSON.stringify(state))
33+
})
34+
}

0 commit comments

Comments
 (0)