mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-19 14:08:45 -04:00
* wip * wip 2 * Grid list single selection * core & pnpm-lock * Merge branch 'main' Conflicts: interface/app/$libraryId/Explorer/index.tsx * missing import from merge * fix total_orphan_paths bug * add top bar context * missing pieces of merge * missing pieces of merge * missing divs * Fill fallback value - was causing null error of page * spelling fixes * notice light theme, list view update, other explorer updates * Update pnpm-lock * Remove procedure * fix light menu ink color * fix list view scrolled state * Change layout default * Remove unused imports * remove keys * empty notice & context menu overview * Fix prevent selection while context menu is up * Fix scroll with keys * Empty notice icon * Add light icons * Context menu and fixed list view scroll * Fix name column sizing * top/bottom scroll position * Tag assign only when objectData * Fix list view locked state * fix ci * shamefully ignore eslint --------- Co-authored-by: Jamie Pine <ijamespine@me.com> Co-authored-by: ameer2468 <33054370+ameer2468@users.noreply.github.com> Co-authored-by: Jamie Pine <32987599+jamiepine@users.noreply.github.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
40 lines
892 B
TypeScript
40 lines
892 B
TypeScript
import DragSelect from 'dragselect';
|
|
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
|
|
type ProviderProps = {
|
|
children: React.ReactNode;
|
|
settings?: ConstructorParameters<typeof DragSelect>[0];
|
|
};
|
|
|
|
const Context = createContext<DragSelect | undefined>(undefined);
|
|
|
|
function DragSelectProvider({ children, settings = {} }: ProviderProps) {
|
|
const [ds, setDS] = useState<DragSelect>();
|
|
|
|
useEffect(() => {
|
|
setDS((prevState) => {
|
|
if (prevState) return prevState;
|
|
return new DragSelect({});
|
|
});
|
|
return () => {
|
|
if (ds) {
|
|
console.log('stop');
|
|
ds.stop();
|
|
setDS(undefined);
|
|
}
|
|
};
|
|
}, [ds]);
|
|
|
|
useEffect(() => {
|
|
ds?.setSettings(settings);
|
|
}, [ds, settings]);
|
|
|
|
return <Context.Provider value={ds}>{children}</Context.Provider>;
|
|
}
|
|
|
|
function useDragSelect() {
|
|
return useContext(Context);
|
|
}
|
|
|
|
export { DragSelectProvider, useDragSelect };
|