FileBrowser can report the folder it is showing
A chooser whose answer is a folder had no way to ask. Folders navigate rather than being pickable — getting to a file requires it — so the only way to say "this one" is to be standing in it, and the caller needs to know which one that is to put a button on it. Reported from the component rather than threaded through the hook: the hook's job is the folder, and a seventh positional argument is how a signature stops being readable.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { Breadcrumb } from './components/Breadcrumb';
|
||||
import { Toolbar } from './components/Toolbar';
|
||||
import { UploadProgress } from './components/UploadProgress';
|
||||
@@ -35,6 +36,14 @@ type FileBrowserAppProps = {
|
||||
* handling reimplemented, all of it free to drift from the real browser.
|
||||
*/
|
||||
onPickFile?: (file: PickedFile) => void;
|
||||
/**
|
||||
* The folder being shown, whenever it changes.
|
||||
*
|
||||
* For a chooser whose answer is a FOLDER rather than a file. Folders navigate rather than being
|
||||
* pickable — getting to a file requires it — so the only way to say "this one" is to be standing in
|
||||
* it, and the caller needs to know which one that is to put a button on it.
|
||||
*/
|
||||
onPathChange?: (path: string) => void;
|
||||
};
|
||||
|
||||
export const FileBrowserApp = ({
|
||||
@@ -45,9 +54,18 @@ export const FileBrowserApp = ({
|
||||
panelId,
|
||||
pathParam,
|
||||
onPickFile,
|
||||
onPathChange,
|
||||
}: FileBrowserAppProps) => {
|
||||
const fileBrowserManager = useFileBrowserApp(basePath, rootOverride, urlPath, panelId, pathParam, onPickFile);
|
||||
const { handleNavigate } = fileBrowserManager;
|
||||
const { handleNavigate, currentPath } = fileBrowserManager;
|
||||
|
||||
// Reported from here rather than threaded through the hook: the hook's job is the folder, and one
|
||||
// more positional argument on a six-argument call is how a signature stops being readable.
|
||||
const report = useRef(onPathChange);
|
||||
report.current = onPathChange;
|
||||
useEffect(() => {
|
||||
report.current?.(currentPath);
|
||||
}, [currentPath]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full overflow-hidden">
|
||||
|
||||
Reference in New Issue
Block a user