Changeset View
Changeset View
Standalone View
Standalone View
web/redux/redux-setup.js
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
} from './action-types.js'; | } from './action-types.js'; | ||||
import { reduceCommunityPickerStore } from './community-picker-reducer.js'; | import { reduceCommunityPickerStore } from './community-picker-reducer.js'; | ||||
import { defaultWebState } from './default-state.js'; | import { defaultWebState } from './default-state.js'; | ||||
import reduceNavInfo from './nav-reducer.js'; | import reduceNavInfo from './nav-reducer.js'; | ||||
import { onStateDifference } from './redux-debug-utils.js'; | import { onStateDifference } from './redux-debug-utils.js'; | ||||
import { reduceServicesAccessToken } from './services-access-token-reducer.js'; | import { reduceServicesAccessToken } from './services-access-token-reducer.js'; | ||||
import { getVisibility } from './visibility.js'; | import { getVisibility } from './visibility.js'; | ||||
import { activeThreadSelector } from '../selectors/nav-selectors.js'; | import { activeThreadSelector } from '../selectors/nav-selectors.js'; | ||||
import { processDBStoreOperations } from '../shared-worker/utils/store.js'; | |||||
import type { InitialReduxState } from '../types/redux-types.js'; | import type { InitialReduxState } from '../types/redux-types.js'; | ||||
export type WindowDimensions = { width: number, height: number }; | export type WindowDimensions = { width: number, height: number }; | ||||
export type CommunityPickerStore = { | export type CommunityPickerStore = { | ||||
+chat: ?string, | +chat: ?string, | ||||
+calendar: ?string, | +calendar: ?string, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | for (const keyserverID in keyserverInfos) { | ||||
keyserverInfo: { | keyserverInfo: { | ||||
...state.keyserverStore.keyserverInfos[keyserverID], | ...state.keyserverStore.keyserverInfos[keyserverID], | ||||
...keyserverInfos[keyserverID], | ...keyserverInfos[keyserverID], | ||||
actualizedCalendarQuery, | actualizedCalendarQuery, | ||||
}, | }, | ||||
}, | }, | ||||
}); | }); | ||||
} | } | ||||
return validateStateAndProcessDBOperations( | return validateStateAndQueueOpsProcessing( | ||||
action, | action, | ||||
oldState, | oldState, | ||||
{ | { | ||||
...state, | ...state, | ||||
...rest, | ...rest, | ||||
userStore: { userInfos }, | userStore: { userInfos }, | ||||
keyserverStore: keyserverStoreOpsHandlers.processStoreOperations( | keyserverStore: keyserverStoreOpsHandlers.processStoreOperations( | ||||
state.keyserverStore, | state.keyserverStore, | ||||
replaceOperations, | replaceOperations, | ||||
), | ), | ||||
initialStateLoaded: true, | initialStateLoaded: true, | ||||
}, | }, | ||||
{ | { | ||||
...storeOperations, | ...storeOperations, | ||||
keyserverStoreOperations: [ | keyserverStoreOperations: [ | ||||
...storeOperations.keyserverStoreOperations, | ...storeOperations.keyserverStoreOperations, | ||||
...replaceOperations, | ...replaceOperations, | ||||
], | ], | ||||
}, | }, | ||||
); | ); | ||||
} else if (action.type === updateWindowDimensionsActionType) { | } else if (action.type === updateWindowDimensionsActionType) { | ||||
return validateStateAndProcessDBOperations( | return validateStateAndQueueOpsProcessing( | ||||
action, | action, | ||||
oldState, | oldState, | ||||
{ | { | ||||
...state, | ...state, | ||||
windowDimensions: action.payload, | windowDimensions: action.payload, | ||||
}, | }, | ||||
storeOperations, | storeOperations, | ||||
); | ); | ||||
} else if (action.type === updateWindowActiveActionType) { | } else if (action.type === updateWindowActiveActionType) { | ||||
return validateStateAndProcessDBOperations( | return validateStateAndQueueOpsProcessing( | ||||
action, | action, | ||||
oldState, | oldState, | ||||
{ | { | ||||
...state, | ...state, | ||||
windowActive: action.payload, | windowActive: action.payload, | ||||
}, | }, | ||||
storeOperations, | storeOperations, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | state = { | ||||
), | ), | ||||
communityPickerStore, | communityPickerStore, | ||||
commServicesAccessToken: reduceServicesAccessToken( | commServicesAccessToken: reduceServicesAccessToken( | ||||
state.commServicesAccessToken, | state.commServicesAccessToken, | ||||
action, | action, | ||||
), | ), | ||||
}; | }; | ||||
return validateStateAndProcessDBOperations( | return validateStateAndQueueOpsProcessing( | ||||
action, | action, | ||||
oldState, | oldState, | ||||
state, | state, | ||||
storeOperations, | storeOperations, | ||||
); | ); | ||||
} | } | ||||
function validateStateAndProcessDBOperations( | function validateStateAndQueueOpsProcessing( | ||||
action: Action, | action: Action, | ||||
oldState: AppState, | oldState: AppState, | ||||
state: AppState, | state: AppState, | ||||
storeOperations: StoreOperations, | storeOperations: StoreOperations, | ||||
): AppState { | ): AppState { | ||||
const updateActiveThreadOps: ThreadStoreOperation[] = []; | const updateActiveThreadOps: ThreadStoreOperation[] = []; | ||||
if ( | if ( | ||||
(state.navInfo.activeChatThreadID && | (state.navInfo.activeChatThreadID && | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | ): AppState { | ||||
// The operations were already dispatched from the main tab | // The operations were already dispatched from the main tab | ||||
// For now the `dispatchSource` field is not included in any of the | // For now the `dispatchSource` field is not included in any of the | ||||
// redux actions and this causes flow to throw an error. | // redux actions and this causes flow to throw an error. | ||||
// As soon as one of the actions is updated, this fix (and the corresponding | // As soon as one of the actions is updated, this fix (and the corresponding | ||||
// one in tab-synchronization.js) can be removed. | // one in tab-synchronization.js) can be removed. | ||||
// $FlowFixMe | // $FlowFixMe | ||||
if (action.dispatchSource !== 'tab-sync') { | if (action.dispatchSource === 'tab-sync') { | ||||
state = { | return state; | ||||
...state, | |||||
dbOpsStore: queueDBOps( | |||||
state.dbOpsStore, | |||||
action.messageID, | |||||
storeOperations, | |||||
), | |||||
}; | |||||
void processDBStoreOperations( | |||||
storeOperations, | |||||
state.currentUserInfo?.id ?? null, | |||||
); | |||||
} | } | ||||
return state; | return { | ||||
...state, | |||||
dbOpsStore: queueDBOps(state.dbOpsStore, action.messageID, storeOperations), | |||||
}; | |||||
} | } | ||||
export { nonUserSpecificFieldsWeb, reducer }; | export { nonUserSpecificFieldsWeb, reducer }; |