1 import type { Action, Reducer } from 'redux';
3 import { popupTabStateGarbageCollect, popupTabStateSave } from '@proton/pass/store/actions/creators/popup';
4 import type { ItemFilters, MaybeNull, SelectedItem, TabId } from '@proton/pass/types';
5 import { objectDelete } from '@proton/pass/utils/object/delete';
6 import { merge } from '@proton/pass/utils/object/merge';
8 export type PopupTabState = {
10 domain: MaybeNull<string>;
11 search: MaybeNull<string>;
12 selectedItem: MaybeNull<SelectedItem>;
15 export type PopupState = {
16 tabs: { [tabId: TabId]: PopupTabState };
17 filters: MaybeNull<ItemFilters>;
20 const getInitialState = (): PopupState => ({ tabs: {}, filters: null });
22 const popupReducer: Reducer<PopupState> = (state = getInitialState(), action: Action) => {
23 if (popupTabStateSave.match(action)) {
25 filters: action.payload.filters ?? state.filters,
27 [action.payload.tabId]: action.payload,
32 if (popupTabStateGarbageCollect.match(action)) {
35 tabs: action.payload.tabIds.reduce<PopupState['tabs']>(
36 (acc, tabId) => objectDelete(acc, tabId),
45 export default popupReducer;