mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
ui: two upload dialogs that had drifted apart (#664)
* ui: two upload dialogs that had drifted apart The dashboard and the file browser each had their own upload component: two dropzones, two overwrite toggles, two copies of the progress-bar rendering, against the same `useUploadFile` state. The file browser's dialog was made fullscreen with a drop target that grows; the dashboard's stayed a `large` dialog with a strip to drop onto, because it was a different file. They differ in one thing that is real: the file browser knows the destination because the user selected it, and the dashboard has to ask. That is now the `destination` prop -- `undefined` asks, a string uploads there, and '' is the media directory rather than a missing destination. Everything else is one component, so the next change to either entry point lands on both. * review: an upload dialog that looped on the media directory Pressing Upload in the file browser with nothing selected passes `''` -- the media directory. Three checks along that path read it as "no destination": * The clearing effect ran, and `doClear` is a new function every render whose own setState scheduled the next one. React ended it with "Maximum update depth exceeded", 16 warnings deep, on the default Upload path. The effect now clears only while asking, and `doClear` is stable. * The title read `Upload to: /media/wrolpi/`. * `doUpload` bailed, so a drop on the media root uploaded nothing. All three predate this branch; moving the dialog is what put them behind one component. Tests cover the title, what the hook is told, and that a fixed destination is never the thing that empties the queue.
This commit is contained in:
parent
82fdf9dd92
commit
4c71e84696
5 changed files with 238 additions and 214 deletions
|
|
@ -1788,7 +1788,9 @@ export const useUploadFile = () => {
|
|||
}
|
||||
|
||||
const doUpload = async () => {
|
||||
if (!files || files.length === 0 || !destination) {
|
||||
// `''` is the media directory, which the file browser uploads to when no folder is
|
||||
// selected; only a missing destination means there is nowhere to put the files.
|
||||
if (!files || files.length === 0 || destination === null || destination === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1890,14 +1892,17 @@ export const useUploadFile = () => {
|
|||
setInProgress(false);
|
||||
}
|
||||
|
||||
const doClear = () => {
|
||||
// Stable across renders. Callers put it in effect dependencies, and every call sets state
|
||||
// with fresh objects -- an unstable identity there re-runs the effect on the render its own
|
||||
// setState caused, which React ends with "Maximum update depth exceeded".
|
||||
const doClear = React.useCallback(() => {
|
||||
setFiles([]);
|
||||
setProgresses({});
|
||||
setTotalSize(0);
|
||||
setUploadedSize(0);
|
||||
setOverallProgress(0);
|
||||
setInProgress(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
doUpload()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue