Merge branch 'fix-typo-drive' into 'main'
[ProtonMail-WebClient.git] / packages / pass / hooks / useBulkInFlight.ts
blobd666fc7e4e5e241f6d9fa185132b4d6799e18022
1 import { useSelector } from 'react-redux';
3 import { isTrashed } from '@proton/pass/lib/items/item.predicates';
4 import {
5     itemsBulkDeleteRequest,
6     itemsBulkMoveRequest,
7     itemsBulkRestoreRequest,
8     itemsBulkTrashRequest,
9     trashEmptyRequest,
10     trashRestoreRequest,
11     vaultMoveAllItemsRequest,
12 } from '@proton/pass/store/actions/requests';
13 import { selectRequestInFlight, selectRequestInFlightData } from '@proton/pass/store/selectors';
14 import type { BulkSelectionDTO, ItemRevision, MaybeNull, SelectedItem } from '@proton/pass/types';
16 type BulkRequestDTO = { selected: BulkSelectionDTO };
18 const bulkSelectionContains =
19     ({ shareId, itemId }: SelectedItem) =>
20     (dto: MaybeNull<BulkRequestDTO>) =>
21         dto?.selected?.[shareId]?.[itemId] ?? false;
23 export const useBulkInFlight = (item: ItemRevision) => {
24     const bulkMoveDTO = useSelector(selectRequestInFlightData<BulkRequestDTO>(itemsBulkMoveRequest()));
25     const bulkTrashDTO = useSelector(selectRequestInFlightData<BulkRequestDTO>(itemsBulkTrashRequest()));
26     const bulkRestoreDTO = useSelector(selectRequestInFlightData<BulkRequestDTO>(itemsBulkRestoreRequest()));
27     const bulkRemoveDTO = useSelector(selectRequestInFlightData<BulkRequestDTO>(itemsBulkDeleteRequest()));
29     const trashed = isTrashed(item);
30     const trashEmptyInFlight = useSelector(selectRequestInFlight(trashEmptyRequest())) && trashed;
31     const trashRestoreInFlight = useSelector(selectRequestInFlight(trashRestoreRequest())) && trashed;
32     const vaultMoveInFlight = Boolean(useSelector(selectRequestInFlight(vaultMoveAllItemsRequest(item.shareId))));
34     const inBulk = bulkSelectionContains(item);
36     return (
37         trashEmptyInFlight ||
38         trashRestoreInFlight ||
39         vaultMoveInFlight ||
40         inBulk(bulkTrashDTO) ||
41         inBulk(bulkMoveDTO) ||
42         inBulk(bulkRestoreDTO) ||
43         inBulk(bulkRemoveDTO)
44     );