Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / vaults / trash-restore.saga.ts
blob0a47769073a57081ad8020b27b35e94fc020a734
1 import { put, select, take, takeLeading } from 'redux-saga/effects';
3 import {
4     restoreTrashFailure,
5     restoreTrashIntent,
6     restoreTrashProgress,
7     restoreTrashSuccess,
8 } from '@proton/pass/store/actions';
9 import { type BulkRestoreChannel, bulkRestoreChannel } from '@proton/pass/store/sagas/items/item-bulk-restore.saga';
10 import { selectTrashedItems } from '@proton/pass/store/selectors';
11 import type { RootSagaOptions } from '@proton/pass/store/types';
12 import type { ItemRevision } from '@proton/pass/types';
14 function* restoreTrash({ onItemsUpdated }: RootSagaOptions, { meta }: ReturnType<typeof restoreTrashIntent>) {
15     const requestId = meta.request.id;
16     const trashedItems: ItemRevision[] = yield select(selectTrashedItems);
17     const progressChannel = bulkRestoreChannel(trashedItems);
19     while (true) {
20         const action: BulkRestoreChannel = yield take(progressChannel);
21         onItemsUpdated?.();
23         if (action.type === 'progress') yield put(restoreTrashProgress(requestId, action.progress, action.data));
24         if (action.type === 'done') yield put(restoreTrashSuccess(requestId));
25         if (action.type === 'error') yield put(restoreTrashFailure(requestId, action.error));
26     }
29 export default function* watcher(options: RootSagaOptions) {
30     yield takeLeading(restoreTrashIntent.match, restoreTrash, options);