mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-04 13:48:32 -05:00
user pref store tweaks
This commit is contained in:
@@ -5,6 +5,7 @@ import {ApiApi, UserPreference} from "@/openapi";
|
|||||||
import {ref} from "vue";
|
import {ref} from "vue";
|
||||||
|
|
||||||
const DEVICE_SETTINGS_KEY = 'TANDOOR_DEVICE_SETTINGS'
|
const DEVICE_SETTINGS_KEY = 'TANDOOR_DEVICE_SETTINGS'
|
||||||
|
const USER_PREFERENCE_KEY = 'TANDOOR_USER_PREFERENCE'
|
||||||
|
|
||||||
class DeviceSettings {
|
class DeviceSettings {
|
||||||
|
|
||||||
@@ -20,9 +21,18 @@ class DeviceSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useUserPreferenceStore = defineStore('user_preference_store', () => {
|
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 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() {
|
function loadUserSettings() {
|
||||||
console.log('loading user settings from DB')
|
console.log('loading user settings from DB')
|
||||||
let api = new ApiApi()
|
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()
|
loadUserSettings()
|
||||||
|
|
||||||
return {deviceSettings, userSettings}
|
return {deviceSettings, userSettings, loadUserSettings}
|
||||||
})
|
})
|
||||||
|
|
||||||
// enable hot reload for store
|
// enable hot reload for store
|
||||||
|
|||||||
Reference in New Issue
Block a user