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);
15 const action: BulkDeleteChannel = yield take(progressChannel);
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));
24 export default function* watcher(options: RootSagaOptions) {
25 yield takeLeading(emptyTrashIntent.match, emptyTrashWorker, options);