-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(settings): load theme if page was loaded before (#83)
resolves #82
- Loading branch information
1 parent
5e2141b
commit b7c5725
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
Phonebook.Frontend/src/migration/migrations/3/migration3.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { migration3 } from './migration3'; | ||
|
||
const APPSTATE_KEY: string = 'appstate'; | ||
|
||
describe('Migration: 3', () => { | ||
it(migration3.name, () => { | ||
localStorage.setItem( | ||
APPSTATE_KEY, | ||
`{"serviceWorkerNotificationDisplayed":false,"version":"1.0.0","displayedNotificationVersion":1,"sendFeedback":false}` | ||
); | ||
migration3.script(); | ||
expect(localStorage.getItem(APPSTATE_KEY)).toEqual( | ||
`{"serviceWorkerNotificationDisplayed":false,"version":"1.0.0","displayedNotificationVersion":1,"sendFeedback":false,"activeTheme":"magenta_light_theme"}` | ||
); | ||
}); | ||
|
||
it('shoud do no harm if data is already migrated', () => { | ||
const alreadyMigratedString = `{"serviceWorkerNotificationDisplayed":false,"version":"1.0.0","displayedNotificationVersion":1,"sendFeedback":false,"activeTheme":"blue_dark_theme"}`; | ||
localStorage.setItem(APPSTATE_KEY, alreadyMigratedString); | ||
migration3.script(); | ||
expect(localStorage.getItem(APPSTATE_KEY)).toEqual(alreadyMigratedString); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
Phonebook.Frontend/src/migration/migrations/3/migration3.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Migration } from 'src/migration/Migration'; | ||
|
||
const APPSTATE_KEY: string = 'appstate'; | ||
export const migration3: Migration = { | ||
name: 'Add activeTheme Property to AppState', | ||
id: 3, | ||
script: () => { | ||
const appStateString = localStorage.getItem(APPSTATE_KEY); | ||
if (appStateString) { | ||
const appState: any = JSON.parse(appStateString); | ||
if (appState.activeTheme === undefined) { | ||
const newAppState = { | ||
...appState, | ||
activeTheme: 'magenta_light_theme' | ||
}; | ||
localStorage.setItem(APPSTATE_KEY, JSON.stringify(newAppState)); | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './1/migration1'; | ||
export * from './2/migration2'; | ||
export * from './3/migration3'; |