fix: allow UI settings to persist (#21)

UI settings were being overwritten on refresh. Changing this check
appears to resolve this issue and allows for the UI settings to persist.
This commit is contained in:
Peter Bui authored and GitHub committed 2023-07-26 09:27:02 -07:00
1 parent 7ec2bc47d5
commit d696e2ee00
1 file changed
+1 -10
+1 -10
View File
@@ -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) => {