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:
2026-09-07 14:06:46 +01:00
parent 5fa3f3ec76
commit da07048f53
@@ -1,3 +1,4 @@
import { useEffect, useRef } from 'react';
import { Breadcrumb } from './components/Breadcrumb'; import { Breadcrumb } from './components/Breadcrumb';
import { Toolbar } from './components/Toolbar'; import { Toolbar } from './components/Toolbar';
import { UploadProgress } from './components/UploadProgress'; import { UploadProgress } from './components/UploadProgress';
@@ -35,6 +36,14 @@ type FileBrowserAppProps = {
* handling reimplemented, all of it free to drift from the real browser. * handling reimplemented, all of it free to drift from the real browser.
*/ */
onPickFile?: (file: PickedFile) => void; 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 = ({ export const FileBrowserApp = ({
@@ -45,9 +54,18 @@ export const FileBrowserApp = ({
panelId, panelId,
pathParam, pathParam,
onPickFile, onPickFile,
onPathChange,
}: FileBrowserAppProps) => { }: FileBrowserAppProps) => {
const fileBrowserManager = useFileBrowserApp(basePath, rootOverride, urlPath, panelId, pathParam, onPickFile); 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 ( return (
<div className="flex flex-col h-full overflow-hidden"> <div className="flex flex-col h-full overflow-hidden">