Skip to content

Commit

Permalink
use default setting value if value is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Ray committed Jul 18, 2023
1 parent 1808a2c commit dc760bf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/app/contexts/SettingsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,21 @@ export const SettingsProvider = ({

values.forEach((kv) => {
const [key, value] = kv
const typedKey = key as keyof ISettings

if (typeof value !== 'string') return

let parsedValue
try {
parsedValue = JSON.parse(value)
} catch (e) {
parsedValue = value
if (value === 'undefined') {
parsedValue = (defaultSettings as ISettings)[typedKey]
} else {
parsedValue = value
}
}

const typedKey = key as keyof ISettings
parsedSettings[typedKey] = parsedValue
})

Expand Down

0 comments on commit dc760bf

Please sign in to comment.