mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-05 05:46:24 -04:00
* Fix renaming * Hide rename context menu in media view * Alert to user if rename fails --------- Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com>
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { ReactNode, RefObject, createContext, useContext } from 'react';
|
|
import { ExplorerItem } from '@sd/client';
|
|
|
|
export type ExplorerViewSelection = number | number[];
|
|
|
|
export interface ExplorerViewContext<T extends ExplorerViewSelection = ExplorerViewSelection> {
|
|
items: ExplorerItem[] | null;
|
|
scrollRef: RefObject<HTMLDivElement>;
|
|
selected?: T;
|
|
onSelectedChange?: (selected: ExplorerViewSelectionChange<T>) => void;
|
|
overscan?: number;
|
|
onLoadMore?: () => void;
|
|
rowsBeforeLoadMore?: number;
|
|
top?: number;
|
|
multiSelect?: boolean;
|
|
contextMenu?: ReactNode;
|
|
setIsContextMenuOpen?: (isOpen: boolean) => void;
|
|
isRenaming: boolean;
|
|
setIsRenaming: (isRenaming: boolean) => void;
|
|
selectable?: boolean;
|
|
padding?: number | { x?: number; y?: number };
|
|
}
|
|
|
|
export type ExplorerViewSelectionChange<T extends ExplorerViewSelection> = T extends number[]
|
|
? number[]
|
|
: number | undefined;
|
|
|
|
export const ViewContext = createContext<ExplorerViewContext | null>(null);
|
|
|
|
export const useExplorerViewContext = () => {
|
|
const ctx = useContext(ViewContext);
|
|
|
|
if (ctx === null) throw new Error('ViewContext.Provider not found!');
|
|
|
|
return ctx;
|
|
};
|