From 540dc0cc1a788d6a75b12f8680ebb3e38b453308 Mon Sep 17 00:00:00 2001 From: xEsiah Date: Thu, 22 Oct 2026 14:44:08 +0200 Subject: [PATCH] feat(files): add bulk selection, move and upload progress Allow selecting multiple files and folders to move them together in one dialog. Show upload progress (current/total) during single-file and drag-and-drop uploads. --- frontend/src/components/dialogs.tsx | 33 +++++---- frontend/src/pages/Browser.tsx | 103 ++++++++++++++++++++++++---- 2 files changed, 109 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/dialogs.tsx b/frontend/src/components/dialogs.tsx index fb67baf..b84cb65 100644 --- a/frontend/src/components/dialogs.tsx +++ b/frontend/src/components/dialogs.tsx @@ -157,14 +157,19 @@ const loadTree = async (): Promise => { export const MoveDialog = ({ target, + targets, onClose, onDone, }: { - target: Target; + target?: Target; + targets?: Target[]; onClose: () => void; onDone: () => void; }) => { const { t } = useI18n(); + const items = targets && targets.length > 0 ? targets : target ? [target] : []; + const single = items.length === 1 ? items[0] : null; + const title = single ? t("Déplacer") : t("Déplacer {count} éléments", { count: items.length }); const [entries, setEntries] = useState(null); const [destination, setDestination] = useState(""); const [error, setError] = useState(null); @@ -182,8 +187,10 @@ export const MoveDialog = ({ setError(null); const parentId = destination === "" ? null : destination; try { - if (target.type === "folder") await api.moveFolder(target.id, parentId); - else await api.moveFile(target.id, parentId); + for (const item of items) { + if (item.type === "folder") await api.moveFolder(item.id, parentId); + else await api.moveFile(item.id, parentId); + } onDone(); } catch (caught) { setError(messageOf(caught, t("Déplacement impossible."))); @@ -193,10 +200,12 @@ export const MoveDialog = ({ }; return ( - +
void submit(event)}>

- {t("Destination de {name}.", { name: target.name })} + {single + ? t("Destination de {name}.", { name: single.name }) + : t("{count} éléments seront déplacés.", { count: items.length })}

{entries === null && !error ? ( {t("Chargement des dossiers…")} @@ -214,13 +223,13 @@ export const MoveDialog = ({ )} > - {(entries ?? []) - .filter((entry) => entry.id !== target.id) - .map((entry) => ( - - ))} + {(entries ?? []) + .filter((entry) => !items.some((item) => item.type === "folder" && item.id === entry.id)) + .map((entry) => ( + + ))} )} diff --git a/frontend/src/pages/Browser.tsx b/frontend/src/pages/Browser.tsx index 0ae76ef..c80f8b3 100644 --- a/frontend/src/pages/Browser.tsx +++ b/frontend/src/pages/Browser.tsx @@ -48,6 +48,7 @@ type Dialog = | { kind: "create" } | { kind: "rename"; target: Target } | { kind: "move"; target: Target } + | { kind: "moveMany"; targets: Target[] } | { kind: "share"; folder: Folder } | null; @@ -84,6 +85,8 @@ export const Browser = () => { // quand le pointeur passe d'un element enfant a un autre. const [dragDepth, setDragDepth] = useState(0); const [dropTargetId, setDropTargetId] = useState(null); + const [selected, setSelected] = useState>(new Set()); + const [uploadProgress, setUploadProgress] = useState<{ current: number; total: number } | null>(null); const current = path[path.length - 1] ?? { id: null, name: "Racine" }; const dragActive = dragDepth > 0; @@ -138,14 +141,19 @@ export const Browser = () => { const goTo = (index: number) => setPath((previous) => previous.slice(0, index + 1)); - const upload = async (selected: FileList | null) => { - if (!selected || selected.length === 0) return; + const upload = async (selectedFiles: FileList | null) => { + if (!selectedFiles || selectedFiles.length === 0) return; setUploading(true); setError(null); setNotice(null); + const total = selectedFiles.length; + setUploadProgress({ current: 0, total }); try { - for (const file of Array.from(selected)) { - await api.uploadFile(file, current.id); + const filesArr = Array.from(selectedFiles); + for (let i = 0; i < filesArr.length; i++) { + const f = filesArr[i] as File; + setUploadProgress({ current: i + 1, total }); + await api.uploadFile(f, current.id); } void refresh(); await reload(); @@ -153,6 +161,7 @@ export const Browser = () => { setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); } finally { setUploading(false); + setUploadProgress(null); if (fileInputRef.current) fileInputRef.current.value = ""; } }; @@ -162,14 +171,19 @@ export const Browser = () => { * dossier affiche ou l'un des sous-dossiers listes ; le serveur revalide les * droits d'ecriture dans tous les cas. */ - const uploadInto = async (selected: FileList | null, folderId: string | null, label?: string) => { - if (!selected || selected.length === 0) return; + const uploadInto = async (selectedFiles: FileList | null, folderId: string | null, label?: string) => { + if (!selectedFiles || selectedFiles.length === 0) return; setUploading(true); setError(null); setNotice(null); + const total = selectedFiles.length; + setUploadProgress({ current: 0, total }); try { - for (const file of Array.from(selected)) { - await api.uploadFile(file, folderId); + const filesArr = Array.from(selectedFiles); + for (let i = 0; i < filesArr.length; i++) { + const f = filesArr[i] as File; + setUploadProgress({ current: i + 1, total }); + await api.uploadFile(f, folderId); } void refresh(); // Seule la vue courante est rechargée : un depot dans un sous-dossier ne @@ -178,15 +192,16 @@ export const Browser = () => { setNotice( label ? t("{count} fichier(s) déposé(s) dans {name}.", { - count: selected.length, + count: filesArr.length, name: label, }) - : t("{count} fichier(s) déposé(s) dans ce dossier.", { count: selected.length }), + : t("{count} fichier(s) déposé(s) dans ce dossier.", { count: filesArr.length }), ); } catch (caught) { setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); } finally { setUploading(false); + setUploadProgress(null); } }; @@ -300,8 +315,26 @@ export const Browser = () => { void refreshUnread(); }; - const canWrite = user?.role_slug === "admin" || user?.role_slug === "user"; + const toggleSelection = (key: string) => { + setSelected((previous) => { + const next = new Set(previous); + if (next.has(key)) next.delete(key); + else next.add(key); + return next; + }); + }; + + const clearSelection = () => setSelected(new Set()); + + const selectedItems: Target[] = []; + for (const folder of folders) { + if (selected.has(`f:${folder.id}`)) selectedItems.push({ type: "folder", id: folder.id, name: folder.name }); + } + for (const file of files) { + if (selected.has(`i:${file.id}`)) selectedItems.push({ type: "file", id: file.id, name: file.name }); + } const empty = folders.length === 0 && files.length === 0; + const canWrite = true; const visibleFiles = kind ? files.filter((file) => mediaKind(file.mime_type) === kind) : files; const currentUnread = current.id ? unread[current.id] ?? 0 : 0; const quotaPercent = @@ -424,7 +457,9 @@ export const Browser = () => { isLoading={uploading} onClick={() => fileInputRef.current?.click()} > - {t("Envoyer")} + {uploading && uploadProgress + ? t("Envoi {current}/{total}…", uploadProgress) + : t("Envoyer")} + + + + + ) : null} + {loading ? (
@@ -491,8 +544,16 @@ export const Browser = () => { className={cn( "flex items-center gap-1 rounded-lg border border-border bg-surface p-2 transition-colors hover:border-border-strong hover:bg-surface-hover", dropTargetId === folder.id && "border-accent bg-accent/10 ring-1 ring-accent/50", + selected.has(`f:${folder.id}`) && "border-accent/60 ring-1 ring-accent/40", )} > + toggleSelection(`f:${folder.id}`)} + />