Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / vaults / vault-move-all-items.saga.ts
blob2878fc532c0d5f845194f5c0ba59c04bacd48e16
1 import { put, select, take, takeEvery } from 'redux-saga/effects';
3 import {
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>
17 ) {
18     const { shareId, content, destinationShareId } = payload;
19     const itemsToMove: ItemRevision[] = yield select(selectItemsByShareId(shareId));
20     const channel = bulkMoveChannel(itemsToMove, destinationShareId);
22     while (true) {
23         const action: BulkMoveItemsChannel = yield take(channel);
25         if (action.type === 'progress') {
26             yield put(
27                 vaultMoveAllItemsProgress(meta.request.id, action.progress, {
28                     ...action.data,
29                     destinationShareId,
30                 })
31             );
32             onItemsUpdated?.();
33         }
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));
37     }
40 export default function* watcher(options: RootSagaOptions) {
41     yield takeEvery(vaultMoveAllItemsIntent.match, moveAllItemsWorker, options);