diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -1,5 +1,6 @@ // @flow +import { siweAuthActionTypes } from './siwe-actions.js'; import threadWatcher from '../shared/thread-watcher.js'; import type { LogOutResult, @@ -475,6 +476,17 @@ const setAccessTokenActionType = 'SET_ACCESS_TOKEN'; +const logOutSuccessActionsSet: Set = new Set([ + logOutActionTypes.success, + deleteKeyserverAccountActionTypes.success, +]); + +const logInSuccessActionsSet: Set = new Set([ + logInActionTypes.success, + siweAuthActionTypes.success, + registerActionTypes.success, +]); + export { changeUserPasswordActionTypes, changeUserPassword, @@ -506,4 +518,6 @@ updateUserAvatar, resetUserStateActionType, setAccessTokenActionType, + logOutSuccessActionsSet, + logInSuccessActionsSet, }; diff --git a/lib/reducers/loading-reducer.js b/lib/reducers/loading-reducer.js --- a/lib/reducers/loading-reducer.js +++ b/lib/reducers/loading-reducer.js @@ -2,6 +2,10 @@ import _omit from 'lodash/fp/omit.js'; +import { + logOutSuccessActionsSet, + logInSuccessActionsSet, +} from '../actions/user-actions.js'; import type { LoadingStatus } from '../types/loading-types.js'; import type { BaseAction } from '../types/redux-types.js'; import type { ActionTypes } from '../utils/action-utils.js'; @@ -13,10 +17,30 @@ fetchKeyRegistry.add(actionTypes.failed); }; +const logOutActionsPrefixSet: Set = new Set( + Array.from(logOutSuccessActionsSet, actionName => { + const groups = actionName.match(/(.*)_SUCCESS/); + if (groups) { + return groups[1]; + } + return undefined; + }).filter(Boolean), +); + function reduceLoadingStatuses( state: { [key: string]: { [idx: number]: LoadingStatus } }, action: BaseAction, ): { [key: string]: { [idx: number]: LoadingStatus } } { + if (logInSuccessActionsSet.has(action.type)) { + const newState = { ...state }; + for (const key in state) { + if (logOutActionsPrefixSet.has(key)) { + newState[key] = {}; + } + } + state = newState; + } + const startMatch = action.type.match(/(.*)_STARTED/); if (startMatch && fetchKeyRegistry.has(action.type)) { if (!action.loadingInfo || typeof action.loadingInfo !== 'object') { diff --git a/lib/reducers/user-reducer.js b/lib/reducers/user-reducer.js --- a/lib/reducers/user-reducer.js +++ b/lib/reducers/user-reducer.js @@ -17,6 +17,7 @@ setUserSettingsActionTypes, updateUserAvatarActionTypes, resetUserStateActionType, + logInSuccessActionsSet, } from '../actions/user-actions.js'; import { convertUserInfosToReplaceUserOps, @@ -262,7 +263,10 @@ action.type, onStateDifference, ); - if (!_isEqual(state.userInfos)(newUserInfos)) { + if ( + logInSuccessActionsSet.has(action.type) || + !_isEqual(state.userInfos)(newUserInfos) + ) { return [ { userInfos: newUserInfos,