website 1.11.0: layouts and backgrounds for the blocks; a video for the top of the page

- Blocks get layouts (BLOCK_VARIANTS: text standard/centred; image and text photo left,
  right or above; quote centred/with a line; call to action centred/banner), stored on
  Section.variant and checked against the type; an unknown one draws as the default, as
  every block looked before. The demo's image-text block id is now image-left.
- Each block has its own background (Section.background, migration
  20261201000000_block_background), in the published source only when set, put back by
  Discard and Restore, drawn as the homepage's (data-bg).
- MP4 uploads up to 20 MB for the hero's Video layout: QuickTime refused, metadata boxes
  (udta, meta, uuid) blanked into free boxes of the same size so where it was filmed is
  gone and the frame offsets hold; size read from tkhd. GET /media lists mime.
- Admin: a block's Layout and Background when open; the hero's Video field (only videos;
  photo fields only photos); the media library shows and takes videos. An upload over the
  limit says so instead of "That request isn't valid."
- Tests: backend (152, three new); e2e for block layouts and a video upload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-01 09:57:02 +02:00
co-authored by Claude Opus 5.5
parent a38468ba47
commit f5f778f0d7
28 changed files with 543 additions and 69 deletions
@@ -2,7 +2,7 @@
import { useState } from "react";
import { api, canEdit } from "@/admin/api";
import { gb, StorageMeter, Uploader, type MediaItem, type Storage } from "@/admin/media";
import { gb, MediaThumb, StorageMeter, Uploader, type MediaItem, type Storage } from "@/admin/media";
import { Btn, inputClass, Loading, Notice, Panel, Title, useAction, useAdmin, when } from "@/admin/ui";
import { Image as ImageIcon, Trash2 } from "lucide-react";
@@ -19,15 +19,15 @@ export default function Media() {
const s = data.storage;
return (
<>
<Title icon={ImageIcon} sub="Photos for your pages. Sermon audio and video are linked (YouTube, Spotify), never uploaded.">Media library</Title>
<Title icon={ImageIcon} sub="Photos for your pages, and a short video for the top of your home page. Sermon audio and video are linked (YouTube, Spotify), never uploaded.">Media library</Title>
<div className="grid gap-6 lg:grid-cols-[2fr_1fr]">
<Panel>
{message && <div className="mb-3"><Notice tone={message.tone}>{message.text}</Notice></div>}
{data.items.length === 0 && <p className="text-gray-600">No photos yet.</p>}
{data.items.length === 0 && <p className="text-gray-600">No photos or videos yet.</p>}
<ul className="grid gap-4 sm:grid-cols-2">
{data.items.map((m) => (
<li key={m.id} className="space-y-2">
<img src={m.url} alt={m.alt} className="aspect-[4/3] w-full rounded object-cover" />
<MediaThumb m={m} className="aspect-[4/3] w-full rounded object-cover" />
<label className="block text-xs text-gray-600">What it shows
<input className={inputClass} value={alts[m.id] ?? m.alt} maxLength={500} onChange={(e) => setAlts({ ...alts, [m.id]: e.target.value })} />
</label>
@@ -70,7 +70,7 @@ export default function Media() {
</div>
</Panel>
<Panel title="Upload a photo">
{s.full ? <Notice tone="warning">Uploads have stopped: your storage is full.</Notice> : <Uploader onUploaded={() => reload()} />}
{s.full ? <Notice tone="warning">Uploads have stopped: your storage is full.</Notice> : <Uploader kind="any" onUploaded={() => reload()} />}
</Panel>
</div>
</div>
@@ -18,11 +18,11 @@ import { api } from "@/admin/api";
import { BLOCK_FIELDS, DataForm, SECTION_FIELDS } from "@/admin/fields";
import { frameFor, type Framing } from "@/admin/framing";
import { WithPreview } from "@/admin/LivePreview";
import { BACKGROUNDS, layoutsFor, moved, TEMPLATE_NAMES, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions, type HomeEntry } from "@/admin/layouts";
import { BACKGROUNDS, BLOCK_LAYOUTS, blockLayout, layoutsFor, moved, TEMPLATE_NAMES, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions, type HomeEntry } from "@/admin/layouts";
import { ImagePicker } from "@/admin/media";
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Tabs, Title, useAction, useAdmin } from "@/admin/ui";
type Section = { id: string; type: string; variant: string | null; hidden: boolean; data: Record<string, unknown>; updatedAt: string };
type Section = { id: string; type: string; variant: string | null; hidden: boolean; background: string | null; data: Record<string, unknown>; updatedAt: string };
type PageData = { id: string; kind: string; slug: string; title: string; seoTitle: string | null; description: string | null; navLabel: string | null; inNav: boolean; imageId: string | null; updatedAt: string; sections: Section[] };
const HOME_ORDER = ["hero", "serviceTimes", "welcome", "ministries", "team", "events", "latestMessage", "invitation"];
@@ -50,11 +50,25 @@ const summary = (data: Record<string, unknown>) => {
return null;
};
function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, frame, layout, settings }: {
/** A section's or block's own background, from the church's colours ("" follows the style). */
function BackgroundField({ name, value, busy, onChange }: { name: string; value: string; busy: boolean; onChange: (background: string) => void }) {
return (
<Field label="Background" hint="From your church's colours. A layout with a photo or band keeps its own.">
<span className="flex items-center gap-2">
<span className="h-9 w-9 shrink-0 rounded border border-gray-300" style={{ background: BACKGROUNDS.find((b) => b.id === value)?.swatch }} aria-hidden />
<select aria-label={`${name}: background`} className={inputClass} value={value} disabled={busy} onChange={(ev) => onChange(ev.target.value)}>
{BACKGROUNDS.map((b) => <option key={b.id} value={b.id}>{b.name}</option>)}
</select>
</span>
</Field>
);
}
function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, frame, layout, layoutName, settings }: {
type: string; title: string; fields: Parameters<typeof DataForm>[0]["fields"]; initial: Record<string, unknown>; frame?: Framing["frame"];
onSave: (data: Record<string, unknown>) => Promise<unknown>; hidden?: React.ReactNode; extra?: React.ReactNode;
/** A home page section's layout (only its fields are offered) and its layout and background controls. */
layout?: string; settings?: React.ReactNode;
layout?: string; layoutName?: string; settings?: React.ReactNode;
}) {
const [value, setValue] = useState(initial);
const [open, setOpen] = useState(false);
@@ -68,7 +82,7 @@ function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, fr
<span className="flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-brand/10 text-brand-text" aria-hidden><Icon className="h-[18px] w-[18px]" /></span>
<span className="min-w-0 flex-1">
<span className="flex flex-wrap items-center gap-2 font-semibold text-gray-900">{title}{hidden}</span>
<span className="block truncate text-xs text-gray-500">{layout && `${VARIANT_NAMES[layout] ?? layout} · `}{line ?? "Nothing written yet"}</span>
<span className="block truncate text-xs text-gray-500">{layout && `${layoutName ?? VARIANT_NAMES[layout] ?? layout} · `}{line ?? "Nothing written yet"}</span>
</span>
{open ? <ChevronDown className="h-4 w-4 shrink-0 text-gray-400" aria-hidden /> : <ChevronRight className="h-4 w-4 shrink-0 text-gray-400" aria-hidden />}
<span className="sr-only">{open ? "Close" : "Edit"}</span>
@@ -196,16 +210,7 @@ export default function EditPage() {
</select>
</Field>
{/* The top of the page draws its own background (photo, colour or plain). */}
{type !== "hero" && (
<Field label="Background" hint="From your church's colours. A layout with a photo or band keeps its own.">
<span className="flex items-center gap-2">
<span className="h-9 w-9 shrink-0 rounded border border-gray-300" style={{ background: BACKGROUNDS.find((b) => b.id === background)?.swatch }} aria-hidden />
<select aria-label={`${spec.name}: background`} className={inputClass} value={background} disabled={layouts.busy} onChange={(ev) => saveDesign({ home: withBackground(home, type, ev.target.value) })}>
{BACKGROUNDS.map((b) => <option key={b.id} value={b.id}>{b.name}</option>)}
</select>
</span>
</Field>
)}
{type !== "hero" && <BackgroundField name={spec.name} value={background} busy={layouts.busy} onChange={(b) => saveDesign({ home: withBackground(home, type, b) })} />}
</div>
);
return <SectionEditor key={type} type={type} title={spec.name} fields={spec.fields} initial={s?.data ?? {}} frame={(key, n) => frameFor(saved, type, key, n)}
@@ -226,8 +231,25 @@ export default function EditPage() {
{page.sections.map((s, i) => {
const spec = BLOCK_FIELDS[s.type];
if (!spec) return null;
// A block's layout and background are its own (saved on it straight away, like hiding it).
const layout = blockLayout(s.type, s.variant);
const options = BLOCK_LAYOUTS[s.type] ?? [];
const name = `${spec.name} block ${i + 1}`;
const settings = (
<div className="grid gap-4 rounded-lg bg-gray-50 p-3 sm:grid-cols-2">
{options.length > 1 && (
<Field label="Layout">
<select aria-label={`${name}: layout`} className={inputClass} value={layout} disabled={blocks.busy} onChange={(ev) => blockCall(`/blocks/${s.id}`, "PUT", { variant: ev.target.value })}>
{options.map((l) => <option key={l.id} value={l.id}>{l.name}</option>)}
</select>
</Field>
)}
<BackgroundField name={name} value={s.background ?? ""} busy={blocks.busy} onChange={(b) => blockCall(`/blocks/${s.id}`, "PUT", { background: b || null })} />
</div>
);
return (
<SectionEditor key={s.id} type={s.type} title={spec.name} fields={spec.fields} initial={s.data} frame={(key, i) => frameFor(design.data?.design, s.type, key, i)}
<SectionEditor key={s.id} type={s.type} title={spec.name} fields={spec.fields} initial={s.data} layout={layout} layoutName={options.find((l) => l.id === layout)?.name} settings={settings}
frame={(key, n) => frameFor(design.data?.design && { ...design.data.design, variants: { ...design.data.design.variants, [s.type]: layout ?? "" } }, s.type, key, n)}
hidden={s.hidden && <span className="inline-flex items-center gap-1 rounded-full bg-gray-100 px-2 py-0.5 text-xs font-medium text-gray-600"><EyeOff className="h-3 w-3" aria-hidden />Hidden</span>}
onSave={async (data) => setData(await api<PageData>(`/pages/${id}/blocks/${s.id}`, { method: "PUT", body: { data, ifUpdatedAt: s.updatedAt } }))}
extra={<>