From 759a21fed7294c5d7baa3d47c5a89c81b5c4e0cd Mon Sep 17 00:00:00 2001 From: xEsiah Date: Thu, 22 Oct 2026 15:20:54 +0200 Subject: [PATCH] feat(ui): add toasts, hover-only actions and bulk selection styling Move notifications to auto-expiring toasts top-right. Show checkboxes and item actions only on hover, keep chat visible. Emphasize bulk selection bar. --- frontend/src/components/toast.tsx | 79 ++++++++++ frontend/src/main.tsx | 5 +- frontend/src/pages/Browser.tsx | 231 +++++++++++++++--------------- 3 files changed, 199 insertions(+), 116 deletions(-) create mode 100644 frontend/src/components/toast.tsx diff --git a/frontend/src/components/toast.tsx b/frontend/src/components/toast.tsx new file mode 100644 index 0000000..730655b --- /dev/null +++ b/frontend/src/components/toast.tsx @@ -0,0 +1,79 @@ +import { createContext, useCallback, useContext, useState, type ReactNode } from "react"; +import { cn } from "../ui/index.js"; +import { CloseIcon } from "./icons.js"; + +type ToastTone = "success" | "error" | "info"; + +interface Toast { + id: number; + message: string; + tone: ToastTone; + duration: number; +} + +interface ToastContextValue { + toast: (message: string, tone?: ToastTone, duration?: number) => void; + success: (message: string, duration?: number) => void; + error: (message: string, duration?: number) => void; + info: (message: string, duration?: number) => void; +} + +const ToastContext = createContext(null); + +export const useToast = () => { + const ctx = useContext(ToastContext); + if (!ctx) throw new Error("useToast must be used within ToastProvider"); + return ctx; +}; + +let toastId = 0; + +export const ToastProvider = ({ children }: { children: ReactNode }) => { + const [toasts, setToasts] = useState([]); + + const remove = useCallback((id: number) => { + setToasts((prev) => prev.filter((t) => t.id !== id)); + }, []); + + const toast = useCallback((message: string, tone: ToastTone = "info", duration = 4000) => { + const id = ++toastId; + setToasts((prev) => [...prev, { id, message, tone, duration }]); + if (duration > 0) { + setTimeout(() => remove(id), duration); + } + }, [remove]); + + const success = useCallback((message: string, duration = 4000) => toast(message, "success", duration), [toast]); + const error = useCallback((message: string, duration = 5000) => toast(message, "error", duration), [toast]); + const info = useCallback((message: string, duration = 4000) => toast(message, "info", duration), [toast]); + + return ( + + {children} +
+ {toasts.map((t) => ( +
+

{t.message}

+ +
+ ))} +
+
+ ); +}; diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index a7f5f42..d70e6a1 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -6,6 +6,7 @@ import { SessionProvider, useSession } from "./lib/session.js"; import { I18nProvider } from "./lib/i18n.js"; import { ThemeProvider } from "./lib/theme.js"; import { ConfirmProvider } from "./components/confirm.js"; +import { ToastProvider } from "./components/toast.js"; import "./styles/index.css"; const container = document.getElementById("root"); @@ -23,7 +24,9 @@ const Providers = ({ children }: { children: ReactNode }) => { return ( - {children} + + {children} + ); diff --git a/frontend/src/pages/Browser.tsx b/frontend/src/pages/Browser.tsx index c80f8b3..4172c2d 100644 --- a/frontend/src/pages/Browser.tsx +++ b/frontend/src/pages/Browser.tsx @@ -17,6 +17,7 @@ import { MediaViewer } from "../components/MediaViewer.js"; import { MediaThumb } from "../components/MediaThumb.js"; import { IconAction } from "../components/IconAction.js"; import { FolderChat, type ChatFolder } from "../components/FolderChat.js"; +import { useToast } from "../components/toast.js"; import { CreateFolderDialog, MoveDialog, @@ -28,7 +29,6 @@ import { ChatIcon, DownloadIcon, FolderIcon, - MoveIcon, PenIcon, PlusIcon, ShareIcon, @@ -66,6 +66,7 @@ export const Browser = () => { const { user, refresh } = useSession(); const { t } = useI18n(); const confirm = useConfirm(); + const toast = useToast(); const [path, setPath] = useState([{ id: null, name: "Racine" }]); const [folders, setFolders] = useState([]); const [files, setFiles] = useState([]); @@ -102,7 +103,9 @@ export const Browser = () => { setFolders(folderResult.folders); setFiles(fileResult.files); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : t("Chargement impossible.")); + const msg = caught instanceof ApiError ? caught.message : t("Chargement impossible."); + setError(msg); + toast.error(msg); setFolders([]); setFiles([]); } finally { @@ -158,7 +161,9 @@ export const Browser = () => { void refresh(); await reload(); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); + const msg = caught instanceof ApiError ? caught.message : t("Envoi impossible."); + setError(msg); + toast.error(msg); } finally { setUploading(false); setUploadProgress(null); @@ -189,16 +194,18 @@ export const Browser = () => { // Seule la vue courante est rechargée : un depot dans un sous-dossier ne // change rien a l'ecran tant qu'on ne l'ouvre pas. if (folderId === current.id) await reload(); - setNotice( - label - ? t("{count} fichier(s) déposé(s) dans {name}.", { - count: filesArr.length, - name: label, - }) - : t("{count} fichier(s) déposé(s) dans ce dossier.", { count: filesArr.length }), - ); + const msg = label + ? t("{count} fichier(s) déposé(s) dans {name}.", { + count: filesArr.length, + name: label, + }) + : t("{count} fichier(s) déposé(s) dans ce dossier.", { count: filesArr.length }); + setNotice(msg); + toast.success(msg); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : t("Envoi impossible.")); + const msg = caught instanceof ApiError ? caught.message : t("Envoi impossible."); + setError(msg); + toast.error(msg); } finally { setUploading(false); setUploadProgress(null); @@ -294,7 +301,9 @@ export const Browser = () => { } await reload(); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : t("Suppression impossible.")); + const msg = caught instanceof ApiError ? caught.message : t("Suppression impossible."); + setError(msg); + toast.error(msg); } finally { setRemoving(null); } @@ -306,7 +315,9 @@ export const Browser = () => { const { file: updated } = await api.starFile(file.id); setFiles((previous) => previous.map((item) => (item.id === updated.id ? updated : item))); } catch (caught) { - setError(caught instanceof ApiError ? caught.message : t("Action impossible.")); + const msg = caught instanceof ApiError ? caught.message : t("Action impossible."); + setError(msg); + toast.error(msg); } }; @@ -502,7 +513,7 @@ export const Browser = () => { {canWrite && selectedItems.length > 0 ? (
-

+

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

@@ -542,14 +553,17 @@ export const Browser = () => { onDragLeave={(event) => onFolderDragLeave(event, folder.id)} onDrop={(event) => onFolderDrop(event, folder)} 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", + "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", )} > toggleSelection(`f:${folder.id}`)} @@ -571,50 +585,42 @@ export const Browser = () => { - } - badge={unread[folder.id] ?? 0} - onClick={() => setChat({ id: folder.id, name: folder.name })} - /> - {canWrite ? ( -
- } - onClick={() => setDialog({ kind: "share", folder })} - /> - } - onClick={() => - setDialog({ - kind: "rename", - target: { type: "folder", id: folder.id, name: folder.name }, - }) - } - /> - } - onClick={() => - setDialog({ - kind: "move", - 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 }) - } - /> -
- ) : null} +
+ } + badge={unread[folder.id] ?? 0} + onClick={() => setChat({ id: folder.id, name: folder.name })} + /> + {canWrite ? ( + <> + } + onClick={() => setDialog({ kind: "share", folder })} + /> + } + onClick={() => + setDialog({ + kind: "rename", + 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 }) + } + /> + + ) : null} +
))} @@ -633,11 +639,14 @@ export const Browser = () => { {visibleFiles.map((file, index) => (
  • toggleSelection(`i:${file.id}`)} @@ -660,60 +669,52 @@ export const Browser = () => { - - } - onClick={() => void toggleStar(file)} - /> +
    + + } + onClick={() => void toggleStar(file)} + /> - - - {t("Télécharger")} - + + + {t("Télécharger")} + - {canWrite ? ( - <> - } - onClick={() => - setDialog({ - kind: "rename", - target: { type: "file", id: file.id, name: file.name }, - }) - } - /> - } - onClick={() => - setDialog({ - kind: "move", - 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} + {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} +
  • ))}