From 5b3445a5b585d8c3210cd5c517e2ed655e8223d2 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sat, 20 Jul 2024 13:47:39 +0200 Subject: [PATCH] user pref store tweaks --- vue3/src/stores/UserPreferenceStore.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/vue3/src/stores/UserPreferenceStore.ts b/vue3/src/stores/UserPreferenceStore.ts index c5aec1857..5d6d84c36 100644 --- a/vue3/src/stores/UserPreferenceStore.ts +++ b/vue3/src/stores/UserPreferenceStore.ts @@ -5,6 +5,7 @@ import {ApiApi, UserPreference} from "@/openapi"; import {ref} from "vue"; const DEVICE_SETTINGS_KEY = 'TANDOOR_DEVICE_SETTINGS' +const USER_PREFERENCE_KEY = 'TANDOOR_USER_PREFERENCE' class DeviceSettings { @@ -20,9 +21,18 @@ class DeviceSettings { } export const useUserPreferenceStore = defineStore('user_preference_store', () => { + /** + * settings only saved on device to allow per device customization + */ let deviceSettings = useStorage(DEVICE_SETTINGS_KEY, {} as DeviceSettings) - let userSettings = ref({} as UserPreference) + /** + * database user settings, cache in local storage in case application is started offline + */ + let userSettings = useStorage(USER_PREFERENCE_KEY, {} as UserPreference) + /** + * retrieve user settings from DB + */ function loadUserSettings() { console.log('loading user settings from DB') let api = new ApiApi() @@ -37,9 +47,10 @@ export const useUserPreferenceStore = defineStore('user_preference_store', () => }) } + // always load user settings on first initialization of store loadUserSettings() - return {deviceSettings, userSettings} + return {deviceSettings, userSettings, loadUserSettings} }) // enable hot reload for store