import { defaultThemeCode , ThemeCode , } from "onefx/lib/styletron-react/theme-provider" ; const storeTheme = ( newTheme ) => { try { localStorage . setItem ( "theme" , newTheme ) ; } catch ( err ) { console . error ( err ) ; } } ; export function baseReducer ( initialState = { themeCode : defaultThemeCode } , action ) { if ( action . type === "SET_THEME" ) { const themeCode = action . payload === "light" ? "light" : "dark" ; window . document && window . document . documentElement . setAttribute ( "data-theme" , themeCode ) ; storeTheme ( themeCode ) ; return { ... initialState , themeCode , } ; } if ( ! initialState . themeCode ) { initialState . themeCode = defaultThemeCode ; } return initialState ; } export function actionSetTheme ( themeCode ) { return { type : "SET_THEME" , payload : themeCode , } ; }