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.
This commit is contained in:
@@ -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<ToastContextValue | null>(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<Toast[]>([]);
|
||||
|
||||
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 (
|
||||
<ToastContext.Provider value={{ toast, success, error, info }}>
|
||||
{children}
|
||||
<div className="fixed right-4 top-4 z-[100] flex flex-col gap-2">
|
||||
{toasts.map((t) => (
|
||||
<div
|
||||
key={t.id}
|
||||
className={cn(
|
||||
"animate-in slide-in-from-right fade-in flex min-w-[280px] max-w-sm items-start gap-3 rounded-lg border px-4 py-3 shadow-lg",
|
||||
t.tone === "success" && "border-accent/40 bg-accent/10 text-foreground",
|
||||
t.tone === "error" && "border-destructive/40 bg-destructive/10 text-destructive",
|
||||
t.tone === "info" && "border-border bg-surface text-foreground",
|
||||
)}
|
||||
role="status"
|
||||
>
|
||||
<p className="flex-1 text-sm leading-relaxed">{t.message}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => remove(t.id)}
|
||||
className="text-muted-foreground transition-colors hover:text-foreground"
|
||||
aria-label="Fermer"
|
||||
>
|
||||
<CloseIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</ToastContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -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 (
|
||||
<ThemeProvider theme={user?.theme ?? "system"}>
|
||||
<I18nProvider language={user?.language ?? "fr"}>
|
||||
<ConfirmProvider>{children}</ConfirmProvider>
|
||||
<ConfirmProvider>
|
||||
<ToastProvider>{children}</ToastProvider>
|
||||
</ConfirmProvider>
|
||||
</I18nProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
+116
-115
@@ -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<Crumb[]>([{ id: null, name: "Racine" }]);
|
||||
const [folders, setFolders] = useState<Folder[]>([]);
|
||||
const [files, setFiles] = useState<UploadedFile[]>([]);
|
||||
@@ -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 ? (
|
||||
<Card>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 p-3">
|
||||
<p className="text-sm text-foreground">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t("{count} élément(s) sélectionné(s).", { count: selectedItems.length })}
|
||||
</p>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
@@ -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",
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="ml-1 h-4 w-4 rounded border-border-control"
|
||||
className={cn(
|
||||
"ml-1 h-4 w-4 rounded border-border-control transition-opacity",
|
||||
selected.has(`f:${folder.id}`) ? "opacity-100" : "opacity-0 group-hover:opacity-100 focus:opacity-100",
|
||||
)}
|
||||
checked={selected.has(`f:${folder.id}`)}
|
||||
aria-label={t("Sélectionner {name}", { name: folder.name })}
|
||||
onChange={() => toggleSelection(`f:${folder.id}`)}
|
||||
@@ -571,50 +585,42 @@ export const Browser = () => {
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<IconAction
|
||||
label={t("Discussion {name}", { name: folder.name })}
|
||||
icon={<ChatIcon className="h-4 w-4" />}
|
||||
badge={unread[folder.id] ?? 0}
|
||||
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
||||
/>
|
||||
{canWrite ? (
|
||||
<div className="flex shrink-0 items-center gap-0.5">
|
||||
<IconAction
|
||||
label={t("Partager {name}", { name: folder.name })}
|
||||
icon={<ShareIcon className="h-4 w-4" />}
|
||||
onClick={() => setDialog({ kind: "share", folder })}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Renommer {name}", { name: folder.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "folder", id: folder.id, name: folder.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Déplacer {name}", { name: folder.name })}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "move",
|
||||
target: { type: "folder", id: folder.id, name: folder.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Supprimer {name}", { name: folder.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === folder.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "folder", id: folder.id, name: folder.name })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
<IconAction
|
||||
label={t("Discussion {name}", { name: folder.name })}
|
||||
icon={<ChatIcon className="h-4 w-4" />}
|
||||
badge={unread[folder.id] ?? 0}
|
||||
onClick={() => setChat({ id: folder.id, name: folder.name })}
|
||||
/>
|
||||
{canWrite ? (
|
||||
<>
|
||||
<IconAction
|
||||
label={t("Partager {name}", { name: folder.name })}
|
||||
icon={<ShareIcon className="h-4 w-4" />}
|
||||
onClick={() => setDialog({ kind: "share", folder })}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Renommer {name}", { name: folder.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "folder", id: folder.id, name: folder.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Supprimer {name}", { name: folder.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === folder.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "folder", id: folder.id, name: folder.name })
|
||||
}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -633,11 +639,14 @@ export const Browser = () => {
|
||||
{visibleFiles.map((file, index) => (
|
||||
<li
|
||||
key={file.id}
|
||||
className={cn("flex items-center gap-2 px-3 py-2.5", selected.has(`i:${file.id}`) && "bg-accent/5")}
|
||||
className={cn("group flex items-center gap-2 px-3 py-2.5", selected.has(`i:${file.id}`) && "bg-accent/5")}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="h-4 w-4 rounded border-border-control"
|
||||
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",
|
||||
)}
|
||||
checked={selected.has(`i:${file.id}`)}
|
||||
aria-label={t("Sélectionner {name}", { name: file.name })}
|
||||
onChange={() => toggleSelection(`i:${file.id}`)}
|
||||
@@ -660,60 +669,52 @@ export const Browser = () => {
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<IconAction
|
||||
label={
|
||||
file.is_starred
|
||||
? t("Retirer l'étoile de {name}", { name: file.name })
|
||||
: t("Étoiler {name}", { name: file.name })
|
||||
}
|
||||
icon={
|
||||
<StarIcon className="h-4 w-4" {...(file.is_starred ? { filled: true } : {})} />
|
||||
}
|
||||
onClick={() => void toggleStar(file)}
|
||||
/>
|
||||
<div className="flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
<IconAction
|
||||
label={
|
||||
file.is_starred
|
||||
? t("Retirer l'étoile de {name}", { name: file.name })
|
||||
: t("Étoiler {name}", { name: file.name })
|
||||
}
|
||||
icon={
|
||||
<StarIcon className="h-4 w-4" {...(file.is_starred ? { filled: true } : {})} />
|
||||
}
|
||||
onClick={() => void toggleStar(file)}
|
||||
/>
|
||||
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
download={file.name}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-sm border border-border-strong bg-surface px-3 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
<DownloadIcon className="h-3.5 w-3.5" />
|
||||
<span className="hidden sm:inline">{t("Télécharger")}</span>
|
||||
</a>
|
||||
<a
|
||||
href={api.downloadUrl(file.id)}
|
||||
download={file.name}
|
||||
className="inline-flex h-8 items-center gap-1.5 rounded-sm border border-border-strong bg-surface px-3 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors hover:bg-surface-hover"
|
||||
>
|
||||
<DownloadIcon className="h-3.5 w-3.5" />
|
||||
<span className="hidden sm:inline">{t("Télécharger")}</span>
|
||||
</a>
|
||||
|
||||
{canWrite ? (
|
||||
<>
|
||||
<IconAction
|
||||
label={t("Renommer {name}", { name: file.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "file", id: file.id, name: file.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Déplacer {name}", { name: file.name })}
|
||||
icon={<MoveIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "move",
|
||||
target: { type: "file", id: file.id, name: file.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Supprimer {name}", { name: file.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === file.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "file", id: file.id, name: file.name })
|
||||
}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{canWrite ? (
|
||||
<>
|
||||
<IconAction
|
||||
label={t("Renommer {name}", { name: file.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
onClick={() =>
|
||||
setDialog({
|
||||
kind: "rename",
|
||||
target: { type: "file", id: file.id, name: file.name },
|
||||
})
|
||||
}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Supprimer {name}", { name: file.name })}
|
||||
icon={<TrashIcon className="h-4 w-4" />}
|
||||
isLoading={removing === file.id}
|
||||
tone="danger"
|
||||
onClick={() =>
|
||||
void removeTarget({ type: "file", id: file.id, name: file.name })
|
||||
}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user