From 07c7bf2ef77c89297a30841181dfc5e4d8415af7 Mon Sep 17 00:00:00 2001 From: xEsiah Date: Fri, 23 Oct 2026 16:18:23 +0200 Subject: [PATCH] feat(ui): add grouped actions; add contextual menu for grouped actions; items & folders can be selected without precisly clicking the checkbox --- frontend/src/components/IconAction.tsx | 2 +- frontend/src/components/feedback.tsx | 2 +- frontend/src/components/toast.tsx | 4 +- frontend/src/pages/Browser.tsx | 575 ++++++++++++++++--------- 4 files changed, 383 insertions(+), 200 deletions(-) diff --git a/frontend/src/components/IconAction.tsx b/frontend/src/components/IconAction.tsx index ffd1d79..f1e3225 100644 --- a/frontend/src/components/IconAction.tsx +++ b/frontend/src/components/IconAction.tsx @@ -11,7 +11,7 @@ export const IconAction = ({ }: { label: string; icon: ReactNode; - onClick: () => void; + onClick: (event: React.MouseEvent) => void; isLoading?: boolean; tone?: "neutral" | "danger"; badge?: number; diff --git a/frontend/src/components/feedback.tsx b/frontend/src/components/feedback.tsx index 4e80b9d..33024d4 100644 --- a/frontend/src/components/feedback.tsx +++ b/frontend/src/components/feedback.tsx @@ -42,7 +42,7 @@ export const Modal = ({ role="dialog" aria-modal="true" aria-label={title} - className="animate-panel-in relative w-full max-w-md rounded-lg border border-border bg-surface p-4 shadow-lg" + className="animate-panel-in relative w-full max-w-lg sm:max-w-md rounded-lg border border-border bg-surface p-4 sm:p-5 shadow-lg" >

diff --git a/frontend/src/components/toast.tsx b/frontend/src/components/toast.tsx index 730655b..4a36596 100644 --- a/frontend/src/components/toast.tsx +++ b/frontend/src/components/toast.tsx @@ -50,12 +50,12 @@ export const ToastProvider = ({ children }: { children: ReactNode }) => { return ( {children} -
+
{toasts.map((t) => (
{ const [folders, setFolders] = useState([]); const [files, setFiles] = useState([]); const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - const [notice, setNotice] = useState(null); + const [, setError] = useState(null); + const [, setNotice] = useState(null); const [uploading, setUploading] = useState(false); const [removing, setRemoving] = useState(null); const [dialog, setDialog] = useState(null); @@ -87,31 +93,40 @@ export const Browser = () => { 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 [uploadProgress, setUploadProgress] = useState<{ + current: number; + total: number; + } | null>(null); const current = path[path.length - 1] ?? { id: null, name: "Racine" }; const dragActive = dragDepth > 0; - const load = useCallback(async (parentId: string | null) => { - setLoading(true); - setError(null); - try { - const [folderResult, fileResult] = await Promise.all([ - api.folders(parentId), - api.files(parentId), - ]); - setFolders(folderResult.folders); - setFiles(fileResult.files); - } catch (caught) { - const msg = caught instanceof ApiError ? caught.message : t("Chargement impossible."); - setError(msg); - toast.error(msg); - setFolders([]); - setFiles([]); - } finally { - setLoading(false); - } - }, [t]); + const load = useCallback( + async (parentId: string | null) => { + setLoading(true); + setError(null); + try { + const [folderResult, fileResult] = await Promise.all([ + api.folders(parentId), + api.files(parentId), + ]); + setFolders(folderResult.folders); + setFiles(fileResult.files); + } catch (caught) { + const msg = + caught instanceof ApiError + ? caught.message + : t("Chargement impossible."); + setError(msg); + toast.error(msg); + setFolders([]); + setFiles([]); + } finally { + setLoading(false); + } + }, + [t], + ); const refreshUnread = useCallback(async () => { try { @@ -142,7 +157,8 @@ export const Browser = () => { setPath((previous) => [...previous, { id: folder.id, name: folder.name }]); }; - const goTo = (index: number) => setPath((previous) => previous.slice(0, index + 1)); + const goTo = (index: number) => + setPath((previous) => previous.slice(0, index + 1)); const upload = async (selectedFiles: FileList | null) => { if (!selectedFiles || selectedFiles.length === 0) return; @@ -161,7 +177,8 @@ export const Browser = () => { void refresh(); await reload(); } catch (caught) { - const msg = caught instanceof ApiError ? caught.message : t("Envoi impossible."); + const msg = + caught instanceof ApiError ? caught.message : t("Envoi impossible."); setError(msg); toast.error(msg); } finally { @@ -176,7 +193,11 @@ 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 (selectedFiles: FileList | null, folderId: string | null, label?: string) => { + const uploadInto = async ( + selectedFiles: FileList | null, + folderId: string | null, + label?: string, + ) => { if (!selectedFiles || selectedFiles.length === 0) return; setUploading(true); setError(null); @@ -199,11 +220,14 @@ export const Browser = () => { count: filesArr.length, name: label, }) - : t("{count} fichier(s) déposé(s) dans ce dossier.", { count: filesArr.length }); + : t("{count} fichier(s) déposé(s) dans ce dossier.", { + count: filesArr.length, + }); setNotice(msg); toast.success(msg); } catch (caught) { - const msg = caught instanceof ApiError ? caught.message : t("Envoi impossible."); + const msg = + caught instanceof ApiError ? caught.message : t("Envoi impossible."); setError(msg); toast.error(msg); } finally { @@ -285,7 +309,10 @@ export const Browser = () => { const kind = target.type === "folder" ? t("ce dossier") : t("ce fichier"); const ok = await confirm({ title: t("Mettre à la corbeille"), - message: t("Placer {name} ({kind}) dans la corbeille ?", { name: target.name, kind }), + message: t("Placer {name} ({kind}) dans la corbeille ?", { + name: target.name, + kind, + }), confirmLabel: t("Corbeille"), tone: "danger", }); @@ -301,7 +328,10 @@ export const Browser = () => { } await reload(); } catch (caught) { - const msg = caught instanceof ApiError ? caught.message : t("Suppression impossible."); + const msg = + caught instanceof ApiError + ? caught.message + : t("Suppression impossible."); setError(msg); toast.error(msg); } finally { @@ -313,9 +343,12 @@ export const Browser = () => { setError(null); try { const { file: updated } = await api.starFile(file.id); - setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item))); + setFiles((previous) => + previous.map((item) => (item.id === updated.id ? updated : item)), + ); } catch (caught) { - const msg = caught instanceof ApiError ? caught.message : t("Action impossible."); + const msg = + caught instanceof ApiError ? caught.message : t("Action impossible."); setError(msg); toast.error(msg); } @@ -339,15 +372,19 @@ export const Browser = () => { const selectedItems: Target[] = []; for (const folder of folders) { - if (selected.has(`f:${folder.id}`)) selectedItems.push({ type: "folder", id: folder.id, name: folder.name }); + 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 }); + 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 visibleFiles = kind + ? files.filter((file) => mediaKind(file.mime_type) === kind) + : files; + const currentUnread = current.id ? (unread[current.id] ?? 0) : 0; const quotaPercent = user && user.quota_bytes > 0 ? Math.min(100, Math.round((user.used_bytes / user.quota_bytes) * 100)) @@ -374,60 +411,72 @@ export const Browser = () => { - {path.length > 1 ? ( - - ) : null} + {path.length > 1 ? ( + + ) : null} - + {index > 0 ? ( + + ) : null} + {index === path.length - 1 ? ( + + {t(crumb.name)} + + ) : ( + + )} + + ))} + + - {current.id ? ( - - ) : null} + {current.id ? ( + + ) : null}
} /> @@ -436,7 +485,9 @@ export const Browser = () => {
- {t("Espace utilisé")} + + {t("Espace utilisé")} + {t("{used} sur {quota}", { used: formatBytes(user?.used_bytes ?? 0), @@ -452,6 +503,27 @@ export const Browser = () => {
+ {uploading && uploadProgress ? ( +
+
+ + {t("Envoi en cours")} + + + {t("{current}/{total}", uploadProgress)} + +
+
+
+
+
+ ) : null} + {canWrite ? (
{ {files.length > 0 ? ( -
+
{KINDS.map((option) => (
) : null} - {error ? {error} : null} - {notice ? {notice} : null} + {/* Alerts replaced by toasts */} {canWrite && selectedItems.length > 0 ? ( - -
-

- {t("{count} élément(s) sélectionné(s).", { count: selectedItems.length })} +

+
+

+ {t("{count} élément(s) sélectionné(s).", { + count: selectedItems.length, + })}

-
- +
- +
) : null} {loading ? ( @@ -536,7 +637,9 @@ export const Browser = () => { } title={t("Emplacement vide")} - description={t("Créez un sous-dossier ou envoyez un fichier pour commencer.")} + description={t( + "Créez un sous-dossier ou envoyez un fichier pour commencer.", + )} /> ) : (
@@ -552,25 +655,39 @@ export const Browser = () => { onDragOver={(event) => onFolderDragOver(event, folder.id)} onDragLeave={(event) => onFolderDragLeave(event, folder.id)} onDrop={(event) => onFolderDrop(event, folder)} + onClick={() => toggleSelection(`f:${folder.id}`)} className={cn( - "group relative 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", + "group relative flex items-center gap-1 rounded-lg border border-border bg-surface p-2 transition-colors hover:border-border-strong hover:bg-surface-hover cursor-pointer", + 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", )} > 0 + ? "opacity-100" + : "opacity-100 md:opacity-0 md:group-hover:opacity-100 md:focus:opacity-100", )} checked={selected.has(`f:${folder.id}`)} - aria-label={t("Sélectionner {name}", { name: folder.name })} - onChange={() => toggleSelection(`f:${folder.id}`)} + aria-label={t("Sélectionner {name}", { + name: folder.name, + })} + onChange={(event) => { + event.stopPropagation(); + toggleSelection(`f:${folder.id}`); + }} /> -
+
} badge={unread[folder.id] ?? 0} - onClick={() => setChat({ id: folder.id, name: folder.name })} + onClick={(event) => { + event.stopPropagation(); + setChat({ id: folder.id, name: folder.name }); + }} /> {canWrite ? ( <> } - onClick={() => setDialog({ kind: "share", folder })} + onClick={(event) => { + event.stopPropagation(); + setDialog({ kind: "share", folder }); + }} /> } - onClick={() => + onClick={(event) => { + event.stopPropagation(); setDialog({ kind: "rename", - target: { type: "folder", id: folder.id, name: folder.name }, - }) - } + target: { + type: "folder", + id: folder.id, + name: folder.name, + }, + }); + }} /> } isLoading={removing === folder.id} tone="danger" - onClick={() => - void removeTarget({ type: "folder", id: folder.id, name: folder.name }) - } + onClick={(event) => { + event.stopPropagation(); + void removeTarget({ + type: "folder", + id: folder.id, + name: folder.name, + }); + }} /> ) : null} @@ -633,91 +768,135 @@ export const Browser = () => { {t("Fichiers")}

{visibleFiles.length === 0 ? ( -

{t("Rien à afficher pour ce filtre.")}

+

+ {t("Rien à afficher pour ce filtre.")} +

) : ( -
    - {visibleFiles.map((file, index) => ( -
  • - + {visibleFiles.map((file, index) => ( +
  • toggleSelection(`i:${file.id}`)} className={cn( - "h-4 w-4 rounded border-border-control transition-opacity", - selected.has(`i:${file.id}`) ? "opacity-100" : "opacity-0 group-hover:opacity-100 focus:opacity-100", + "group flex items-center gap-2 px-3 py-2.5 cursor-pointer", + selected.has(`i:${file.id}`) && "bg-accent/5", )} - checked={selected.has(`i:${file.id}`)} - aria-label={t("Sélectionner {name}", { name: file.name })} - onChange={() => toggleSelection(`i:${file.id}`)} - /> - - - - {file.name} - - - {formatBytes(file.size_bytes)} ·{" "} - {new Date(file.created_at).toLocaleDateString(getLocale())} - - - -
    - - } - onClick={() => void toggleStar(file)} + 0 + ? "opacity-100" + : "opacity-100 md:opacity-0 md:group-hover:opacity-100 md:focus:opacity-100", + )} + checked={selected.has(`i:${file.id}`)} + aria-label={t("Sélectionner {name}", { + name: file.name, + })} + onChange={(event) => { + event.stopPropagation(); + toggleSelection(`i:${file.id}`); + }} /> - - { + event.stopPropagation(); + setViewer(index); + }} + className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-sm border border-border bg-surface-muted text-muted-foreground transition-colors hover:border-border-strong focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none" + aria-label={t("Aperçu de {name}", { name: file.name })} > - - {t("Télécharger")} - + + + + + {file.name} + + + {formatBytes(file.size_bytes)} ·{" "} + {new Date(file.created_at).toLocaleDateString( + getLocale(), + )} + + - {canWrite ? ( - <> - } - onClick={() => - setDialog({ - kind: "rename", - target: { type: "file", id: file.id, name: file.name }, - }) - } - /> - } - isLoading={removing === file.id} - tone="danger" - onClick={() => - void removeTarget({ type: "file", id: file.id, name: file.name }) - } - /> - - ) : null} -
    -
  • - ))} -
+
+ + } + onClick={(event) => { + event.stopPropagation(); + void toggleStar(file); + }} + /> + + event.stopPropagation()} + > + + + {t("Télécharger")} + + + + {canWrite ? ( + <> + } + onClick={(event) => { + event.stopPropagation(); + setDialog({ + kind: "rename", + target: { + type: "file", + id: file.id, + name: file.name, + }, + }); + }} + /> + } + isLoading={removing === file.id} + tone="danger" + onClick={(event) => { + event.stopPropagation(); + void removeTarget({ + type: "file", + id: file.id, + name: file.name, + }); + }} + /> + + ) : null} +
+ + ))} + )} ) : null} @@ -765,7 +944,11 @@ export const Browser = () => { {viewer !== null ? ( ({ id: item.id, name: item.name, mime_type: item.mime_type }))} + items={visibleFiles.map((item) => ({ + id: item.id, + name: item.name, + mime_type: item.mime_type, + }))} startIndex={viewer} onClose={() => setViewer(null)} />