Skip to content

Commit

Permalink
fix(sdk): use settings from SDK when there is no preexisting persiste…
Browse files Browse the repository at this point in the history
…d data
  • Loading branch information
jeremyckahn committed Oct 27, 2023
1 parent 9b6a13a commit 51737da
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/Bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,26 +125,40 @@ function Bootstrap({
PersistedStorageKeys.USER_SETTINGS
)

let configFromSdk = {}

try {
const computeUserSettings = async (): Promise<UserSettings> => {
if (queryParams.has(QueryParamKeys.GET_SDK_CONFIG)) {
configFromSdk = await getConfigFromSdk()
try {
const configFromSdk = await getConfigFromSdk()

return {
...userSettings,
...persistedUserSettings,
...configFromSdk,
}
} catch (e) {
console.error(
'Chitchatter configuration from parent frame could not be loaded'
)
}

return userSettings
}
} catch (e) {
console.error(
'Chitchatter configuration from parent frame could not be loaded'
)

if (persistedUserSettings) {
return {
...userSettings,
...persistedUserSettings,
}
}

return userSettings
}

if (persistedUserSettings) {
setUserSettings({
...userSettings,
...persistedUserSettings,
...configFromSdk,
})
} else {
await persistUserSettings(userSettings)
const computedUserSettings = await computeUserSettings()
setUserSettings(computedUserSettings)

if (persistedUserSettings === null) {
await persistUserSettings(computedUserSettings)
}

setHasLoadedSettings(true)
Expand Down

0 comments on commit 51737da

Please sign in to comment.