feat(ui): visionneuse et vignettes, retrait du popup identifiants, en-tete fige (#7)
CD — Déploiement / deploy (push) Successful in 20s

- MediaViewer (image/video/audio/pdf/texte) et MediaThumb (vignette video 1re frame, icones audio/archive)
- Gallery/Browser cables sur le viewer et les vignettes ; lib/media.ts + previewUrl
- Admin: bandeau de succes au lieu du popup "Identifiants generes"
- AppShell/PageHeader: hauteur fixe du viewport + en-tete de page sticky (filtres, recherche, stats figes)

---------

Co-authored-by: xEsiah <[email protected]>
Reviewed-on: #7
Reviewed-by: Esiah <[email protected]>
Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #7.
This commit is contained in:
Gitea Actions
2026-10-16 13:13:25 +00:00
committed by Esiah
co-authored by Esiah
parent c5df5c05f1
commit d49435bbd6
19 changed files with 683 additions and 216 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 138 KiB

After

Width:  |  Height:  |  Size: 426 KiB

+8 -6
View File
@@ -87,8 +87,8 @@ export const AppShell = () => {
};
return (
<div className="flex min-h-dvh bg-background">
<aside className="hidden w-60 shrink-0 flex-col gap-1 border-r border-border bg-surface p-3 lg:flex">
<div className="flex h-dvh overflow-hidden bg-background">
<aside className="hidden w-60 shrink-0 flex-col gap-1 overflow-y-auto border-r border-border bg-surface p-3 lg:flex">
<div className="px-1 py-2">{brand}</div>
{NAV.map(renderLink)}
{isAdmin ? (
@@ -103,7 +103,7 @@ export const AppShell = () => {
</aside>
<div className="flex min-w-0 flex-1 flex-col">
<header className="sticky top-0 z-20 border-b border-border bg-surface">
<header className="z-20 shrink-0 border-b border-border bg-surface">
<div className="mx-auto flex w-full max-w-5xl items-center justify-between gap-4 px-4 py-3">
<div className="flex items-center gap-3">
<button
@@ -161,9 +161,11 @@ export const AppShell = () => {
) : null}
</header>
<main className="mx-auto w-full max-w-5xl flex-1 px-4 py-6">
<Outlet />
</main>
<div className="min-h-0 flex-1 overflow-y-auto">
<main className="mx-auto w-full max-w-5xl px-4 py-6">
<Outlet />
</main>
</div>
</div>
</div>
);
+69
View File
@@ -0,0 +1,69 @@
import { api } from "../lib/api.js";
import { mediaKind } from "../lib/media.js";
import { ArchiveIcon, AudioIcon, FileIcon, PlayIcon } from "./icons.js";
/**
* Vignette d'un fichier, partagee entre le navigateur et la galerie.
* - image : la vignette WebP du backend ;
* - video : la premiere frame, lue en flux par le navigateur (`preload=metadata`
* et fragment `#t=0.1`), avec un bouton lecture en surimpression ;
* - audio / archive / document : une icone dediee.
* Le contenu est `pointer-events-none` : le clic atteint toujours le bouton
* parent qui ouvre l'apercu.
*/
export const MediaThumb = ({
id,
mime,
name,
size = "sm",
}: {
id: string;
mime: string | null;
name: string;
size?: "sm" | "lg";
}) => {
const kind = mediaKind(mime);
if (kind === "image") {
return (
<img
src={api.thumbnailUrl(id)}
alt=""
loading="lazy"
className="pointer-events-none h-full w-full object-cover"
/>
);
}
if (kind === "video") {
const badge = size === "lg" ? "h-9 w-9" : "h-6 w-6";
const glyph = size === "lg" ? "h-4 w-4" : "h-3 w-3";
return (
<span className="relative block h-full w-full bg-black">
<video
src={`${api.previewUrl(id)}#t=0.1`}
preload="metadata"
muted
playsInline
aria-label={name}
className="pointer-events-none h-full w-full object-cover"
/>
<span className="pointer-events-none absolute inset-0 flex items-center justify-center">
<span className={`flex ${badge} items-center justify-center rounded-full bg-black/55 text-white`}>
<PlayIcon className={glyph} />
</span>
</span>
</span>
);
}
if (kind === "audio") {
return <AudioIcon className={`pointer-events-none ${size === "lg" ? "h-8 w-8" : "h-5 w-5"}`} />;
}
if (kind === "archive") {
return (
<ArchiveIcon className={`pointer-events-none ${size === "lg" ? "h-8 w-8" : "h-5 w-5"}`} />
);
}
return <FileIcon className={`pointer-events-none ${size === "lg" ? "h-8 w-8" : "h-5 w-5"}`} />;
};
+214
View File
@@ -0,0 +1,214 @@
import { useEffect, useState } from "react";
import { cn } from "../ui/index.js";
import { api } from "../lib/api.js";
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon, DownloadIcon, FileIcon } from "./icons.js";
export interface MediaViewerItem {
id: string;
name: string;
mime_type: string | null;
}
type Kind = "image" | "video" | "audio" | "pdf" | "text" | "document";
const kindOf = (mime: string | null): Kind => {
const value = (mime ?? "").toLowerCase();
if (value === "image/svg+xml") return "document";
if (value.startsWith("image/")) return "image";
if (value.startsWith("video/")) return "video";
if (value.startsWith("audio/")) return "audio";
if (value === "application/pdf") return "pdf";
if (value === "text/plain") return "text";
return "document";
};
const controlClass =
"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-white/15 bg-black/40 text-white transition-colors hover:bg-black/60";
const actionClass =
"inline-flex items-center gap-2 rounded-md border border-white/20 bg-white/10 px-3.5 py-2 text-sm font-medium text-white transition-colors hover:bg-white/20";
const TextViewer = ({ id }: { id: string }) => {
const [text, setText] = useState<string | null>(null);
const [failed, setFailed] = useState(false);
useEffect(() => {
let active = true;
setText(null);
setFailed(false);
void fetch(api.previewUrl(id))
.then((response) => (response.ok ? response.text() : Promise.reject(new Error("failed"))))
.then((body) => {
if (active) setText(body);
})
.catch(() => {
if (active) setFailed(true);
});
return () => {
active = false;
};
}, [id]);
if (failed) return <p className="text-sm text-white/70">Lecture impossible.</p>;
if (text === null) return <p className="text-sm text-white/70">Chargement…</p>;
return (
<pre className="max-h-full w-full max-w-3xl overflow-auto rounded-md bg-black/60 p-4 text-left text-sm whitespace-pre-wrap text-white/90">
{text}
</pre>
);
};
const Panel = ({
item,
message,
openable,
}: {
item: MediaViewerItem;
message: string;
openable: boolean;
}) => (
<div className="flex w-full max-w-md flex-col items-center gap-4 rounded-xl border border-white/10 bg-black/40 p-8 text-center">
<FileIcon className="h-12 w-12 text-white/60" />
<div className="min-w-0">
<p className="truncate text-sm font-medium text-white">{item.name}</p>
<p className="mt-1 text-xs text-white/60">{message}</p>
</div>
<div className="flex flex-wrap items-center justify-center gap-2">
{openable ? (
<a
href={api.previewUrl(item.id)}
target="_blank"
rel="noopener noreferrer"
className={actionClass}
>
Ouvrir
</a>
) : null}
<a href={api.downloadUrl(item.id)} download={item.name} className={actionClass}>
<DownloadIcon className="h-4 w-4" />
Télécharger
</a>
</div>
</div>
);
const Body = ({ item }: { item: MediaViewerItem }) => {
const kind = kindOf(item.mime_type);
if (kind === "image") {
return (
<img
src={api.previewUrl(item.id)}
alt={item.name}
className="max-h-full max-w-full rounded-md object-contain shadow-2xl"
/>
);
}
if (kind === "video") {
return (
<video
src={api.previewUrl(item.id)}
controls
autoPlay
className="max-h-full max-w-full rounded-md bg-black shadow-2xl"
/>
);
}
if (kind === "audio") {
return (
<div className="flex w-full max-w-md flex-col items-center gap-4 rounded-lg bg-black/40 p-6">
<FileIcon className="h-10 w-10 text-white/70" />
<p className="max-w-full truncate text-sm text-white/90">{item.name}</p>
<audio src={api.previewUrl(item.id)} controls autoPlay className="w-full" />
</div>
);
}
if (kind === "text") return <TextViewer id={item.id} />;
if (kind === "pdf") {
return (
<Panel item={item} message="Le PDF s'ouvre dans un nouvel onglet." openable />
);
}
return <Panel item={item} message="Aperçu indisponible pour ce format." openable={false} />;
};
export const MediaViewer = ({
items,
startIndex,
onClose,
}: {
items: MediaViewerItem[];
startIndex: number;
onClose: () => void;
}) => {
const [index, setIndex] = useState(startIndex);
const current = items[index];
useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") onClose();
if (event.key === "ArrowLeft") setIndex((value) => Math.max(0, value - 1));
if (event.key === "ArrowRight") setIndex((value) => Math.min(items.length - 1, value + 1));
};
window.addEventListener("keydown", onKeyDown);
return () => window.removeEventListener("keydown", onKeyDown);
}, [items.length, onClose]);
if (!current) return null;
return (
<div
className="fixed inset-0 z-50 flex flex-col bg-black/90 backdrop-blur-sm"
role="dialog"
aria-modal="true"
aria-label={current.name}
>
<div className="flex shrink-0 items-center justify-between gap-4 px-4 py-3 text-white">
<p className="min-w-0 truncate text-sm font-medium">{current.name}</p>
<div className="flex shrink-0 items-center gap-2">
<a
href={api.downloadUrl(current.id)}
download={current.name}
className={controlClass}
aria-label="Télécharger"
>
<DownloadIcon className="h-4 w-4" />
</a>
<button type="button" onClick={onClose} className={controlClass} aria-label="Fermer">
<CloseIcon className="h-4 w-4" />
</button>
</div>
</div>
<div
className="relative flex min-h-0 flex-1 items-center justify-center px-4 pb-6"
onClick={(event) => {
if (event.target === event.currentTarget) onClose();
}}
>
{index > 0 ? (
<button
type="button"
onClick={() => setIndex((value) => value - 1)}
className={cn(controlClass, "absolute left-4 z-10")}
aria-label="Fichier précédent"
>
<ArrowLeftIcon className="h-5 w-5" />
</button>
) : null}
<Body item={current} />
{index < items.length - 1 ? (
<button
type="button"
onClick={() => setIndex((value) => value + 1)}
className={cn(controlClass, "absolute right-4 z-10")}
aria-label="Fichier suivant"
>
<ArrowRightIcon className="h-5 w-5" />
</button>
) : null}
</div>
</div>
);
};
+14 -9
View File
@@ -88,21 +88,26 @@ export const PageHeader = ({
title,
description,
actions,
toolbar,
}: {
title: string;
description?: string;
actions?: ReactNode;
toolbar?: ReactNode;
}) => (
<header className="mb-6 flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
<div>
<h1 className="font-display text-base font-semibold uppercase tracking-label text-foreground">
{title}
</h1>
{description ? (
<p className="mt-1 max-w-2xl text-sm leading-relaxed text-muted-foreground">{description}</p>
) : null}
<header className="sticky top-0 z-10 -mx-4 flex flex-col gap-3 border-b border-border bg-background px-4 py-4">
<div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
<div>
<h1 className="font-display text-base font-semibold uppercase tracking-label text-foreground">
{title}
</h1>
{description ? (
<p className="mt-1 max-w-2xl text-sm leading-relaxed text-muted-foreground">{description}</p>
) : null}
</div>
{actions ? <div className="flex flex-wrap items-center gap-2">{actions}</div> : null}
</div>
{actions ? <div className="flex flex-wrap items-center gap-2">{actions}</div> : null}
{toolbar ? <div className="flex flex-col gap-3">{toolbar}</div> : null}
</header>
);
+27
View File
@@ -34,6 +34,27 @@ export const ImageIcon = (props: IconProps) => (
</svg>
);
export const PlayIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M8 5.5v13l11-6.5Z" fill="currentColor" stroke="none" />
</svg>
);
export const AudioIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M9 17V5l10-2v12" />
<circle cx="6.5" cy="17.5" r="2.5" />
<circle cx="16.5" cy="15.5" r="2.5" />
</svg>
);
export const ArchiveIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M3 7.5A1.5 1.5 0 0 1 4.5 6h4l2 2.5h7A1.5 1.5 0 0 1 19 10v7.5A1.5 1.5 0 0 1 17.5 19h-13A1.5 1.5 0 0 1 3 17.5Z" />
<path d="M11 11.5h2m-2 3h2m-2 3h2" />
</svg>
);
export const UploadIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5M4 17v1.5A1.5 1.5 0 0 0 5.5 20h13a1.5 1.5 0 0 0 1.5-1.5V17" />
@@ -151,6 +172,12 @@ export const ArrowLeftIcon = (props: IconProps) => (
</svg>
);
export const ArrowRightIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M5 12h14M13 6l6 6-6 6" />
</svg>
);
export const PenIcon = (props: IconProps) => (
<svg {...base(props)}>
<path d="M4 20h4L18.5 9.5a2.1 2.1 0 0 0-3-3L5 17v3Z" />
+3 -2
View File
@@ -294,6 +294,7 @@ export const api = {
deleteFile: (id: string) => del<{ ok: boolean }>(`/files/${encodeURIComponent(id)}`),
downloadUrl: (id: string) => `${BASE}/files/${encodeURIComponent(id)}/download`,
thumbnailUrl: (id: string) => `${BASE}/files/${encodeURIComponent(id)}/thumbnail`,
previewUrl: (id: string) => `${BASE}/files/${encodeURIComponent(id)}/preview`,
// --- Corbeille, recherche, galerie ------------------------------------
trash: () =>
@@ -324,7 +325,7 @@ export const api = {
role_slug: string;
quota_bytes?: number | null;
max_file_bytes?: number | null;
}) => post<{ user: AdminUser; password: string }>("/admin/users", payload),
}) => post<{ user: AdminUser }>("/admin/users", payload),
adminUpdateUser: (
id: string,
payload: Partial<{
@@ -338,7 +339,7 @@ export const api = {
) => patch<{ user: AdminUser }>(`/admin/users/${encodeURIComponent(id)}`, payload),
adminDeleteUser: (id: string) => del<{ ok: boolean }>(`/admin/users/${encodeURIComponent(id)}`),
adminResetPassword: (id: string) =>
post<{ password: string }>(`/admin/users/${encodeURIComponent(id)}/reset-password`),
post<{ ok: boolean }>(`/admin/users/${encodeURIComponent(id)}/reset-password`),
adminStorageLocations: () =>
request<{ locations: StorageLocation[] }>("/admin/storage-locations"),
adminCreateStorageLocation: (payload: {
+30
View File
@@ -0,0 +1,30 @@
export type MediaKind = "image" | "video" | "audio" | "document" | "archive" | "other";
/** Miroir de `classify()` cote backend, pour choisir la vignette d'un fichier. */
export const mediaKind = (mime: string | null): MediaKind => {
const value = (mime ?? "").toLowerCase();
if (value.startsWith("image/")) return "image";
if (value.startsWith("video/")) return "video";
if (value.startsWith("audio/")) return "audio";
if (
value === "application/pdf" ||
value.startsWith("text/") ||
value.includes("word") ||
value.includes("excel") ||
value.includes("presentation") ||
value.includes("opendocument")
) {
return "document";
}
if (
value.includes("zip") ||
value.includes("tar") ||
value.includes("gzip") ||
value.includes("rar") ||
value.includes("7z") ||
value.includes("compressed")
) {
return "archive";
}
return "other";
};
+67 -94
View File
@@ -47,7 +47,7 @@ export const AdminUsers = () => {
const [busy, setBusy] = useState<string | null>(null);
const [createOpen, setCreateOpen] = useState(false);
const [edit, setEdit] = useState<AdminUser | null>(null);
const [credentials, setCredentials] = useState<{ email: string; password: string } | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const termRef = useRef("");
const load = async (term: string) => {
@@ -86,9 +86,10 @@ export const AdminUsers = () => {
const resetPassword = async (user: AdminUser) => {
setBusy(user.id);
setError(null);
setNotice(null);
try {
const { password } = await api.adminResetPassword(user.id);
setCredentials({ email: user.email, password });
await api.adminResetPassword(user.id);
setNotice(`Mot de passe réinitialisé. Les identifiants ont été envoyés à ${user.email}.`);
} catch (caught) {
setError(messageOf(caught, "Réinitialisation impossible."));
} finally {
@@ -135,38 +136,42 @@ export const AdminUsers = () => {
Nouveau membre
</Button>
}
toolbar={
<>
{stats ? (
<div className="grid grid-cols-3 gap-3">
<StatCard label="Membres" value={String(stats.users)} />
<StatCard label="Fichiers" value={String(stats.files)} />
<StatCard label="Stockage" value={`${toGb(stats.usedBytes)} Go`} />
</div>
) : null}
<form
className="flex items-end gap-2"
onSubmit={(event) => {
event.preventDefault();
void load(q);
}}
>
<div className="flex-1">
<Input
label="Rechercher"
type="search"
placeholder="nom ou e-mail"
value={q}
onChange={(event) => setQ(event.target.value)}
/>
</div>
<Button type="submit" size="md" variant="secondary">
Filtrer
</Button>
</form>
</>
}
/>
{stats ? (
<div className="grid grid-cols-3 gap-3">
<StatCard label="Membres" value={String(stats.users)} />
<StatCard label="Fichiers" value={String(stats.files)} />
<StatCard label="Stockage" value={`${toGb(stats.usedBytes)} Go`} />
</div>
) : null}
<form
className="flex items-end gap-2"
onSubmit={(event) => {
event.preventDefault();
void load(q);
}}
>
<div className="flex-1">
<Input
label="Rechercher"
type="search"
placeholder="nom ou e-mail"
value={q}
onChange={(event) => setQ(event.target.value)}
/>
</div>
<Button type="submit" size="md" variant="secondary">
Filtrer
</Button>
</form>
{error ? <Alert>{error}</Alert> : null}
{notice ? <Alert tone="success">{notice}</Alert> : null}
{users === null ? (
<div className="flex justify-center py-16">
@@ -227,9 +232,9 @@ export const AdminUsers = () => {
{createOpen ? (
<CreateUserDialog
onClose={() => setCreateOpen(false)}
onCreated={(email, password) => {
onCreated={(email) => {
setCreateOpen(false);
setCredentials({ email, password });
setNotice(`Compte créé. Les identifiants ont été envoyés à ${email}.`);
void load(termRef.current);
}}
/>
@@ -245,52 +250,16 @@ export const AdminUsers = () => {
}}
/>
) : null}
<CredentialsModal credentials={credentials} onClose={() => setCredentials(null)} />
</div>
);
};
const CredentialsModal = ({
credentials,
onClose,
}: {
credentials: { email: string; password: string } | null;
onClose: () => void;
}) => {
if (!credentials) return null;
return (
<Modal open title="Identifiants générés" onClose={onClose}>
<div className="flex flex-col gap-4">
<Alert tone="success">
Transmettez ces informations par un canal sûr : le mot de passe ne sera plus affiché.
</Alert>
<dl className="flex flex-col gap-2 text-xs">
<div>
<dt className="text-subtle-foreground">Adresse</dt>
<dd className="font-medium text-foreground">{credentials.email}</dd>
</div>
<div>
<dt className="text-subtle-foreground">Mot de passe</dt>
<dd className="break-all font-mono text-foreground">{credentials.password}</dd>
</div>
</dl>
<div className="flex justify-end">
<Button size="md" onClick={onClose}>
Terminé
</Button>
</div>
</div>
</Modal>
);
};
const CreateUserDialog = ({
onClose,
onCreated,
}: {
onClose: () => void;
onCreated: (email: string, password: string) => void;
onCreated: (email: string) => void;
}) => {
const [email, setEmail] = useState("");
const [firstName, setFirstName] = useState("");
@@ -306,7 +275,7 @@ const CreateUserDialog = ({
setBusy(true);
setError(null);
try {
const { user, password } = await api.adminCreateUser({
const { user } = await api.adminCreateUser({
email: email.trim(),
first_name: firstName.trim(),
last_name: lastName.trim(),
@@ -314,7 +283,7 @@ const CreateUserDialog = ({
quota_bytes: quotaGb ? Math.round(Number(quotaGb) * GB) : null,
max_file_bytes: maxFileMb ? Math.round(Number(maxFileMb) * MB) : null,
});
onCreated(user.email, password);
onCreated(user.email);
} catch (caught) {
setError(messageOf(caught, "Création impossible."));
} finally {
@@ -696,27 +665,31 @@ export const AdminAudit = () => {
return (
<div className="flex flex-col gap-5">
<PageHeader title="Journal d'activité" description="Dernières actions enregistrées." />
<form
className="flex items-end gap-2"
onSubmit={(event) => {
event.preventDefault();
void load(action);
}}
>
<div className="flex-1">
<Input
label="Filtrer par action"
placeholder="auth.login, file.upload…"
value={action}
onChange={(event) => setAction(event.target.value)}
/>
</div>
<Button type="submit" variant="secondary" size="md">
Filtrer
</Button>
</form>
<PageHeader
title="Journal d'activité"
description="Dernières actions enregistrées."
toolbar={
<form
className="flex items-end gap-2"
onSubmit={(event) => {
event.preventDefault();
void load(action);
}}
>
<div className="flex-1">
<Input
label="Filtrer par action"
placeholder="auth.login, file.upload…"
value={action}
onChange={(event) => setAction(event.target.value)}
/>
</div>
<Button type="submit" variant="secondary" size="md">
Filtrer
</Button>
</form>
}
/>
{error ? <Alert>{error}</Alert> : null}
+25 -21
View File
@@ -10,6 +10,8 @@ import {
import { useSession } from "../lib/session.js";
import { Alert, 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";
import { IconAction } from "../components/IconAction.js";
import {
CreateFolderDialog,
@@ -20,7 +22,6 @@ import {
import {
ArrowLeftIcon,
DownloadIcon,
FileIcon,
FolderIcon,
MoveIcon,
PenIcon,
@@ -45,9 +46,6 @@ type Dialog =
| { kind: "share"; folder: Folder }
| null;
const isImage = (file: UploadedFile): boolean =>
(file.mime_type ?? "").toLowerCase().startsWith("image/");
export const Browser = () => {
const { user, refresh } = useSession();
const confirm = useConfirm();
@@ -59,6 +57,7 @@ export const Browser = () => {
const [uploading, setUploading] = useState(false);
const [removing, setRemoving] = useState<string | null>(null);
const [dialog, setDialog] = useState<Dialog>(null);
const [viewer, setViewer] = useState<number | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
const current = path[path.length - 1] ?? { id: null, name: "Racine" };
@@ -165,9 +164,8 @@ export const Browser = () => {
<PageHeader
title={current.name}
description="Vos dossiers et fichiers. Envoyez un fichier ou créez un dossier."
/>
<div className="flex flex-wrap items-center gap-3">
toolbar={
<div className="flex flex-wrap items-center gap-3">
{path.length > 1 ? (
<button
type="button"
@@ -205,7 +203,9 @@ export const Browser = () => {
))}
</ol>
</nav>
</div>
</div>
}
/>
<Card>
<div className="flex flex-col gap-3 p-4 sm:flex-row sm:items-center sm:justify-between">
@@ -353,20 +353,16 @@ export const Browser = () => {
Fichiers
</h2>
<ul className="flex flex-col divide-y divide-border rounded-lg border border-border bg-surface">
{files.map((file) => (
{files.map((file, index) => (
<li key={file.id} className="flex items-center gap-2 px-3 py-2.5">
<span 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">
{isImage(file) ? (
<img
src={api.thumbnailUrl(file.id)}
alt=""
loading="lazy"
className="h-full w-full object-cover"
/>
) : (
<FileIcon className="h-5 w-5" />
)}
</span>
<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={`Aperçu de ${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}
@@ -471,6 +467,14 @@ export const Browser = () => {
{dialog?.kind === "share" ? (
<ShareDialog folder={dialog.folder} onClose={() => setDialog(null)} />
) : null}
{viewer !== null ? (
<MediaViewer
items={files.map((item) => ({ id: item.id, name: item.name, mime_type: item.mime_type }))}
startIndex={viewer}
onClose={() => setViewer(null)}
/>
) : null}
</div>
);
};
+56 -44
View File
@@ -2,7 +2,9 @@ import { useCallback, useEffect, useState } from "react";
import { Button, Spinner, cn } from "../ui/index.js";
import { ApiError, api, formatBytes, type MediaItem } from "../lib/api.js";
import { Alert, EmptyState, PageHeader } from "../components/feedback.js";
import { FileIcon, ImageIcon } from "../components/icons.js";
import { MediaViewer } from "../components/MediaViewer.js";
import { MediaThumb } from "../components/MediaThumb.js";
import { ImageIcon } from "../components/icons.js";
const KINDS = [
{ value: "", label: "Tout" },
@@ -22,6 +24,7 @@ export const Gallery = () => {
const [loading, setLoading] = useState(true);
const [loadingMore, setLoadingMore] = useState(false);
const [error, setError] = useState<string | null>(null);
const [viewer, setViewer] = useState<number | null>(null);
useEffect(() => {
setLoading(true);
@@ -56,31 +59,32 @@ export const Gallery = () => {
<PageHeader
title="Galerie"
description="Parcourez les médias auxquels vous avez accès."
toolbar={
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label="Filtrer par type">
{KINDS.map((option) => (
<button
key={option.value}
type="button"
role="tab"
aria-selected={kind === option.value}
onClick={() => {
setKind(option.value);
setItems([]);
}}
className={cn(
"rounded-sm border px-3 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label transition-colors",
kind === option.value
? "border-accent/50 bg-accent/10 text-accent"
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
)}
>
{option.label}
</button>
))}
</div>
}
/>
<div className="flex flex-wrap gap-1.5" role="tablist" aria-label="Filtrer par type">
{KINDS.map((option) => (
<button
key={option.value}
type="button"
role="tab"
aria-selected={kind === option.value}
onClick={() => {
setKind(option.value);
setItems([]);
}}
className={cn(
"rounded-sm border px-3 py-1.5 font-display text-[0.6875rem] font-semibold uppercase tracking-label transition-colors",
kind === option.value
? "border-accent/50 bg-accent/10 text-accent"
: "border-border-control text-muted-foreground hover:bg-surface-hover hover:text-foreground",
)}
>
{option.label}
</button>
))}
</div>
{error ? <Alert>{error}</Alert> : null}
{loading ? (
@@ -96,24 +100,13 @@ export const Gallery = () => {
) : (
<>
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
{items.map((item) => (
<li key={item.id}>
<a
href={api.downloadUrl(item.id)}
download={item.name}
className="group flex flex-col overflow-hidden rounded-lg border border-border bg-surface transition-colors hover:border-border-strong"
>
{items.map((item, index) => {
const cardClass =
"group flex w-full flex-col overflow-hidden rounded-lg border border-border bg-surface text-left transition-colors hover:border-border-strong";
const inner = (
<>
<span className="flex aspect-square items-center justify-center overflow-hidden bg-surface-muted text-muted-foreground">
{item.kind === "image" && item.has_thumbnail ? (
<img
src={api.thumbnailUrl(item.id)}
alt={item.name}
loading="lazy"
className="h-full w-full object-cover transition-transform duration-fast group-hover:scale-[1.02]"
/>
) : (
<FileIcon className="h-8 w-8" />
)}
<MediaThumb id={item.id} mime={item.mime_type} name={item.name} size="lg" />
</span>
<span className="flex flex-col gap-0.5 p-2">
<span className="truncate text-xs font-medium text-foreground">
@@ -123,9 +116,16 @@ export const Gallery = () => {
{formatBytes(item.size_bytes)}
</span>
</span>
</a>
</li>
))}
</>
);
return (
<li key={item.id}>
<button type="button" onClick={() => setViewer(index)} className={cardClass}>
{inner}
</button>
</li>
);
})}
</ul>
{items.length >= PAGE ? (
@@ -137,6 +137,18 @@ export const Gallery = () => {
) : null}
</>
)}
{viewer !== null ? (
<MediaViewer
items={items.map((item) => ({
id: item.id,
name: item.name,
mime_type: item.mime_type,
}))}
startIndex={viewer}
onClose={() => setViewer(null)}
/>
) : null}
</div>
);
};
+22 -21
View File
@@ -42,29 +42,30 @@ export const Search = () => {
<PageHeader
title="Recherche"
description="Recherchez par nom dans les dossiers et fichiers auxquels vous avez accès."
toolbar={
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
<div className="flex-1">
<Input
label="Terme recherché"
type="search"
autoFocus
placeholder="facture, rapport…"
value={q}
onChange={(event) => setQ(event.target.value)}
/>
</div>
<Button
type="submit"
size="md"
isLoading={loading}
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
>
Rechercher
</Button>
</form>
}
/>
<form className="flex items-end gap-2" onSubmit={(event) => void submit(event)}>
<div className="flex-1">
<Input
label="Terme recherché"
type="search"
autoFocus
placeholder="facture, rapport…"
value={q}
onChange={(event) => setQ(event.target.value)}
/>
</div>
<Button
type="submit"
size="md"
isLoading={loading}
iconLeading={<SearchIcon className="h-3.5 w-3.5" />}
>
Rechercher
</Button>
</form>
{error ? <Alert>{error}</Alert> : null}
{loading ? (