diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js --- a/native/redux/redux-setup.js +++ b/native/redux/redux-setup.js @@ -49,6 +49,7 @@ import { persistConfig, setPersistor } from './persist.js'; import { processDBStoreOperations } from './redux-utils.js'; import type { AppState } from './state-types.js'; +import reduceGlobalThemeInfo from './theme-reducer.js'; import { defaultNavInfo } from '../navigation/default-state.js'; import { getGlobalNavContext } from '../navigation/icky-global.js'; import { activeMessageListSelector } from '../navigation/nav-selectors.js'; @@ -213,6 +214,11 @@ return state; } + state = { + ...state, + globalThemeInfo: reduceGlobalThemeInfo(state.globalThemeInfo, action), + }; + if (action.type === setCustomServer) { return { ...state, @@ -246,13 +252,8 @@ connectivity: action.payload, }; } else if (action.type === updateThemeInfoActionType) { - return { - ...state, - globalThemeInfo: { - ...state.globalThemeInfo, - ...action.payload, - }, - }; + // Handled above by reduceGlobalThemeInfo + return state; } else if (action.type === updateDeviceCameraInfoActionType) { return { ...state, diff --git a/native/redux/theme-reducer.js b/native/redux/theme-reducer.js new file mode 100644 --- /dev/null +++ b/native/redux/theme-reducer.js @@ -0,0 +1,47 @@ +// @flow + +import { siweAuthActionTypes } from 'lib/actions/siwe-actions.js'; +import { + logOutActionTypes, + deleteAccountActionTypes, + logInActionTypes, + registerActionTypes, +} from 'lib/actions/user-actions.js'; +import { setNewSessionActionType } from 'lib/utils/action-utils.js'; + +import { updateThemeInfoActionType, type Action } from './action-types.js'; +import { + type GlobalThemeInfo, + defaultGlobalThemeInfo, +} from '../types/themes.js'; + +export default function reduceGlobalThemeInfo( + state: GlobalThemeInfo, + action: Action, +): GlobalThemeInfo { + if ( + action.type === logInActionTypes.success || + action.type === siweAuthActionTypes.success || + action.type === registerActionTypes.success + ) { + return defaultGlobalThemeInfo; + } else if ( + action.type === setNewSessionActionType && + action.payload.sessionChange.currentUserInfo && + action.payload.sessionChange.currentUserInfo.anonymous + ) { + return defaultGlobalThemeInfo; + } else if ( + action.type === logOutActionTypes.started || + action.type === logOutActionTypes.success || + action.type === deleteAccountActionTypes.success + ) { + return defaultGlobalThemeInfo; + } else if (action.type === updateThemeInfoActionType) { + return { + ...state, + ...action.payload, + }; + } + return state; +}