Projekt

Obecné

Profil

Stáhnout (1.04 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { createSlice } from '@reduxjs/toolkit'
2
import persistReducer from 'redux-persist/es/persistReducer'
3
import storage from 'redux-persist/lib/storage'
4

    
5
export interface NavigationState {
6
    selectedMenuItem?: string, // which item is selected
7
    open: boolean, // whether the menu is open
8
}
9

    
10
// persist navigation bar in local storage
11
const persistConfig = {
12
    key: 'navigation',
13
    storage
14
}
15

    
16
const initialState: NavigationState = {
17
    selectedMenuItem: '',
18
    open: false
19
}
20

    
21
export const navigationSlice = createSlice({
22
    name: 'navigation',
23
    initialState,
24
    reducers: {
25
        setSelectedMenuItem: (state: NavigationState, action: any) => ({...state, selectedMenuItem: action.payload}),
26

    
27
        /**
28
         * Sets the navigation menu open
29
         */
30
        setOpen: (state: NavigationState, action: any) => ({...state, open: action.payload}),
31
    }
32
})
33

    
34
const navigationReducer = persistReducer(persistConfig, navigationSlice.reducer)
35

    
36
export const { setSelectedMenuItem, setOpen } = navigationSlice.actions
37

    
38
export default navigationReducer
(4-4/4)