work on light theme
This commit is contained in:
@ -23,10 +23,12 @@ const initialAuthDataState: AuthDataType = {
|
||||
|
||||
export type SettingsType = {
|
||||
language: string | undefined;
|
||||
theme: string | undefined;
|
||||
};
|
||||
|
||||
const initialSettingsState: SettingsType = {
|
||||
language: undefined,
|
||||
theme: undefined,
|
||||
};
|
||||
|
||||
export type StorePrototype = {
|
||||
@ -44,6 +46,8 @@ export const logOut = createAction("auth/logOut");
|
||||
|
||||
export const setLanguage = createAction<string>("settings/setLanguage");
|
||||
export const loadLanguage = createAction("settings/loadLanguage");
|
||||
export const setTheme = createAction<string>("settings/setTheme");
|
||||
export const loadTheme = createAction("settings/loadTheme");
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
@ -94,6 +98,19 @@ export const store = configureStore({
|
||||
state.language = "en";
|
||||
}
|
||||
});
|
||||
builder.addCase(setTheme, (state, action) => {
|
||||
state.theme = action.payload || "dark";
|
||||
localStorage.setItem("theme", action.payload || "dark");
|
||||
});
|
||||
builder.addCase(loadTheme, (state) => {
|
||||
const theme: string | null = localStorage.getItem("theme");
|
||||
if (theme) {
|
||||
state.theme = theme;
|
||||
} else {
|
||||
const darkThemeMq = window.matchMedia("(prefers-color-scheme: dark)");
|
||||
state.theme = darkThemeMq.matches ? "dark" : "light";
|
||||
}
|
||||
});
|
||||
}),
|
||||
},
|
||||
// Adding the api middleware enables caching, invalidation, polling,
|
||||
|
||||
Reference in New Issue
Block a user