feat(ui): add grouped actions; add contextual menu for grouped actions; items & folders can be selected without precisly clicking the checkbox
PR — Ouverture automatique / create-pr (push) Successful in 2s
PR — Ouverture automatique / create-pr (push) Successful in 2s
This commit is contained in:
@@ -11,7 +11,7 @@ export const IconAction = ({
|
||||
}: {
|
||||
label: string;
|
||||
icon: ReactNode;
|
||||
onClick: () => void;
|
||||
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
||||
isLoading?: boolean;
|
||||
tone?: "neutral" | "danger";
|
||||
badge?: number;
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between gap-4">
|
||||
<h2 className="font-display text-xs font-semibold uppercase tracking-label text-foreground">
|
||||
|
||||
@@ -50,12 +50,12 @@ export const ToastProvider = ({ children }: { children: ReactNode }) => {
|
||||
return (
|
||||
<ToastContext.Provider value={{ toast, success, error, info }}>
|
||||
{children}
|
||||
<div className="fixed right-4 top-4 z-[100] flex flex-col gap-2">
|
||||
<div className="fixed left-4 right-4 top-6 z-[100] flex flex-col gap-2 sm:left-auto sm:right-4 sm:max-w-sm">
|
||||
{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",
|
||||
"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 backdrop-blur",
|
||||
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",
|
||||
|
||||
+379
-196
@@ -1,4 +1,10 @@
|
||||
import { useCallback, useEffect, useRef, useState, type DragEvent } from "react";
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useRef,
|
||||
useState,
|
||||
type DragEvent,
|
||||
} from "react";
|
||||
import { Button, Card, Spinner, cn } from "../ui/index.js";
|
||||
import {
|
||||
ApiError,
|
||||
@@ -11,7 +17,7 @@ import { useSession } from "../lib/session.js";
|
||||
import { useI18n } from "../lib/i18n.js";
|
||||
import { getLocale } from "../lib/locale.js";
|
||||
import { mediaKind } from "../lib/media.js";
|
||||
import { Alert, Badge, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { Badge, EmptyState, PageHeader } from "../components/feedback.js";
|
||||
import { useConfirm } from "../components/confirm.js";
|
||||
import { MediaViewer } from "../components/MediaViewer.js";
|
||||
import { MediaThumb } from "../components/MediaThumb.js";
|
||||
@@ -71,8 +77,8 @@ export const Browser = () => {
|
||||
const [folders, setFolders] = useState<Folder[]>([]);
|
||||
const [files, setFiles] = useState<UploadedFile[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [notice, setNotice] = useState<string | null>(null);
|
||||
const [, setError] = useState<string | null>(null);
|
||||
const [, setNotice] = useState<string | null>(null);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [removing, setRemoving] = useState<string | null>(null);
|
||||
const [dialog, setDialog] = useState<Dialog>(null);
|
||||
@@ -87,31 +93,40 @@ export const Browser = () => {
|
||||
const [dragDepth, setDragDepth] = useState(0);
|
||||
const [dropTargetId, setDropTargetId] = useState<string | null>(null);
|
||||
const [selected, setSelected] = useState<Set<string>>(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 = () => {
|
||||
|
||||
<PageHeader
|
||||
title={current.name}
|
||||
description={t("Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier.")}
|
||||
description={t(
|
||||
"Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier.",
|
||||
)}
|
||||
toolbar={
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
{path.length > 1 ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(path.length - 2)}
|
||||
className="inline-flex items-center gap-1.5 rounded-sm border border-border-control bg-surface px-2.5 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors duration-fast hover:bg-surface-hover focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<ArrowLeftIcon className="h-3.5 w-3.5" />
|
||||
{t("Retour")}
|
||||
</button>
|
||||
) : null}
|
||||
{path.length > 1 ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(path.length - 2)}
|
||||
className="inline-flex items-center gap-1.5 rounded-sm border border-border-control bg-surface px-2.5 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label text-foreground transition-colors duration-fast hover:bg-surface-hover focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<ArrowLeftIcon className="h-3.5 w-3.5" />
|
||||
{t("Retour")}
|
||||
</button>
|
||||
) : null}
|
||||
|
||||
<nav aria-label={t("Fil d'Ariane")} className="min-w-0">
|
||||
<ol className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||
{path.map((crumb, index) => (
|
||||
<li key={`${crumb.id ?? "root"}-${index}`} className="flex items-center gap-1.5">
|
||||
{index > 0 ? (
|
||||
<span className="text-border" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
) : null}
|
||||
{index === path.length - 1 ? (
|
||||
<span className="font-medium text-foreground" aria-current="page">
|
||||
{t(crumb.name)}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(index)}
|
||||
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
||||
<nav aria-label={t("Fil d'Ariane")} className="min-w-0">
|
||||
<ol className="flex flex-wrap items-center gap-1.5 text-xs">
|
||||
{path.map((crumb, index) => (
|
||||
<li
|
||||
key={`${crumb.id ?? "root"}-${index}`}
|
||||
className="flex items-center gap-1.5"
|
||||
>
|
||||
{t(crumb.name)}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
{index > 0 ? (
|
||||
<span className="text-border" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
) : null}
|
||||
{index === path.length - 1 ? (
|
||||
<span
|
||||
className="font-medium text-foreground"
|
||||
aria-current="page"
|
||||
>
|
||||
{t(crumb.name)}
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => goTo(index)}
|
||||
className="text-muted-foreground underline-offset-2 transition-colors hover:text-foreground hover:underline"
|
||||
>
|
||||
{t(crumb.name)}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
{current.id ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() => setChat({ id: current.id as string, name: current.name })}
|
||||
>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
{t("Discussion")}
|
||||
{currentUnread > 0 ? <Badge tone="accent">{currentUnread}</Badge> : null}
|
||||
</span>
|
||||
</Button>
|
||||
) : null}
|
||||
{current.id ? (
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
iconLeading={<ChatIcon className="h-3.5 w-3.5" />}
|
||||
onClick={() =>
|
||||
setChat({ id: current.id as string, name: current.name })
|
||||
}
|
||||
>
|
||||
<span className="inline-flex items-center gap-2">
|
||||
{t("Discussion")}
|
||||
{currentUnread > 0 ? (
|
||||
<Badge tone="accent">{currentUnread}</Badge>
|
||||
) : null}
|
||||
</span>
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
@@ -436,7 +485,9 @@ export const Browser = () => {
|
||||
<div className="flex flex-col gap-3 p-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<span className="text-xs font-medium text-foreground">{t("Espace utilisé")}</span>
|
||||
<span className="text-xs font-medium text-foreground">
|
||||
{t("Espace utilisé")}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{t("{used} sur {quota}", {
|
||||
used: formatBytes(user?.used_bytes ?? 0),
|
||||
@@ -452,6 +503,27 @@ export const Browser = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{uploading && uploadProgress ? (
|
||||
<div className="w-full px-4">
|
||||
<div className="flex items-baseline justify-between gap-2 mb-1">
|
||||
<span className="text-xs font-medium text-foreground">
|
||||
{t("Envoi en cours")}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{t("{current}/{total}", uploadProgress)}
|
||||
</span>
|
||||
</div>
|
||||
<div className="h-1.5 w-full overflow-hidden rounded-full bg-surface-muted">
|
||||
<div
|
||||
className="h-full rounded-full bg-accent transition-[width] duration-200"
|
||||
style={{
|
||||
width: `${Math.round((uploadProgress.current / uploadProgress.total) * 100)}%`,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{canWrite ? (
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
@@ -486,7 +558,11 @@ export const Browser = () => {
|
||||
</Card>
|
||||
|
||||
{files.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label={t("Filtrer par type")}>
|
||||
<div
|
||||
className="flex flex-wrap gap-1.5"
|
||||
role="tablist"
|
||||
aria-label={t("Filtrer par type")}
|
||||
>
|
||||
{KINDS.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
@@ -507,25 +583,50 @@ export const Browser = () => {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{error ? <Alert>{error}</Alert> : null}
|
||||
{notice ? <Alert tone="success">{notice}</Alert> : null}
|
||||
{/* Alerts replaced by toasts */}
|
||||
|
||||
{canWrite && selectedItems.length > 0 ? (
|
||||
<Card>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2 p-3">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t("{count} élément(s) sélectionné(s).", { count: selectedItems.length })}
|
||||
<div className="fixed bottom-3 left-1/2 z-40 w-[calc(100%-1rem)] max-w-xl -translate-x-1/2 px-1 sm:bottom-4 sm:w-auto">
|
||||
<div className="flex flex-col items-center justify-center gap-2 rounded-lg border border-border-strong bg-surface px-3 py-2 shadow-lg sm:flex-row sm:flex-wrap sm:items-center sm:justify-center">
|
||||
<p className="text-center 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">
|
||||
<Button size="sm" variant="secondary" onClick={() => setDialog({ kind: "moveMany", targets: selectedItems })}>
|
||||
<div className="flex flex-wrap items-center justify-center gap-2">
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onClick={() =>
|
||||
setDialog({ kind: "moveMany", targets: selectedItems })
|
||||
}
|
||||
>
|
||||
{t("Déplacer")}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="destructive"
|
||||
onClick={() =>
|
||||
void Promise.all(
|
||||
selectedItems.map((target) =>
|
||||
target.type === "folder"
|
||||
? api.deleteFolder(target.id)
|
||||
: api.deleteFile(target.id),
|
||||
),
|
||||
).then(async () => {
|
||||
clearSelection();
|
||||
await reload();
|
||||
})
|
||||
}
|
||||
>
|
||||
{t("Supprimer")}
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost" onClick={clearSelection}>
|
||||
{t("Annuler la sélection")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{loading ? (
|
||||
@@ -536,7 +637,9 @@ export const Browser = () => {
|
||||
<EmptyState
|
||||
icon={<FolderIcon className="h-8 w-8" />}
|
||||
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.",
|
||||
)}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6">
|
||||
@@ -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",
|
||||
)}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
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",
|
||||
selected.has(`f:${folder.id}`) ||
|
||||
selectedItems.length > 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}`);
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open(folder)}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
open(folder);
|
||||
}}
|
||||
className="flex min-w-0 flex-1 items-center gap-3 rounded-sm p-1 text-left focus-visible:ring-ring focus-visible:ring-2 focus-visible:outline-none"
|
||||
>
|
||||
<span className="shrink-0 text-accent">
|
||||
@@ -581,42 +698,60 @@ export const Browser = () => {
|
||||
{folder.name}
|
||||
</span>
|
||||
<span className="mt-0.5 block text-[0.6875rem] text-subtle-foreground">
|
||||
{new Date(folder.created_at).toLocaleDateString(getLocale())}
|
||||
{new Date(folder.created_at).toLocaleDateString(
|
||||
getLocale(),
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
<div className="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 focus-within:opacity-100">
|
||||
<div className="flex shrink-0 items-center gap-0.5 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100 md: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 })}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
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 })}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
setDialog({ kind: "share", folder });
|
||||
}}
|
||||
/>
|
||||
<IconAction
|
||||
label={t("Renommer {name}", { name: folder.name })}
|
||||
icon={<PenIcon className="h-4 w-4" />}
|
||||
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,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<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 })
|
||||
}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
void removeTarget({
|
||||
type: "folder",
|
||||
id: folder.id,
|
||||
name: folder.name,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
@@ -633,91 +768,135 @@ export const Browser = () => {
|
||||
{t("Fichiers")}
|
||||
</h2>
|
||||
{visibleFiles.length === 0 ? (
|
||||
<p className="text-xs text-muted-foreground">{t("Rien à afficher pour ce filtre.")}</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t("Rien à afficher pour ce filtre.")}
|
||||
</p>
|
||||
) : (
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{visibleFiles.map((file, index) => (
|
||||
<li
|
||||
key={file.id}
|
||||
className={cn("group flex items-center gap-2 px-3 py-2.5", selected.has(`i:${file.id}`) && "bg-accent/5")}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
|
||||
{visibleFiles.map((file, index) => (
|
||||
<li
|
||||
key={file.id}
|
||||
onClick={() => 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}`)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => 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 })}
|
||||
>
|
||||
<MediaThumb id={file.id} mime={file.mime_type} name={file.name} />
|
||||
</button>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)} ·{" "}
|
||||
{new Date(file.created_at).toLocaleDateString(getLocale())}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
<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)}
|
||||
<input
|
||||
type="checkbox"
|
||||
className={cn(
|
||||
"h-4 w-4 rounded border-border-control transition-opacity",
|
||||
selected.has(`i:${file.id}`) ||
|
||||
selectedItems.length > 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}`);
|
||||
}}
|
||||
/>
|
||||
|
||||
<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"
|
||||
<button
|
||||
type="button"
|
||||
onClick={(event) => {
|
||||
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 })}
|
||||
>
|
||||
<DownloadIcon className="h-3.5 w-3.5" />
|
||||
<span className="hidden sm:inline">{t("Télécharger")}</span>
|
||||
</a>
|
||||
<MediaThumb
|
||||
id={file.id}
|
||||
mime={file.mime_type}
|
||||
name={file.name}
|
||||
/>
|
||||
</button>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate text-sm font-medium text-foreground">
|
||||
{file.name}
|
||||
</span>
|
||||
<span className="block text-[0.6875rem] text-subtle-foreground">
|
||||
{formatBytes(file.size_bytes)} ·{" "}
|
||||
{new Date(file.created_at).toLocaleDateString(
|
||||
getLocale(),
|
||||
)}
|
||||
</span>
|
||||
</span>
|
||||
|
||||
{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>
|
||||
<div className="flex items-center gap-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100 md: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={(event) => {
|
||||
event.stopPropagation();
|
||||
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"
|
||||
onClick={(event) => event.stopPropagation()}
|
||||
>
|
||||
<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={(event) => {
|
||||
event.stopPropagation();
|
||||
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={(event) => {
|
||||
event.stopPropagation();
|
||||
void removeTarget({
|
||||
type: "file",
|
||||
id: file.id,
|
||||
name: file.name,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</section>
|
||||
) : null}
|
||||
@@ -765,7 +944,11 @@ export const Browser = () => {
|
||||
|
||||
{viewer !== null ? (
|
||||
<MediaViewer
|
||||
items={visibleFiles.map((item) => ({ 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)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user