Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / hooks / useBulkInFlight.ts
blob8d7a248c955bf6c6e1c6f4364fe92278d4905a0d
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 const bulkSelectionContains =
17     ({ shareId, itemId }: SelectedItem) =>
18     (dto: MaybeNull<BulkSelectionDTO>) =>
19         dto?.[shareId]?.[itemId] ?? false;
21 export const useBulkInFlight = (item: ItemRevision) => {
22     const bulkMoveDTO = useSelector(selectRequestInFlightData<BulkSelectionDTO>(itemsBulkMoveRequest()));
23     const bulkTrashDTO = useSelector(selectRequestInFlightData<BulkSelectionDTO>(itemsBulkTrashRequest()));
24     const bulkRestoreDTO = useSelector(selectRequestInFlightData<BulkSelectionDTO>(itemsBulkRestoreRequest()));
25     const bulkRemoveDTO = useSelector(selectRequestInFlightData<BulkSelectionDTO>(itemsBulkDeleteRequest()));
27     const trashed = isTrashed(item);
28     const trashEmptyInFlight = useSelector(selectRequestInFlight(trashEmptyRequest())) && trashed;
29     const trashRestoreInFlight = useSelector(selectRequestInFlight(trashRestoreRequest())) && trashed;
30     const vaultMoveInFlight = Boolean(useSelector(selectRequestInFlight(vaultMoveAllItemsRequest(item.shareId))));
32     const inBulk = bulkSelectionContains(item);
34     return (
35         trashEmptyInFlight ||
36         trashRestoreInFlight ||
37         vaultMoveInFlight ||
38         inBulk(bulkTrashDTO) ||
39         inBulk(bulkMoveDTO) ||
40         inBulk(bulkRestoreDTO) ||
41         inBulk(bulkRemoveDTO)
42     );