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 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);
38 trashRestoreInFlight ||
40 inBulk(bulkTrashDTO) ||
41 inBulk(bulkMoveDTO) ||
42 inBulk(bulkRestoreDTO) ||