Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / vaults / trash-empty.saga.ts
blob8a731f4e1d3e329d50a1b547e072664d5f63d0d5
1 import { put, select, take, takeLeading } from 'redux-saga/effects';
3 import { emptyTrashFailure, emptyTrashIntent, emptyTrashProgress, emptyTrashSuccess } from '@proton/pass/store/actions';
4 import { type BulkDeleteChannel, bulkDeleteChannel } from '@proton/pass/store/sagas/items/item-bulk-delete.saga';
5 import { selectTrashedItems } from '@proton/pass/store/selectors';
6 import type { RootSagaOptions } from '@proton/pass/store/types';
7 import type { ItemRevision } from '@proton/pass/types';
9 function* emptyTrashWorker({ onItemsUpdated }: RootSagaOptions, { meta }: ReturnType<typeof emptyTrashIntent>) {
10     const requestId = meta.request.id;
11     const trashedItems: ItemRevision[] = yield select(selectTrashedItems);
12     const progressChannel = bulkDeleteChannel(trashedItems);
14     while (true) {
15         const action: BulkDeleteChannel = yield take(progressChannel);
16         onItemsUpdated?.();
18         if (action.type === 'progress') yield put(emptyTrashProgress(requestId, action.progress, action.data));
19         if (action.type === 'done') yield put(emptyTrashSuccess(requestId));
20         if (action.type === 'error') yield put(emptyTrashFailure(requestId, action.error));
21     }
24 export default function* watcher(options: RootSagaOptions) {
25     yield takeLeading(emptyTrashIntent.match, emptyTrashWorker, options);