Every upload and save (Upload, Frame at, Video thumbnails, a clip's Save to library) has a prefilled Name box; the name is also the readable part of the file's name, plus a short random ending. Fetch preview names its picture after the page. Rename on the Media page changes both, moving the file and its small copy and pointing every record that names it at the new path in one transaction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
671 lines
23 KiB
TypeScript
671 lines
23 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
ADMIN: MEDIA
|
|
|
|
Two tabs. Images: the uploaded-image library: search it, add to
|
|
it, copy a file's path, delete what nothing needs. Image fields in
|
|
the editors upload and pick from the same library
|
|
(MediaLibrary.tsx), so this is housekeeping rather than the way
|
|
images get in. Files: documents, audio and zips in the shared
|
|
Google Drive, for pages to link to (DriveFiles.tsx); link fields'
|
|
"Choose a file" picks from them. Requests: every file sent with
|
|
the Request form, by type folder in Drive, each with its request;
|
|
a file Drive no longer has is marked missing.
|
|
|
|
Two ranks, as on the server: editors and up upload, admins and
|
|
up delete. A delete first asks the server which records still
|
|
name the file, since nothing stops one being removed from under
|
|
a page (an image field stores the path, not a foreign key).
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { useEffect, useState, type FormEvent } from "react";
|
|
import { Link } from "react-router-dom";
|
|
|
|
import { ApiError, del, get, patch, post } from "../../lib/api.ts";
|
|
import { useAuth } from "../../lib/auth.tsx";
|
|
import { canDelete, canWrite as roleCanWrite } from "../../lib/roles.ts";
|
|
import {
|
|
ALL_FOLDERS,
|
|
DriveFolderTabs,
|
|
FILE_HELP,
|
|
FileList,
|
|
FileUploadButton,
|
|
RefusedNote,
|
|
inFolder,
|
|
useDriveFiles,
|
|
type DriveFile,
|
|
} from "../../components/admin/DriveFiles.tsx";
|
|
import {
|
|
FolderTabs,
|
|
formatBytes,
|
|
MediaGrid,
|
|
NameBox,
|
|
UPLOAD_HELP,
|
|
UploadButton,
|
|
useMediaLibrary,
|
|
type MediaItem,
|
|
} from "../../components/admin/MediaLibrary.tsx";
|
|
|
|
type Use = { table: string; count: number };
|
|
|
|
/* `base` is where the item lives: /admin/media or /admin/files. */
|
|
function DeleteControl({
|
|
item,
|
|
base = "/admin/media",
|
|
broken = "Those will show no image.",
|
|
onDeleted,
|
|
}: {
|
|
item: { id: number };
|
|
base?: string;
|
|
broken?: string;
|
|
onDeleted: () => void;
|
|
}) {
|
|
const [uses, setUses] = useState<Use[] | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
async function ask() {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const data = await get(`${base}/${item.id}/uses`, { ttl: 0 });
|
|
setUses(data.uses);
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't check where it's used.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
async function remove() {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
await del(`${base}/${item.id}`);
|
|
onDeleted();
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't delete that.");
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
if (uses === null) {
|
|
return (
|
|
<>
|
|
<button
|
|
type="button"
|
|
onClick={ask}
|
|
disabled={busy}
|
|
className="text-xs text-muted hover:text-danger"
|
|
>
|
|
Delete
|
|
</button>
|
|
{error && <p className="mt-1 text-xs text-danger">{error}</p>}
|
|
</>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="bg-danger-tint p-2 text-xs text-body">
|
|
{uses.length > 0 ? (
|
|
<p>
|
|
Still used by{" "}
|
|
{uses.map((use) => `${use.count} in ${use.table.replace(/_/g, " ")}`).join(", ")}. {broken}
|
|
</p>
|
|
) : (
|
|
<p>Nothing uses this file.</p>
|
|
)}
|
|
<div className="mt-2 flex gap-3">
|
|
<button
|
|
type="button"
|
|
onClick={remove}
|
|
disabled={busy}
|
|
className="font-medium text-danger hover:underline"
|
|
>
|
|
{busy ? "Deleting…" : "Delete for good"}
|
|
</button>
|
|
<button type="button" onClick={() => setUses(null)} className="text-muted hover:underline">
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
{error && <p className="mt-1 text-danger">{error}</p>}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/* Rename: the library's name and the file's own. Opening it asks what
|
|
uses the file first, since the server repoints those records at the
|
|
new address and anything outside the site (a sent newsletter, a
|
|
shared link) keeps the old one, which stops working. */
|
|
function RenameControl({ item, onRenamed }: { item: MediaItem; onRenamed: (item: MediaItem) => void }) {
|
|
const [name, setName] = useState<string | null>(null);
|
|
const [uses, setUses] = useState<Use[] | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
async function open() {
|
|
setName(item.original_name);
|
|
setError(null);
|
|
setUses(null);
|
|
try {
|
|
setUses((await get(`/admin/media/${item.id}/uses`, { ttl: 0 })).uses);
|
|
} catch {
|
|
setUses([]);
|
|
}
|
|
}
|
|
|
|
async function save(e: FormEvent) {
|
|
e.preventDefault();
|
|
if (!name?.trim()) return;
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const { media } = await patch(`/admin/media/${item.id}`, { name });
|
|
onRenamed(media);
|
|
setName(null);
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't rename that.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
if (name === null) {
|
|
return (
|
|
<button type="button" onClick={open} className="text-xs text-link hover:underline">
|
|
Rename
|
|
</button>
|
|
);
|
|
}
|
|
|
|
const count = uses?.reduce((sum, use) => sum + use.count, 0) ?? 0;
|
|
return (
|
|
<form onSubmit={save} className="w-full space-y-2 bg-tint p-2 text-xs text-body">
|
|
<NameBox value={name} onChange={setName} />
|
|
<p className="text-muted">
|
|
{uses === null
|
|
? "Checking what uses it…"
|
|
: `Also renames the file${count > 0 ? `, and updates the ${count} record${count === 1 ? "" : "s"} using it` : ""}. Links to the old address outside the site (eg. a sent newsletter) will stop working.`}
|
|
</p>
|
|
<div className="flex gap-3">
|
|
<button type="submit" disabled={busy || !name.trim()} className="font-medium text-link hover:underline disabled:opacity-50">
|
|
{busy ? "Renaming…" : "Save name"}
|
|
</button>
|
|
<button type="button" onClick={() => setName(null)} className="text-muted hover:underline">
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
{error && <p className="text-danger">{error}</p>}
|
|
</form>
|
|
);
|
|
}
|
|
|
|
function CopyPath({ url, label = "Copy path" }: { url: string; label?: string }) {
|
|
const [copied, setCopied] = useState(false);
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
navigator.clipboard?.writeText(url).then(() => {
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 1500);
|
|
});
|
|
}}
|
|
className="text-xs text-link hover:underline"
|
|
>
|
|
{copied ? "Copied" : label}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
/* The folder showing: make one inside it, rename it, or delete it
|
|
when it's empty. Drive is the source; the list reloads after. */
|
|
function FolderControls({ tab, onChanged }: { tab: string; onChanged: (tab: string) => void }) {
|
|
const { user } = useAuth();
|
|
const [mode, setMode] = useState<"new" | "rename" | null>(null);
|
|
const [name, setName] = useState("");
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const inside = tab === ALL_FOLDERS ? "" : tab;
|
|
const button = "btn border border-brand px-3 py-1 text-xs text-link transition-colors hover:bg-tint disabled:opacity-50";
|
|
|
|
async function run(work: () => Promise<string>) {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
onChanged(await work());
|
|
setMode(null);
|
|
setName("");
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't reach the server.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
const submit = () =>
|
|
run(async () =>
|
|
mode === "new"
|
|
? (await post("/admin/files/folders", { path: inside ? `${inside}/${name}` : name })).path
|
|
: (await patch("/admin/files/folders", { path: inside, name })).path,
|
|
);
|
|
const remove = () =>
|
|
run(async () => {
|
|
await del(`/admin/files/folders?path=${encodeURIComponent(inside)}`);
|
|
return inside.split("/").slice(0, -1).join("/") || ALL_FOLDERS;
|
|
});
|
|
|
|
if (!roleCanWrite(user)) return null;
|
|
return (
|
|
<div className="mt-3 flex flex-wrap items-center gap-2">
|
|
{mode ? (
|
|
<>
|
|
<label htmlFor="folder-name" className="sr-only">
|
|
Folder name
|
|
</label>
|
|
<input
|
|
id="folder-name"
|
|
value={name}
|
|
autoFocus
|
|
maxLength={60}
|
|
onChange={(e) => setName(e.target.value)}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "Enter" && name.trim()) submit();
|
|
if (e.key === "Escape") setMode(null);
|
|
}}
|
|
placeholder={mode === "new" ? "New folder's name" : "New name"}
|
|
className="border border-muted/25 bg-surface px-3 py-1 text-sm text-body outline-none focus:border-brand"
|
|
/>
|
|
<button type="button" className={button} disabled={busy || !name.trim()} onClick={submit}>
|
|
{mode === "new" ? (inside ? `Make it in ${inside}` : "Make folder") : "Rename"}
|
|
</button>
|
|
<button type="button" className="text-xs text-muted hover:underline" onClick={() => setMode(null)}>
|
|
Cancel
|
|
</button>
|
|
</>
|
|
) : (
|
|
<>
|
|
<button type="button" className={button} onClick={() => setMode("new")}>
|
|
New folder{inside ? ` in ${inside}` : ""}
|
|
</button>
|
|
{inside && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
onClick={() => {
|
|
setMode("rename");
|
|
setName(inside.split("/").pop() ?? "");
|
|
}}
|
|
>
|
|
Rename {inside}
|
|
</button>
|
|
)}
|
|
{inside && canDelete(user) && (
|
|
<button type="button" className={`${button} border-danger/40 text-danger`} disabled={busy} onClick={remove}>
|
|
Delete {inside} (if empty)
|
|
</button>
|
|
)}
|
|
</>
|
|
)}
|
|
{error && <span className="text-xs text-danger">{error}</span>}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
/* A file's folder, changed in place. */
|
|
function MoveControl({ file, folders, onMoved }: { file: DriveFile; folders: string[]; onMoved: (file: DriveFile) => void }) {
|
|
const [busy, setBusy] = useState(false);
|
|
const [error, setError] = useState<string | null>(null);
|
|
return (
|
|
<div className="w-full">
|
|
<label className="flex items-center gap-2 text-xs text-muted">
|
|
Folder
|
|
<select
|
|
value={file.folder}
|
|
disabled={busy}
|
|
onChange={async (e) => {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
onMoved((await patch(`/admin/files/${file.id}`, { folder: e.target.value })).file);
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't move it.");
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}}
|
|
className="border border-muted/25 bg-surface px-1.5 py-0.5 text-xs text-body"
|
|
>
|
|
<option value="">Not in a folder</option>
|
|
{folders.map((f) => (
|
|
<option key={f} value={f}>
|
|
{f}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
{error && <p className="mt-1 text-xs text-danger">{error}</p>}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function FilesTab() {
|
|
const { user } = useAuth();
|
|
const [query, setQuery] = useState("");
|
|
const { items, folders, ready, refused, error, reload, setItems } = useDriveFiles(query);
|
|
const [tab, setTab] = useState(ALL_FOLDERS);
|
|
const replace = (file: DriveFile) => setItems((current) => (current ?? []).map((f) => (f.id === file.id ? file : f)));
|
|
|
|
return (
|
|
<>
|
|
<div className="mt-6 flex flex-wrap items-start gap-6">
|
|
{roleCanWrite(user) && ready && (
|
|
<div className="max-w-md">
|
|
<FileUploadButton
|
|
label={tab && tab !== ALL_FOLDERS ? `Upload files into ${tab}` : "Upload files"}
|
|
folder={tab === ALL_FOLDERS ? "" : tab}
|
|
onUploaded={(file) => setItems((current) => [file, ...(current ?? [])])}
|
|
/>
|
|
<p className="mt-1 text-xs text-muted">{FILE_HELP}</p>
|
|
</div>
|
|
)}
|
|
<input
|
|
type="search"
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
placeholder="Search by file name"
|
|
aria-label="Search by file name"
|
|
className="ml-auto w-64 border border-muted/25 px-3 py-2 text-sm outline-none focus:border-brand"
|
|
/>
|
|
</div>
|
|
{!ready && (
|
|
<p className="mt-4 text-sm text-danger">
|
|
Google Drive isn't set up on the server (docs/google-drive-and-mail.md), so files can't be uploaded.
|
|
</p>
|
|
)}
|
|
{ready && (
|
|
<div className="mt-6">
|
|
<DriveFolderTabs folders={folders} value={tab} onChange={setTab} />
|
|
<FolderControls
|
|
tab={tab}
|
|
onChanged={(next) => {
|
|
setTab(next);
|
|
reload();
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<div className="mt-6">
|
|
<RefusedNote names={refused} />
|
|
{error ? (
|
|
<p className="text-sm text-danger">{error}</p>
|
|
) : items === null ? (
|
|
<p className="text-sm text-muted">Loading…</p>
|
|
) : (
|
|
<FileList
|
|
items={inFolder(items, tab)}
|
|
renderActions={(file) => (
|
|
<div className="flex flex-wrap items-start gap-x-3 gap-y-1">
|
|
{roleCanWrite(user) && <MoveControl file={file} folders={folders} onMoved={replace} />}
|
|
<CopyPath url={file.url} label="Copy link" />
|
|
<a href={file.url} target="_blank" rel="noreferrer" className="text-xs text-link hover:underline">
|
|
Open in Drive
|
|
</a>
|
|
{canDelete(user) && (
|
|
<div className="w-full">
|
|
<DeleteControl
|
|
item={file}
|
|
base="/admin/files"
|
|
broken="Those links will stop working."
|
|
onDeleted={() => setItems((current) => (current ?? []).filter((f) => f.id !== file.id))}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
/>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
/* Request form files, by their type's folder in Drive (Requests/…). */
|
|
function RequestFilesTab() {
|
|
const { user } = useAuth();
|
|
const [data, setData] = useState<any>(null);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [folder, setFolder] = useState("*");
|
|
const [confirming, setConfirming] = useState<number | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
useEffect(() => {
|
|
get("/admin/request-files", { ttl: 0 })
|
|
.then(setData)
|
|
.catch((err) => setError(err instanceof ApiError ? err.message : "Couldn't load the request files."));
|
|
}, []);
|
|
|
|
async function remove(file) {
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
await del(`/admin/feedback/${file.feedback_id}/files/${file.id}`);
|
|
setData((current) => ({ ...current, files: current.files.filter((f) => f.id !== file.id) }));
|
|
} catch (err) {
|
|
setError(err instanceof ApiError ? err.message : "Couldn't remove it.");
|
|
} finally {
|
|
setBusy(false);
|
|
setConfirming(null);
|
|
}
|
|
}
|
|
|
|
if (error && !data) return <p className="mt-6 text-sm text-danger">{error}</p>;
|
|
if (!data) return <p className="mt-6 text-sm text-muted">Loading…</p>;
|
|
const counts = new Map<string, number>();
|
|
for (const f of data.files) counts.set(f.folder, (counts.get(f.folder) ?? 0) + 1);
|
|
const shown = folder === "*" ? data.files : data.files.filter((f) => f.folder === folder);
|
|
|
|
return (
|
|
<div className="mt-6">
|
|
<div role="tablist" aria-label="Request folders" className="flex flex-wrap gap-1">
|
|
{[["*", "All"], ...data.folders.map((f) => [f, f])].map(([id, label]) => (
|
|
<button
|
|
key={id}
|
|
type="button"
|
|
role="tab"
|
|
aria-selected={folder === id}
|
|
onClick={() => setFolder(id)}
|
|
className={
|
|
"btn px-3 py-1 text-sm transition-colors " +
|
|
(folder === id ? "bg-action font-semibold text-white" : "border border-muted/25 text-muted hover:border-brand/50")
|
|
}
|
|
>
|
|
{label}
|
|
{id !== "*" && counts.get(id) ? ` (${counts.get(id)})` : ""}
|
|
</button>
|
|
))}
|
|
</div>
|
|
{!data.checked && (
|
|
<p className="mt-3 text-sm text-muted">Drive couldn't be asked just now, so missing files aren't marked.</p>
|
|
)}
|
|
{error && <p className="mt-3 text-sm text-danger">{error}</p>}
|
|
|
|
{shown.length === 0 ? (
|
|
<p className="mt-6 text-sm text-muted">No request files here.</p>
|
|
) : (
|
|
<ul className="mt-6 divide-y divide-brand/10 border border-brand/20 bg-surface">
|
|
{shown.map((file) => (
|
|
<li key={file.id} className="flex flex-wrap items-center gap-x-4 gap-y-1 px-4 py-3 text-sm">
|
|
{file.missing ? (
|
|
<span className="font-medium text-muted line-through">{file.name}</span>
|
|
) : (
|
|
<a
|
|
href={`/api/admin/feedback/${file.feedback_id}/files/${file.id}`}
|
|
download={file.name}
|
|
className="font-medium text-link underline underline-offset-2"
|
|
>
|
|
{file.name}
|
|
</a>
|
|
)}
|
|
<span className="text-xs text-muted">{formatBytes(file.size)}</span>
|
|
{file.missing && (
|
|
<span className="bg-danger-tint px-2 py-0.5 text-xs font-medium text-danger">Missing from Drive</span>
|
|
)}
|
|
<Link to="/admin/requests" className="text-xs text-muted hover:text-link hover:underline">
|
|
Request #{file.feedback_id}
|
|
{file.subject ? `: ${file.subject}` : ""} ({file.status})
|
|
</Link>
|
|
{canDelete(user) && (
|
|
<span className="ml-auto">
|
|
{confirming === file.id ? (
|
|
<>
|
|
<button
|
|
type="button"
|
|
disabled={busy}
|
|
onClick={() => remove(file)}
|
|
className="btn bg-danger px-3 py-0.5 text-xs text-white disabled:opacity-60"
|
|
>
|
|
{busy ? "Removing…" : "Remove it"}
|
|
</button>{" "}
|
|
<button type="button" onClick={() => setConfirming(null)} className="text-xs text-muted hover:underline">
|
|
Keep it
|
|
</button>
|
|
</>
|
|
) : (
|
|
<button type="button" onClick={() => setConfirming(file.id)} className="text-xs text-muted hover:text-danger">
|
|
Remove
|
|
</button>
|
|
)}
|
|
</span>
|
|
)}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const TABS = [
|
|
["images", "Images"],
|
|
["files", "Files"],
|
|
["requests", "Requests"],
|
|
] as const;
|
|
|
|
export default function AdminMedia() {
|
|
const { user } = useAuth();
|
|
const [tab, setTab] = useState<(typeof TABS)[number][0]>("images");
|
|
// The image folder showing; "" is all of them, clips included.
|
|
const [folder, setFolder] = useState("");
|
|
const [query, setQuery] = useState("");
|
|
const { items, error, setItems } = useMediaLibrary(query, undefined, folder);
|
|
|
|
return (
|
|
<div>
|
|
<div className="flex flex-wrap items-baseline gap-3">
|
|
<h1 className="text-2xl font-bold text-link">Media</h1>
|
|
<p className="text-sm text-muted">
|
|
{tab === "images"
|
|
? "Uploaded images. Image fields in every editor pick from here."
|
|
: tab === "files"
|
|
? "Files in the shared Google Drive's Media folder, for pages to link to, including any put there in Drive itself. Link fields pick from here with Choose a file."
|
|
: "Files sent with the Request form, in the shared Google Drive's Requests folder. Removing one takes it off its request too."}
|
|
</p>
|
|
</div>
|
|
|
|
<nav aria-label="Media" className="mt-4 flex gap-1 border-b border-brand/15">
|
|
{TABS.map(([id, label]) => (
|
|
<button
|
|
key={id}
|
|
type="button"
|
|
aria-current={tab === id ? "page" : undefined}
|
|
onClick={() => setTab(id)}
|
|
className={
|
|
"-mb-px border-b-2 px-4 py-2 text-sm font-semibold transition-colors " +
|
|
(tab === id ? "border-link text-link" : "border-transparent text-muted hover:text-link")
|
|
}
|
|
>
|
|
{label}
|
|
</button>
|
|
))}
|
|
</nav>
|
|
|
|
{tab === "requests" ? (
|
|
<RequestFilesTab />
|
|
) : tab === "files" ? (
|
|
<FilesTab />
|
|
) : (
|
|
<>
|
|
|
|
<div className="mt-6">
|
|
<FolderTabs value={folder} onChange={setFolder} />
|
|
</div>
|
|
|
|
<div className="mt-6 flex flex-wrap items-start gap-6">
|
|
{roleCanWrite(user) && (
|
|
<div className="max-w-md">
|
|
<UploadButton
|
|
multiple
|
|
label={folder === "logos" ? "Upload logos" : "Upload images"}
|
|
folder={folder || undefined}
|
|
onUploaded={(item) => setItems((current) => [item, ...(current ?? [])])}
|
|
/>
|
|
<p className="mt-1 text-xs text-muted">{UPLOAD_HELP}</p>
|
|
</div>
|
|
)}
|
|
<input
|
|
type="search"
|
|
value={query}
|
|
onChange={(e) => setQuery(e.target.value)}
|
|
placeholder="Search by file name"
|
|
aria-label="Search by file name"
|
|
className="ml-auto w-64 border border-muted/25 px-3 py-2 text-sm outline-none focus:border-brand"
|
|
/>
|
|
</div>
|
|
|
|
<div className="mt-6">
|
|
{error ? (
|
|
<p className="text-sm text-danger">{error}</p>
|
|
) : items === null ? (
|
|
<p className="text-sm text-muted">Loading…</p>
|
|
) : (
|
|
<MediaGrid
|
|
items={items}
|
|
renderActions={(item) => (
|
|
<div className="flex flex-wrap items-start gap-x-3 gap-y-1">
|
|
<CopyPath url={item.url} />
|
|
<a
|
|
href={item.url}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
className="text-xs text-link hover:underline"
|
|
>
|
|
Open
|
|
</a>
|
|
{roleCanWrite(user) && (
|
|
<RenameControl
|
|
item={item}
|
|
onRenamed={(renamed) =>
|
|
setItems((current) => (current ?? []).map((m) => (m.id === renamed.id ? renamed : m)))
|
|
}
|
|
/>
|
|
)}
|
|
{canDelete(user) && (
|
|
<div className="w-full">
|
|
<DeleteControl
|
|
item={item}
|
|
onDeleted={() =>
|
|
setItems((current) => (current ?? []).filter((m) => m.id !== item.id))
|
|
}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)}
|
|
/>
|
|
)}
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|