Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit ca370ea

Browse files
Merge pull request #76 from thefringeninja/preferences
saving preferred theme
2 parents b4eecb1 + efe0301 commit ca370ea

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: src/themes.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ const actions = {
2424
type: createAction<void>(),
2525
};
2626

27-
const defaultTheme = createTheme('light');
27+
const paletteTypeKey = 'paletteType';
28+
29+
const loadPaletteType = (): PaletteType => {
30+
const type = window.localStorage.getItem(paletteTypeKey);
31+
return type === 'dark' ? 'dark' : 'light';
32+
};
33+
34+
const savePaletteType = (type: PaletteType) =>
35+
window.localStorage.setItem(paletteTypeKey, type);
36+
37+
const defaultTheme = createTheme(loadPaletteType());
2838

2939
interface ThemeState {
3040
theme: Theme;
@@ -41,6 +51,8 @@ const theme$ = createState<ThemeState>(
4151
}),
4252
).map(({ theme }) => theme);
4353

54+
theme$.subscribe(({ palette: { type } }) => savePaletteType(type));
55+
4456
export default {
4557
actions,
4658
defaultTheme,

0 commit comments

Comments
 (0)