Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / applications / drive / src / app / components / FileBrowser / state / useSelection.tsx
blob128b121037f25aa05cbd6997ef1ea67cdf1e0773
1 import type { ReactNode } from 'react';
2 import { createContext, useContext } from 'react';
4 import type { SelectionState } from '../hooks/useSelectionControls';
5 import { useSelectionControls } from '../hooks/useSelectionControls';
6 import type { BrowserItemId } from '../interface';
8 interface SelectionFunctions {
9     selectedItemIds: BrowserItemId[];
10     toggleSelectItem: (id: BrowserItemId) => void;
11     toggleAllSelected: () => void;
12     selectItem: (id: BrowserItemId) => void;
13     clearSelections: () => void;
14     toggleRange: (selectedBrowserItemId: BrowserItemId) => void;
15     isSelected: (linkId: string) => boolean;
16     selectionState: SelectionState;
19 const SelectionContext = createContext<SelectionFunctions | null>(null);
21 interface Props {
22     itemIds: string[];
23     children: ReactNode;
26 export function SelectionProvider({ itemIds, children }: Props) {
27     const selectionFunction = useSelectionControls({ itemIds });
29     return <SelectionContext.Provider value={selectionFunction}>{children}</SelectionContext.Provider>;
32 export function useSelection() {
33     const state = useContext(SelectionContext);
34     if (!state) {
35         return null;
36     }
37     return state;