Skip to content

Commit

Permalink
feat(localStorage): add merge defaults function for user settings sto…
Browse files Browse the repository at this point in the history
…rage
  • Loading branch information
rudnovd committed Mar 5, 2024
1 parent c8e5e87 commit 6f85ca1
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/utils/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ interface DemoLocalStorage {
step: string | null
}

export const userSettingsStorage = useLocalStorage<UserSettingsLocalStorage>('user-settings', {
locale: getBrowserLocale(),
autoUpdateApp: true,
offlineMode: false,
items: {
standardTagsLocale: getBrowserLocale(),
export const userSettingsStorage = useLocalStorage<UserSettingsLocalStorage>(
'user-settings',
{
locale: getBrowserLocale(),
autoUpdateApp: true,
offlineMode: false,
items: {
standardTagsLocale: getBrowserLocale(),
},
},
{
mergeDefaults(storageValue: Partial<UserSettingsLocalStorage>, defaults) {
return {
autoUpdateApp: storageValue?.autoUpdateApp ?? defaults.autoUpdateApp,
locale: storageValue?.locale ?? defaults.locale,
offlineMode: storageValue?.offlineMode ?? defaults.offlineMode,
items: {
standardTagsLocale: storageValue.items?.standardTagsLocale ?? defaults.items.standardTagsLocale,
},
}
},
},
})
)

export const demoStorage = useLocalStorage<Partial<DemoLocalStorage>>(
'demo',
Expand Down

0 comments on commit 6f85ca1

Please sign in to comment.