Add image uploads with a media library, and event card backgrounds

Uploads (migration 028, server/src/media.js, routes/media.js): editors
and up upload JPEG, PNG, GIF, WebP or SVG. Photos are resized to 2400px
and saved as WebP by default, or kept as uploaded on request. Files
live in UPLOADS_DIR, served by nginx in production and by the API in
dev. Admins and up delete, after seeing what still uses the file.

Every image field in the editor is now an image widget: preview, the
path as text, Upload and Choose from library. A new Media page lists
the library. Org lists and event cards now resolve logos through
media.ts, so uploaded paths work there.

Events get a card_image (migration 029): a photo behind the card under
a light veil so the text stays readable. The card's size is unchanged.

Setup for production is in docs/media-uploads.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-27 15:04:45 -05:00
parent cd393e4ab2
commit eaff23839f
26 changed files with 1234 additions and 22 deletions

View file

@ -32,6 +32,7 @@ import AdminLogin from "./pages/admin/AdminLogin.tsx";
import AdminPanel from "./pages/admin/AdminPanel.tsx";
import AdminHome from "./pages/admin/AdminHome.tsx";
import AdminFeedback from "./pages/admin/AdminFeedback.tsx";
import AdminMedia from "./pages/admin/AdminMedia.tsx";
import EntityList from "./pages/admin/EntityList.tsx";
import EntityEdit from "./pages/admin/EntityEdit.tsx";
@ -80,6 +81,7 @@ export default function App() {
<Route path="panel" element={<AdminPanel />} />
</Route>
<Route path="feedback" element={<AdminFeedback />} />
<Route path="media" element={<AdminMedia />} />
<Route path=":entity" element={<EntityList />} />
<Route path=":entity/:id" element={<EntityEdit />} />
</Route>

View file

@ -0,0 +1,407 @@
/* ═══════════════════════════════════════════════════════════════
MEDIA LIBRARY
Everything the admin does with uploaded images, in one file:
ImageInput the `widget: "image"` form field. A preview, the
stored value as editable text, and buttons to
upload a new file or pick an earlier one.
MediaPicker the dialog behind "Choose from library".
MediaGrid the thumbnails both the picker and the Media page
(pages/admin/AdminMedia.tsx) draw.
UploadButton a file input dressed as a button, with the
"keep original" choice beside it.
An image field stores a path, not a media id: '/uploads/<file>'
for an upload, or, as before, a bare filename in the field's
public/ directory or a full URL. So the text box stays: old
values keep working, and a URL from elsewhere can be pasted in.
`resolve` on the field (a media.ts helper) turns a bare filename
into something the preview can load.
Uploading is editor and up; the server says the same. Reads use
ttl: 0 because two people uploading at once is exactly when a
cached list would lie.
═══════════════════════════════════════════════════════════════ */
import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react";
import { ApiError, get, upload } from "../../lib/api.ts";
import { useAuth } from "../../lib/auth.tsx";
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
export type MediaItem = {
id: number;
url: string;
original_name: string;
content_type: string;
bytes: number;
width: number | null;
height: number | null;
processed: boolean;
uploaded_by: string | null;
created_at: string;
};
const button =
"rounded-full border border-[#138ba0] px-3 py-1 text-sm font-medium text-[#138ba0] " +
"transition-colors hover:bg-[#eef9fb] disabled:cursor-default disabled:opacity-50";
/* A light checkerboard, so a white logo on a transparent background
is still visible in its thumbnail. */
const CHECKER = {
backgroundColor: "#fff",
backgroundImage:
"linear-gradient(45deg,#e6eef0 25%,transparent 25%),linear-gradient(-45deg,#e6eef0 25%,transparent 25%)," +
"linear-gradient(45deg,transparent 75%,#e6eef0 75%),linear-gradient(-45deg,transparent 75%,#e6eef0 75%)",
backgroundSize: "12px 12px",
backgroundPosition: "0 0,0 6px,6px -6px,-6px 0",
};
export function formatBytes(bytes: number) {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${Math.round(bytes / 1024)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
export function mediaSize(item: MediaItem) {
const dims = item.width && item.height ? `${item.width} × ${item.height}, ` : "";
return `${dims}${formatBytes(item.bytes)}`;
}
/* ── Data ────────────────────────────────────────────────────── */
export function uploadImage(file: File, keepOriginal: boolean): Promise<MediaItem> {
const form = new FormData();
form.append("file", file);
if (keepOriginal) form.append("keep_original", "1");
return upload("/admin/media", form).then((data) => data.media);
}
export function useMediaLibrary(query: string) {
const [items, setItems] = useState<MediaItem[] | null>(null);
const [error, setError] = useState<string | null>(null);
const reload = useCallback(() => {
const q = query.trim();
setError(null);
get(`/admin/media${q ? `?q=${encodeURIComponent(q)}` : ""}`, { ttl: 0 })
.then((data) => setItems(data.media))
.catch((err) =>
setError(err instanceof ApiError ? err.message : "Couldn't load the library."),
);
}, [query]);
useEffect(reload, [reload]);
return { items, error, reload, setItems };
}
/* ── Upload button ───────────────────────────────────────────── */
export function UploadButton({
onUploaded,
multiple = false,
label = "Upload",
}: {
onUploaded: (item: MediaItem) => void;
multiple?: boolean;
label?: string;
}) {
const inputRef = useRef<HTMLInputElement>(null);
const keepId = useId();
const [keepOriginal, setKeepOriginal] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function send(files: FileList | null) {
if (!files || files.length === 0) return;
setBusy(true);
setError(null);
try {
// One at a time: each is up to 25 MB, and a failure should
// name the file it happened to.
for (const file of Array.from(files)) {
try {
onUploaded(await uploadImage(file, keepOriginal));
} catch (err) {
const why = err instanceof ApiError ? err.message : "Upload failed.";
setError(files.length > 1 ? `${file.name}: ${why}` : why);
break;
}
}
} finally {
setBusy(false);
if (inputRef.current) inputRef.current.value = "";
}
}
return (
<div>
<div className="flex flex-wrap items-center gap-3">
<button
type="button"
className={button}
disabled={busy}
onClick={() => inputRef.current?.click()}
>
{busy ? "Uploading…" : label}
</button>
<input
ref={inputRef}
type="file"
accept="image/jpeg,image/png,image/gif,image/webp,image/svg+xml"
multiple={multiple}
className="hidden"
onChange={(e) => send(e.target.files)}
/>
<label htmlFor={keepId} className="flex items-center gap-1.5 text-xs text-[#4a6b72]">
<input
id={keepId}
type="checkbox"
checked={keepOriginal}
onChange={(e) => setKeepOriginal(e.target.checked)}
className="h-3.5 w-3.5 rounded border-[#4a6b72]/40 text-[#138ba0]"
/>
Keep original
</label>
</div>
{error && <p className="mt-1 text-xs text-[#b3261e]">{error}</p>}
</div>
);
}
export const UPLOAD_HELP =
"Photos are shrunk to 2400px and saved as WebP, which also removes their location data. " +
"Keep original stores the file exactly as it is (up to 10 MB). SVGs are always kept as they are.";
/* ── Grid ────────────────────────────────────────────────────── */
export function MediaGrid({
items,
selected,
onPick,
renderActions,
}: {
items: MediaItem[];
selected?: string | null;
onPick?: (item: MediaItem) => void;
renderActions?: (item: MediaItem) => ReactNode;
}) {
if (items.length === 0) {
return <p className="text-sm text-[#4a6b72]">Nothing here yet.</p>;
}
return (
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
{items.map((item) => {
const isSelected = selected === item.url;
const thumb = (
<>
<div className="aspect-[4/3] overflow-hidden rounded-lg" style={CHECKER}>
<img
src={item.url}
alt=""
loading="lazy"
className="h-full w-full object-contain"
/>
</div>
<p className="mt-1.5 truncate text-xs font-medium text-[#26454c]" title={item.original_name}>
{item.original_name}
</p>
<p className="text-xs text-[#4a6b72]/80">{mediaSize(item)}</p>
</>
);
return (
<li
key={item.id}
className={`rounded-xl border bg-white p-2 ${
isSelected ? "border-[#138ba0] ring-2 ring-[#138ba0]/30" : "border-[#4a6b72]/20"
}`}
>
{onPick ? (
<button
type="button"
onClick={() => onPick(item)}
className="block w-full text-left"
aria-pressed={isSelected}
>
{thumb}
</button>
) : (
thumb
)}
{renderActions && <div className="mt-2">{renderActions(item)}</div>}
</li>
);
})}
</ul>
);
}
/* ── Picker dialog ───────────────────────────────────────────── */
export function MediaPicker({
selected,
onPick,
onClose,
}: {
selected?: string | null;
onPick: (item: MediaItem) => void;
onClose: () => void;
}) {
const { user } = useAuth();
const [query, setQuery] = useState("");
const { items, error, setItems } = useMediaLibrary(query);
const dialogRef = useRef<HTMLDialogElement>(null);
// showModal gives focus trapping, Escape and the backdrop for free.
useEffect(() => {
dialogRef.current?.showModal();
}, []);
return (
<dialog
ref={dialogRef}
onClose={onClose}
onClick={(e) => {
// A click on the backdrop lands on the dialog itself.
if (e.target === dialogRef.current) dialogRef.current?.close();
}}
className="w-[min(56rem,calc(100vw-2rem))] rounded-2xl p-0 backdrop:bg-[#0f2f36]/40"
>
<div className="flex max-h-[85vh] flex-col">
<div className="flex flex-wrap items-center gap-3 border-b border-[#138ba0]/15 px-5 py-4">
<h2 className="text-lg font-semibold text-[#138ba0]">Choose an image</h2>
<input
type="search"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search by file name"
className="ml-auto w-56 rounded-lg border border-[#4a6b72]/25 px-3 py-1.5 text-sm outline-none focus:border-[#138ba0]"
/>
<button
type="button"
onClick={() => dialogRef.current?.close()}
aria-label="Close"
className="h-8 w-8 rounded-full text-[#4a6b72] hover:bg-[#eef9fb]"
>
✕
</button>
</div>
{roleCanWrite(user) && (
<div className="border-b border-[#138ba0]/10 px-5 py-3">
<UploadButton
label="Upload new"
onUploaded={(item) => {
setItems((current) => [item, ...(current ?? [])]);
onPick(item);
dialogRef.current?.close();
}}
/>
<p className="mt-1 text-xs text-[#4a6b72]">{UPLOAD_HELP}</p>
</div>
)}
<div className="overflow-y-auto px-5 py-4">
{error ? (
<p className="text-sm text-[#b3261e]">{error}</p>
) : items === null ? (
<p className="text-sm text-[#4a6b72]">Loading…</p>
) : (
<MediaGrid
items={items}
selected={selected}
onPick={(item) => {
onPick(item);
dialogRef.current?.close();
}}
/>
)}
</div>
</div>
</dialog>
);
}
/* ── The form field ──────────────────────────────────────────── */
export function ImageInput({
id,
value,
resolve,
locked,
className,
onChange,
}: {
id: string;
value: string | null | undefined;
resolve?: (file?: string | null) => string | null;
locked: boolean;
className: string;
onChange: (value: string) => void;
}) {
const { user } = useAuth();
const [picking, setPicking] = useState(false);
const [broken, setBroken] = useState(false);
const src = value ? (resolve ? resolve(value) : value) : null;
useEffect(() => setBroken(false), [src]);
const editable = !locked && roleCanWrite(user);
return (
<div className="flex gap-3">
<div
className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-[#4a6b72]/20"
style={CHECKER}
>
{src && !broken ? (
<img src={src} alt="" className="h-full w-full object-contain" onError={() => setBroken(true)} />
) : (
<span className="px-1 text-center text-[10px] text-[#4a6b72]/70">
{src ? "Not found" : "No image"}
</span>
)}
</div>
<div className="min-w-0 flex-1 space-y-2">
<input
id={id}
type="text"
value={value ?? ""}
readOnly={locked}
onChange={(e) => onChange(e.target.value)}
className={className}
/>
{editable && (
<div className="flex flex-wrap items-start gap-2">
<UploadButton onUploaded={(item) => onChange(item.url)} />
<button type="button" className={button} onClick={() => setPicking(true)}>
Choose from library
</button>
{value && (
<button
type="button"
onClick={() => onChange("")}
className="px-2 py-1 text-sm text-[#4a6b72] hover:text-[#b3261e]"
>
Clear
</button>
)}
</div>
)}
</div>
{picking && (
<MediaPicker
selected={value}
onPick={(item) => onChange(item.url)}
onClose={() => setPicking(false)}
/>
)}
</div>
);
}

View file

@ -18,6 +18,11 @@
that column in the server's admin-schema.js or the row will be
saved as real input.
`widget: "image"` is a text box with a preview and upload and
library buttons beside it (ImageInput in MediaLibrary.tsx). Its
`resolve` option is the media.ts helper for the field's public/
directory, so a bare filename previews from the right place.
Two options change the box itself rather than what goes in it:
prefix fixed text inside the box, left of the cursor. The
@ -34,6 +39,8 @@
import { useRef, useState } from "react";
import { ImageInput } from "./MediaLibrary.tsx";
const input =
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
"outline-none transition-colors focus:border-[#138ba0] focus:ring-2 focus:ring-[#138ba0]/25";
@ -168,6 +175,15 @@ export function Field({ field, value, row, options, error, onChange }: any) {
className={locked ? inputLocked : common.className}
/>
</div>
) : widget === "image" ? (
<ImageInput
id={id}
value={value}
resolve={field.resolve}
locked={locked}
className={locked ? inputLocked : common.className}
onChange={onChange}
/>
) : field.prefix && !locked ? (
// The span is not a form control, so it can't be typed
// into, tabbed to, or selected by dragging through the

View file

@ -17,6 +17,16 @@
import { preview } from "./text.ts";
import { PLATFORMS } from "./platforms.ts";
import {
awardLogo,
blockMedia,
eventBackground,
eventLogo,
heroPhoto,
orgLogo,
personPhoto,
teamLogo,
} from "./media.ts";
const PLACE_FIELDS = [
{ path: "venue", label: "Venue" },
@ -228,7 +238,7 @@ const blocksChild = {
],
},
{ path: "text", label: "Text", widget: "textarea", full: true },
{ path: "media", label: "Media", help: "Filename or URL" },
{ path: "media", label: "Media", widget: "image", resolve: blockMedia, full: true },
{ path: "href", label: "Link" },
],
children: [
@ -288,7 +298,7 @@ const organizations = {
{ path: "short_name", label: "Short name" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "logo", label: "Logo", help: "Filename in /org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: orgLogo, full: true },
],
},
{
@ -495,10 +505,18 @@ const events = {
{
legend: "Appearance",
fields: [
{ path: "event_logo", label: "Event logo", help: "Filename in /event-logos/" },
{ path: "org_logo", label: "Org logo override" },
{ path: "event_logo", label: "Event logo", widget: "image", resolve: eventLogo, full: true },
{ path: "org_logo", label: "Org logo override", widget: "image", resolve: orgLogo, full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "gradient", label: "Gradient", full: true },
{
path: "card_image",
label: "Card background",
widget: "image",
resolve: eventBackground,
full: true,
help: "A photo behind the event's card, faded so the text stays readable.",
},
],
},
timelineGroup("event"),
@ -577,7 +595,7 @@ const people = {
{ path: "sort_name", label: "Sort name", help: "Doe, Jane" },
{ path: "pronouns", label: "Pronouns" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "photo", label: "Photo", help: "Filename in /people/" },
{ path: "photo", label: "Photo", widget: "image", resolve: personPhoto, full: true },
{
path: "primary_org_id",
label: "Home organization",
@ -738,7 +756,7 @@ const teams = {
{ path: "name", label: "Name", required: true, help: "Board, Leadership Team" },
{ path: "tagline", label: "Tagline", full: true },
{ path: "color", label: "Colour", widget: "color" },
{ path: "logo", label: "Logo", help: "Filename in /org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: teamLogo, full: true },
],
},
{ legend: "Publishing", fields: PUBLISH_FIELDS },
@ -814,7 +832,7 @@ const awards = {
},
{ path: "name", label: "Name", required: true },
{ path: "description", label: "Description", widget: "textarea", full: true },
{ path: "logo", label: "Logo", help: "Filename in public/org-logos/" },
{ path: "logo", label: "Logo", widget: "image", resolve: awardLogo, full: true },
],
},
{
@ -1151,7 +1169,7 @@ const frontPage = {
title: (row) => row.caption || row.media || "New photo",
blank: { media: "", alt: "", caption: "" },
fields: [
{ path: "media", label: "Photo", required: true, help: "Filename in /front-page/, or a URL" },
{ path: "media", label: "Photo", required: true, widget: "image", resolve: heroPhoto, full: true },
{ path: "alt", label: "Description", help: "For screen readers" },
{ path: "caption", label: "Caption", full: true },
{ path: "link_url", label: "Link", help: "Optional; makes the caption a link" },

View file

@ -115,3 +115,9 @@ export function patch(path, data) {
export function del(path) {
return request(path, { method: "DELETE" });
}
/* A multipart body. No Content-Type here: the browser sets it,
boundary included, from the FormData itself. */
export function upload(path, form: FormData) {
return request(path, { method: "POST", body: form });
}

View file

@ -17,6 +17,10 @@
const ABSOLUTE = /^(https?:|\/|data:)/
/* An uploaded file ('/uploads/…'), a path anywhere on the site, or
a full URL: something to use as it is rather than resolve. */
export const isAbsoluteMedia = (file?: string | null) => Boolean(file && ABSOLUTE.test(file))
function inDir(dir: string) {
return (file?: string | null): string | null => {
if (!file) return null
@ -27,6 +31,7 @@ function inDir(dir: string) {
export const personPhoto = inDir('/people') // confirmed
export const eventLogo = inDir('/event-logos') // confirmed
export const eventBackground = inDir('/event-backgrounds')
export const orgLogo = inDir('/org-logos') // ⚠ guess
export const teamLogo = inDir('/team-logos') // ⚠ guess
export const awardLogo = inDir('/award-logos') // ⚠ guess

View file

@ -101,6 +101,8 @@ export type EventRecord = {
event_logo?: string | null
color?: string | null
gradient?: string | null
/** Behind the card. See 029_event_card_image.sql. */
card_image?: string | null
/* In billing order. The first is the one `color` and `org_logo`
fell back to when the event set neither. */
hosts: EventHost[]

View file

@ -0,0 +1,193 @@
/* ═══════════════════════════════════════════════════════════════
ADMIN: MEDIA
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
page is for housekeeping rather than the way images get in.
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 { useState } from "react";
import { ApiError, del, get } from "../../lib/api.ts";
import { useAuth } from "../../lib/auth.tsx";
import { canDelete, canWrite as roleCanWrite } from "../../lib/roles.ts";
import {
MediaGrid,
UPLOAD_HELP,
UploadButton,
useMediaLibrary,
type MediaItem,
} from "../../components/admin/MediaLibrary.tsx";
type Use = { table: string; count: number };
function DeleteControl({ item, onDeleted }: { item: MediaItem; 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(`/admin/media/${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(`/admin/media/${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-[#4a6b72] hover:text-[#b3261e]"
>
Delete
</button>
{error && <p className="mt-1 text-xs text-[#b3261e]">{error}</p>}
</>
);
}
return (
<div className="rounded-lg bg-[#fdf3f2] p-2 text-xs text-[#26454c]">
{uses.length > 0 ? (
<p>
Still used by{" "}
{uses.map((use) => `${use.count} in ${use.table.replace(/_/g, " ")}`).join(", ")}. Those
will show no image.
</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-[#b3261e] hover:underline"
>
{busy ? "Deleting…" : "Delete for good"}
</button>
<button type="button" onClick={() => setUses(null)} className="text-[#4a6b72] hover:underline">
Cancel
</button>
</div>
{error && <p className="mt-1 text-[#b3261e]">{error}</p>}
</div>
);
}
function CopyPath({ url }: { url: 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-[#138ba0] hover:underline"
>
{copied ? "Copied" : "Copy path"}
</button>
);
}
export default function AdminMedia() {
const { user } = useAuth();
const [query, setQuery] = useState("");
const { items, error, setItems } = useMediaLibrary(query);
return (
<div>
<div className="flex flex-wrap items-baseline gap-3">
<h1 className="text-2xl font-bold text-[#138ba0]">Media</h1>
<p className="text-sm text-[#4a6b72]">
Uploaded images. Image fields in every editor pick from here.
</p>
</div>
<div className="mt-6 flex flex-wrap items-start gap-6">
{roleCanWrite(user) && (
<div className="max-w-md">
<UploadButton
multiple
label="Upload images"
onUploaded={(item) => setItems((current) => [item, ...(current ?? [])])}
/>
<p className="mt-1 text-xs text-[#4a6b72]">{UPLOAD_HELP}</p>
</div>
)}
<input
type="search"
value={query}
onChange={(e) => setQuery(e.target.value)}
placeholder="Search by file name"
className="ml-auto w-64 rounded-lg border border-[#4a6b72]/25 px-3 py-2 text-sm outline-none focus:border-[#138ba0]"
/>
</div>
<div className="mt-6">
{error ? (
<p className="text-sm text-[#b3261e]">{error}</p>
) : items === null ? (
<p className="text-sm text-[#4a6b72]">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-[#138ba0] hover:underline"
>
Open
</a>
{canDelete(user) && (
<div className="w-full">
<DeleteControl
item={item}
onDeleted={() =>
setItems((current) => (current ?? []).filter((m) => m.id !== item.id))
}
/>
</div>
)}
</div>
)}
/>
)}
</div>
</div>
);
}

View file

@ -70,6 +70,13 @@ export const CMS_NAV = [
label: "Front page",
blurb: "The hero, its photos or livestream, and which bands the home page draws.",
},
// Not an entity: the uploaded-image library every image field
// picks from. Its own page, AdminMedia.tsx.
{
to: "/admin/media",
label: "Media",
blurb: "Uploaded images: logos, photos and backgrounds, ready to reuse.",
},
];
/* Forms are submissions coming in rather than content going out, so

View file

@ -5,6 +5,7 @@ import { eventHref } from "../../lib/hrefs.ts";
import { EVENT_TYPES, eventTypeLabel } from "../../lib/eventTypes.ts";
import { seriesLabel } from "../../lib/eventSeries.ts";
import PlatformIcon from "../../components/PlatformIcon.tsx";
import { eventBackground, isAbsoluteMedia } from "../../lib/media.ts";
/* ═══════════════════════════════════════════════════════════════
EVENT LIST — CARDS
@ -35,7 +36,9 @@ const LOGOS = Object.fromEntries(
Object.entries(LOGO_FILES).map(([path, src]) => [path.split("/").pop(), src])
);
const logoSrc = file => (file && LOGOS[file]) || null;
/* A bundled logo by filename, or an upload or URL as it is. */
const logoSrc = file =>
(file && LOGOS[file]) || (isAbsoluteMedia(file) ? file : null);
/* Last resort only. The API already falls back to the host
organization's logo when an event doesn't name its own, so this
@ -60,6 +63,25 @@ function Logo({ file, alt = "", className }) {
const TEAL = "#138ba0"; // last-resort card color
const CARD_BG = "#ffffff"; // sits under every card, gradient or not
/* Laid over a card's background image so black text reads on any
photo. Heavier at the top, where the title and dates are, and
lighter lower down so more of the picture shows through. */
const CARD_IMAGE_VEIL =
"linear-gradient(to bottom, rgba(255,255,255,0.9), rgba(255,255,255,0.78))";
/* The card's background layers, top first: its gradient if it has
one, then the veil and photo if it has one, then white. */
function cardBackground(ev) {
const layers: string[] = [];
if (ev.gradient) layers.push(ev.gradient);
const image = eventBackground(ev.card_image);
if (image) {
layers.push(CARD_IMAGE_VEIL, `url(${JSON.stringify(image)}) center / cover no-repeat`);
}
layers.push(CARD_BG);
return layers.join(", ");
}
/* ── Grid view ────────────────────────────────────────────────
The grid fits as many columns as the screen allows, with no
breakpoints: each card is at least CARD_MIN wide, and the
@ -185,7 +207,7 @@ export function Card({
}`}
style={{
border: `1px solid ${color}`,
background: ev.gradient ? `${ev.gradient}, ${CARD_BG}` : CARD_BG,
background: cardBackground(ev),
filter: past ? "saturate(0.75)" : "none",
pointerEvents: interactive ? "auto" : "none",
}}

View file

@ -1,5 +1,6 @@
import { useState } from "react";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import {
initialsFor,
orgPath,
@ -21,8 +22,6 @@ import {
array — only the short card description.
═══════════════════════════════════════════════════════════════ */
const LOGO_BASE = "/org-logos/";
const MUTED = "#7a9299";
const INK = "#2c4a50";
const FALLBACK_COLOR = "#4a6b72";
@ -39,7 +38,7 @@ function OrgMark({ org, color }) {
if (org.logo && !failed) {
return (
<img
src={`${LOGO_BASE}${org.logo}`}
src={orgLogo(org.logo) ?? undefined}
alt=""
onError={() => setFailed(true)}
className="h-14 w-14 object-contain rounded-xl shrink-0"

View file

@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from "react";
import { useCommunity } from "../../data/chapters.ts";
import { Link } from "react-router-dom";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import { initialsFor, orgPath } from "../../data/organizations.ts";
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
@ -39,8 +40,6 @@ const ROWS = 7;
// stays at max-w-6xl, so this deliberately breaks out past it.
const CONTENT_MAX = "88rem";
const LOGO_BASE = "/org-logos/";
const MUTED = "#7a9299";
const RULE = "#cfe3e7";
const INK = "#2c4a50";
@ -472,7 +471,7 @@ function OrgLogo({ org, color, size = "h-14 w-14" }) {
if (org.logo && !failed) {
return (
<img
src={`${LOGO_BASE}${org.logo}`}
src={orgLogo(org.logo) ?? undefined}
alt={org.name}
onError={() => setFailed(true)}
className={`${size} object-contain rounded-xl shrink-0`}

View file

@ -1,5 +1,6 @@
import { useId, useState } from "react";
import ArrowLink from "../../components/ArrowLink.tsx";
import { orgLogo } from "../../lib/media.ts";
import PlatformIcon from "../../components/PlatformIcon.tsx";
import {
areasSentence,
@ -36,8 +37,6 @@ import {
a partner row simply doesn't have them.
═══════════════════════════════════════════════════════════════ */
const LOGO_BASE = "/org-logos/";
const MUTED = "#7a9299";
const RULE = "#cfe3e7";
const INK = "#2c4a50";
@ -66,7 +65,7 @@ function OrgMark({ org, color }) {
if (org.logo && !failed) {
return (
<img
src={`${LOGO_BASE}${org.logo}`}
src={orgLogo(org.logo) ?? undefined}
alt=""
onError={() => setFailed(true)}
className="h-8 w-8 object-contain shrink-0"