fix: zen mode on refresh
This commit is contained in:
parent
680b3493b3
commit
bef1371516
5 changed files with 18 additions and 14 deletions
|
@ -2,10 +2,8 @@ import type { Ref } from 'vue'
|
|||
import type { FeatureFlags, UserSettings, WellnessSettings } from './definition'
|
||||
import { STORAGE_KEY_SETTINGS } from '~/constants'
|
||||
|
||||
export const useUserSettings = () => {
|
||||
if (process.server)
|
||||
return useState('user-settings', getDefaultUserSettings)
|
||||
return useUserLocalStorage(STORAGE_KEY_SETTINGS, getDefaultUserSettings)
|
||||
export function useUserSettings() {
|
||||
return useUserLocalStorage<UserSettings>(STORAGE_KEY_SETTINGS, getDefaultUserSettings)
|
||||
}
|
||||
|
||||
// TODO: refactor & simplify this
|
||||
|
|
|
@ -277,7 +277,10 @@ interface UseUserLocalStorageCache {
|
|||
/**
|
||||
* Create reactive storage for the current user
|
||||
*/
|
||||
export function useUserLocalStorage<T extends object>(key: string, initial: () => T) {
|
||||
export function useUserLocalStorage<T extends object>(key: string, initial: () => T): Ref<T> {
|
||||
if (process.server)
|
||||
return shallowRef(initial())
|
||||
|
||||
// @ts-expect-error bind value to the function
|
||||
const map: Map<string, UseUserLocalStorageCache> = useUserLocalStorage._ = useUserLocalStorage._ || new Map()
|
||||
|
||||
|
@ -296,7 +299,7 @@ export function useUserLocalStorage<T extends object>(key: string, initial: () =
|
|||
map.set(key, { scope, value: value! })
|
||||
}
|
||||
|
||||
return map.get(key)!.value
|
||||
return map.get(key)!.value as Ref<T>
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue