1 import { put, select, take, takeLeading } from 'redux-saga/effects';
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);
20 const action: BulkRestoreChannel = yield take(progressChannel);
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));
29 export default function* watcher(options: RootSagaOptions) {
30 yield takeLeading(restoreTrashIntent.match, restoreTrash, options);