1 import { put, select, take, takeEvery } from 'redux-saga/effects';
4 vaultMoveAllItemsFailure,
5 vaultMoveAllItemsIntent,
6 vaultMoveAllItemsProgress,
7 vaultMoveAllItemsSuccess,
8 } from '@proton/pass/store/actions';
9 import { type BulkMoveItemsChannel, bulkMoveChannel } from '@proton/pass/store/sagas/items/item-bulk-move.saga';
10 import { selectItemsByShareId } from '@proton/pass/store/selectors';
11 import type { RootSagaOptions } from '@proton/pass/store/types';
12 import type { ItemRevision } from '@proton/pass/types';
14 function* moveAllItemsWorker(
15 { onItemsUpdated }: RootSagaOptions,
16 { payload, meta }: ReturnType<typeof vaultMoveAllItemsIntent>
18 const { shareId, content, destinationShareId } = payload;
19 const itemsToMove: ItemRevision[] = yield select(selectItemsByShareId(shareId));
20 const channel = bulkMoveChannel(itemsToMove, destinationShareId);
23 const action: BulkMoveItemsChannel = yield take(channel);
25 if (action.type === 'progress') {
27 vaultMoveAllItemsProgress(meta.request.id, action.progress, {
35 if (action.type === 'done') yield put(vaultMoveAllItemsSuccess(meta.request.id, { content }));
36 if (action.type === 'error') yield put(vaultMoveAllItemsFailure(meta.request.id, payload, action.error));
40 export default function* watcher(options: RootSagaOptions) {
41 yield takeEvery(vaultMoveAllItemsIntent.match, moveAllItemsWorker, options);