Skip to content

Commit

Permalink
fix: allow UI settings to persist (#21)
Browse files Browse the repository at this point in the history
UI settings were being overwritten on refresh. Changing this check
appears to resolve this issue and allows for the UI settings to persist.
  • Loading branch information
pbui committed Jul 26, 2023
1 parent 7ec2bc4 commit d696e2e
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,12 @@ const defaultSettings: Settings = {

export const userSettings = writable(defaultSettings)

function mergeObjects<T>(obj1: any, obj2: any): T {
for (let prop in obj2) {
if (!(prop in obj1) || obj1[prop] == null || obj2[prop] == '') {
obj1[prop] = obj2[prop]
}
}
return obj1
}

if (typeof window != 'undefined') {
let oldUserSettings = JSON.parse(
localStorage.getItem('settings') ?? JSON.stringify(defaultSettings)
)

userSettings.set(mergeObjects<Settings>(oldUserSettings, defaultSettings))
userSettings.set({...defaultSettings, ...oldUserSettings})
}

userSettings.subscribe((settings) => {
Expand Down

0 comments on commit d696e2e

Please sign in to comment.