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
+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" />