Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / optimistic / selectors / select-failed-action.ts
blob94ae4c9590a4476bd815f078db4d0f3abf8096eb
1 import type { Maybe } from '@proton/pass/types';
3 import type { OptimisticFailedHistoryItem, WrappedOptimisticState } from '../types';
4 import { isOptimisticHistoryItemWithId } from '../utils/assertions';
6 const selectFailedAction: (
7     optimisticId: string
8 ) => <T extends WrappedOptimisticState = WrappedOptimisticState>(state: T) => Maybe<OptimisticFailedHistoryItem> =
9     (optimisticId) => (state) => {
10         const { optimistic } = state;
11         const { history } = optimistic;
13         const failedHistoryItemIndex = history.findIndex(isOptimisticHistoryItemWithId(optimisticId, { failed: true }));
15         return failedHistoryItemIndex !== -1
16             ? (history[failedHistoryItemIndex] as OptimisticFailedHistoryItem)
17             : undefined;
18     };
20 export default selectFailedAction;