Projekt

Obecné

Profil

Stáhnout (906 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 0d90d67b Vaclav Honzik
import { createSlice } from '@reduxjs/toolkit'
2
import { persistReducer } from 'redux-persist'
3
import storage from 'redux-persist/lib/storage'
4
import { PaletteMode } from '@mui/material'
5
6 558a15d4 Vaclav Honzik
// State of the theme - controls whether the theme is dark or light
7 0d90d67b Vaclav Honzik
export interface ThemeState {
8
    paletteMode: PaletteMode
9
}
10
11
const persistConfig = {
12
    key: 'theme',
13
    storage, // localStorage for browsers
14
}
15
16
const initialState: ThemeState = {
17
    paletteMode: 'light',
18
}
19
20
const themeSlice = createSlice({
21
    name: 'theme',
22
    initialState,
23
    reducers: {
24 558a15d4 Vaclav Honzik
        toggleTheme: (state: any) => ({
25 0d90d67b Vaclav Honzik
            ...state,
26
            paletteMode: state.paletteMode === 'light' ? 'dark' : 'light',
27
        }),
28
    },
29
})
30
31
const themeReducer = persistReducer(persistConfig, themeSlice.reducer)
32
// const themeReducer = themeSlice.reducer
33
export const { toggleTheme } = themeSlice.actions
34
export default themeReducer