1 import { useSelector } from 'react-redux';
3 import { isTrashed } from '@proton/pass/lib/items/item.predicates';
5 itemsBulkDeleteRequest,
7 itemsBulkRestoreRequest,
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);
36 trashRestoreInFlight ||
38 inBulk(bulkTrashDTO) ||
39 inBulk(bulkMoveDTO) ||
40 inBulk(bulkRestoreDTO) ||