website 1.10.0: the home page laid out from its editor; photos that match the layout
- Pages → Home: each section's layout and background when it's open, and move up, move down and show or hide on its header. They save straight to the design, as Template and style → Home page layout does (which keeps them too). Shared lists in admin/layouts.ts. - A section offers only the photo fields its layout shows: a slot for each (hero: 1 for Photo, Video and Split, 3 for Collage, none for Text only); Welcome's photo and pastor and the Invitation's photo only for the layouts that use them. Photos for other layouts are kept. - e2e: the hero opens with /^Top of the page/; a new test for the editor's layout controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,9 @@
|
||||
|
||||
/**
|
||||
* One page (§6), with its live preview on the right. Content: the home page has one of each
|
||||
* homepage section (their layouts, order and whether they show are under Template and style); every
|
||||
* other page is built from blocks, which can be added, moved, hidden and removed. Page details: its
|
||||
* homepage section, each with its layout, background, place and whether it shows (also under
|
||||
* Template and style), and only the photos its layout shows; every other page is built from blocks,
|
||||
* which can be added, moved, hidden and removed. Page details: its
|
||||
* title, address, menu and search engine details.
|
||||
*/
|
||||
import Link from "next/link";
|
||||
@@ -17,12 +18,12 @@ 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 { 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 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[] };
|
||||
type Design = { template: string; variants: Record<string, string>; home: { section: string; hidden: boolean }[] };
|
||||
|
||||
const HOME_ORDER = ["hero", "serviceTimes", "welcome", "ministries", "team", "events", "latestMessage", "invitation"];
|
||||
const LISTS: Record<string, string> = {
|
||||
@@ -49,9 +50,11 @@ const summary = (data: Record<string, unknown>) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, frame }: {
|
||||
function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, frame, layout, 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;
|
||||
}) {
|
||||
const [value, setValue] = useState(initial);
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -65,7 +68,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">{line ?? "Nothing written yet"}</span>
|
||||
<span className="block truncate text-xs text-gray-500">{layout && `${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>
|
||||
@@ -74,7 +77,8 @@ function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, fr
|
||||
</div>
|
||||
{open && (
|
||||
<div className="space-y-4 border-t border-gray-100 p-4">
|
||||
<DataForm fields={fields} value={value} onChange={setValue} errors={errors} frame={frame} />
|
||||
{settings}
|
||||
<DataForm fields={fields} value={value} onChange={setValue} errors={errors} frame={frame} layout={layout} />
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Btn kind="primary" busy={busy} onClick={() => run(() => onSave(value), "Saved as a draft.")}>Save</Btn>
|
||||
<Btn onClick={() => setOpen(false)}>Close</Btn>
|
||||
@@ -135,18 +139,26 @@ export default function EditPage() {
|
||||
const router = useRouter();
|
||||
const { data: page, error, setData } = useAdmin<PageData>(`/pages/${id}`);
|
||||
const isHome = page?.kind === "home";
|
||||
const design = useAdmin<{ design: Design }>("/design");
|
||||
const design = useAdmin<{ design: Design; options: DesignOptions }>("/design");
|
||||
const blocks = useAction();
|
||||
const remove = useAction();
|
||||
const layouts = useAction();
|
||||
const [tab, setTab] = useState<"content" | "details">("content");
|
||||
// The saved page: when it changes (any save), the preview reloads.
|
||||
const version = useMemo(() => (page ? JSON.stringify([page.updatedAt, page.slug, page.sections.map((s) => [s.id, s.updatedAt, s.hidden])]) : ""), [page]);
|
||||
// The saved page and the design (layouts, order, backgrounds): when either changes, the preview reloads.
|
||||
const saved = design.data?.design;
|
||||
const version = useMemo(() => (page ? JSON.stringify([page.updatedAt, page.slug, page.sections.map((s) => [s.id, s.updatedAt, s.hidden]), saved]) : ""), [page, saved]);
|
||||
if (!page) return <Loading error={error} />;
|
||||
const path = isHome ? "/" : `/${page.slug}`;
|
||||
const blockCall = (p: string, method: string, body?: unknown) => blocks.run(async () => setData(await api<PageData>(`/pages/${id}${p}`, { method, body })));
|
||||
|
||||
// The home page's sections in the order the site shows them, and whether each shows.
|
||||
const home = design.data?.design.home ?? HOME_ORDER.map((section) => ({ section, hidden: false }));
|
||||
const home: HomeEntry[] = saved?.home ?? HOME_ORDER.map((section) => ({ section, hidden: false }));
|
||||
// A section's layout, order, background and whether it shows are the site's design (as under
|
||||
// Template and style): they save straight away, apart from the section's words and photos.
|
||||
const saveDesign = (patch: Partial<Design>) => layouts.run(async () => {
|
||||
const r = await api<{ design: Design }>("/design", { method: "PUT", body: patch });
|
||||
if (design.data) design.setData({ ...design.data, design: r.design });
|
||||
});
|
||||
|
||||
return (
|
||||
<WithPreview path={path} version={version}>
|
||||
@@ -167,13 +179,43 @@ export default function EditPage() {
|
||||
<div hidden={tab !== "content"}>
|
||||
{isHome ? (
|
||||
<div className="space-y-3">
|
||||
<Notice>Open a section to change what it says. Its layout, its place on the page and whether it shows are under <Link href="/admin/template" className="font-semibold underline">Template and style</Link>.</Notice>
|
||||
{home.map(({ section: type, hidden }) => {
|
||||
<Notice>Open a section to choose its layout and background and change what it says. Use the arrows to move a section and the eye to show or hide it. The layout, background, order and showing save straight away; the words and photos save with the section's Save button.</Notice>
|
||||
{layouts.message?.tone === "error" && <Notice tone="error">{layouts.message.text}</Notice>}
|
||||
{home.map(({ section: type, hidden }, i) => {
|
||||
const s = page.sections.find((x) => x.type === type);
|
||||
const spec = SECTION_FIELDS[type];
|
||||
if (!spec) return null;
|
||||
return <SectionEditor key={type} type={type} title={spec.name} fields={spec.fields} initial={s?.data ?? {}} frame={(key, i) => frameFor(design.data?.design, type, key, i)}
|
||||
const layout = saved?.variants[type];
|
||||
const background = home[i]?.background ?? "";
|
||||
const { ordered, recommended } = saved ? layoutsFor(saved, design.data?.options, type) : { ordered: [], recommended: [] };
|
||||
const settings = saved && (
|
||||
<div className="grid gap-4 rounded-lg bg-gray-50 p-3 sm:grid-cols-2">
|
||||
<Field label="Layout" hint={`Those marked suit ${TEMPLATE_NAMES[saved.template] ?? "your template"} best; every one works.`}>
|
||||
<select aria-label={`${spec.name}: layout`} className={inputClass} value={layout} disabled={layouts.busy} onChange={(ev) => saveDesign({ variants: { [type]: ev.target.value } })}>
|
||||
{ordered.map((v) => <option key={v} value={v}>{VARIANT_NAMES[v]}{recommended.includes(v) ? " (suits this template)" : ""}</option>)}
|
||||
</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>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return <SectionEditor key={type} type={type} title={spec.name} fields={spec.fields} initial={s?.data ?? {}} frame={(key, n) => frameFor(saved, type, key, n)}
|
||||
layout={layout} settings={settings}
|
||||
hidden={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 />Not shown</span>}
|
||||
extra={saved && <>
|
||||
<Btn kind="icon" onClick={() => { const h = moved(home, i, -1); if (h) void saveDesign({ home: h }); }} disabled={layouts.busy || i === 0} aria-label={`Move ${spec.name} up`} title="Move up"><ArrowUp className="h-4 w-4" aria-hidden /></Btn>
|
||||
<Btn kind="icon" onClick={() => { const h = moved(home, i, 1); if (h) void saveDesign({ home: h }); }} disabled={layouts.busy || i === home.length - 1} aria-label={`Move ${spec.name} down`} title="Move down"><ArrowDown className="h-4 w-4" aria-hidden /></Btn>
|
||||
<Btn kind="icon" onClick={() => saveDesign({ home: withShown(home, type, hidden) })} disabled={layouts.busy} aria-label={hidden ? `Show ${spec.name}` : `Hide ${spec.name}`} title={hidden ? "Show it" : "Hide it"}>{hidden ? <Eye className="h-4 w-4" aria-hidden /> : <EyeOff className="h-4 w-4" aria-hidden />}</Btn>
|
||||
</>}
|
||||
onSave={async (data) => setData(await api<PageData>(`/pages/${id}/home/${type}`, { method: "PUT", body: { data, ifUpdatedAt: s?.updatedAt } }))} />;
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -10,22 +10,9 @@ import { useState } from "react";
|
||||
import { ArrowDown, ArrowUp, Check, Eye, LayoutTemplate, ListOrdered, Palette, SlidersHorizontal } from "lucide-react";
|
||||
import { api } from "@/admin/api";
|
||||
import { WithPreview } from "@/admin/LivePreview";
|
||||
import { BACKGROUNDS, layoutsFor, moved, SECTION_NAMES as SECTIONS, VARIANT_NAMES, withBackground, withShown, type Design, type DesignOptions as Options } from "@/admin/layouts";
|
||||
import { Btn, cx, Field, inputClass, Loading, Notice, Panel, Tabs, Title, useAction, useAdmin } from "@/admin/ui";
|
||||
|
||||
type HomeEntry = { section: string; hidden: boolean; background?: string };
|
||||
type Design = { template: string; variants: Record<string, string>; home: HomeEntry[]; style: Record<string, string> };
|
||||
|
||||
/** A section's own background (backend variants.ts SECTION_BACKGROUNDS), each from the church's colours; "" follows Style → Section colour. */
|
||||
const BACKGROUNDS: { id: string; name: string; swatch: string }[] = [
|
||||
{ id: "", name: "As the style sets it", swatch: "repeating-linear-gradient(45deg, #fff 0 4px, rgb(var(--brand-tint)) 4px 8px)" },
|
||||
{ id: "light", name: "White", swatch: "#fff" },
|
||||
{ id: "tint", name: "Soft main colour", swatch: "rgb(var(--brand-tint))" },
|
||||
{ id: "accent", name: "Soft accent colour", swatch: "linear-gradient(rgb(var(--accent) / 0.12), rgb(var(--accent) / 0.12)), #fff" },
|
||||
{ id: "brand", name: "Main colour", swatch: "rgb(var(--brand))" },
|
||||
{ id: "dark", name: "Deep main colour", swatch: "linear-gradient(rgb(0 0 0 / 0.35), rgb(0 0 0 / 0.35)), rgb(var(--brand-dark))" },
|
||||
];
|
||||
type Options = { variants: Record<string, Record<string, string[]>>; headers: Record<string, string[]> };
|
||||
|
||||
const TEMPLATES = [
|
||||
{ id: "heritage", name: "Heritage", text: "Traditional and dignified: centred, framed images, serif headings." },
|
||||
{ id: "bold", name: "Bold", text: "Modern and energetic: full-screen photos, big headlines, bands." },
|
||||
@@ -33,16 +20,6 @@ const TEMPLATES = [
|
||||
{ id: "clean", name: "Clean", text: "Minimal and calm: lots of space, good without photos." },
|
||||
];
|
||||
|
||||
const SECTIONS: Record<string, string> = { hero: "Top of the page", serviceTimes: "Service times", welcome: "Welcome", ministries: "Ministries", team: "Team", events: "Upcoming events", latestMessage: "Latest message", invitation: "Invitation" };
|
||||
const VARIANT_NAMES: Record<string, string> = {
|
||||
photo: "Photo", video: "Video", collage: "Collage", split: "Split", text: "Text only", panel: "Panel", strip: "Inline strip", map: "With map",
|
||||
"image-text": "Image and text", pastor: "With pastor", cards: "Cards", list: "List", bands: "Alternating bands", faces: "Faces", featured: "Featured",
|
||||
calendar: "Calendar strip", card: "Card", compact: "Compact", banner: "Banner", centred: "Centred", image: "Image background",
|
||||
};
|
||||
const ALL_VARIANTS: Record<string, string[]> = {
|
||||
hero: ["photo", "video", "collage", "split", "text"], serviceTimes: ["panel", "strip", "map"], welcome: ["text", "image-text", "pastor"], ministries: ["cards", "list", "bands"],
|
||||
team: ["faces", "list", "featured"], events: ["cards", "list", "calendar"], latestMessage: ["video", "card", "compact"], invitation: ["banner", "centred", "image"],
|
||||
};
|
||||
const HEADER_NAMES: Record<string, string> = {
|
||||
centred: "Centred", "centred-top-bar": "Centred, with a top bar", transparent: "Over the photo, solid when scrolling", solid: "Solid",
|
||||
"logo-left-button": "Logo left, with a Plan your visit button", "logo-left-tinted": "Logo left, on a tinted bar", small: "Small", "small-menu": "Small, menu on every screen",
|
||||
@@ -66,11 +43,8 @@ export default function TemplatePage() {
|
||||
return r;
|
||||
}, done);
|
||||
const move = (i: number, d: -1 | 1) => {
|
||||
const home = [...design.home];
|
||||
const j = i + d;
|
||||
if (j < 0 || j >= home.length) return;
|
||||
[home[i], home[j]] = [home[j]!, home[i]!];
|
||||
save({ home });
|
||||
const home = moved(design.home, i, d);
|
||||
if (home) save({ home });
|
||||
};
|
||||
return (
|
||||
<WithPreview path="/" version={JSON.stringify(design)}>
|
||||
@@ -105,11 +79,10 @@ export default function TemplatePage() {
|
||||
)}
|
||||
|
||||
{tab === "home" && (
|
||||
<Panel title="Home page: sections and layouts" icon={ListOrdered} sub={<>Every layout works in every template; the first ones listed suit {TEMPLATES.find((t) => t.id === design.template)?.name} best. Each section can have its own background in your church's colours (a layout with a photo or band keeps its own). What each section says is on the home page, under Pages.</>}>
|
||||
<Panel title="Home page: sections and layouts" icon={ListOrdered} sub={<>Every layout works in every template; the first ones listed suit {TEMPLATES.find((t) => t.id === design.template)?.name} best. Each section can have its own background in your church's colours (a layout with a photo or band keeps its own). What each section says is on the home page, under Pages, where you can change all of this too.</>}>
|
||||
<ul className="divide-y divide-gray-100">
|
||||
{design.home.map((e, i) => {
|
||||
const recommended = options.variants[design.template]?.[e.section] ?? [];
|
||||
const ordered = [...recommended, ...ALL_VARIANTS[e.section]!.filter((v) => !recommended.includes(v))];
|
||||
const { ordered, recommended } = layoutsFor(design, options, e.section);
|
||||
return (
|
||||
<li key={e.section} className={cx("flex flex-wrap items-center gap-3 py-3", e.hidden && "opacity-60")}>
|
||||
<span className="flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-gray-100 text-xs font-semibold text-gray-600" aria-hidden>{i + 1}</span>
|
||||
@@ -123,13 +96,13 @@ export default function TemplatePage() {
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="h-6 w-6 shrink-0 rounded border border-gray-300" style={{ background: BACKGROUNDS.find((b) => b.id === (e.background ?? ""))?.swatch }} aria-hidden />
|
||||
<select aria-label={`${SECTIONS[e.section]} background`} title="Background" className={`${inputClass} w-48`} value={e.background ?? ""} disabled={busy}
|
||||
onChange={(ev) => save({ home: design.home.map(({ background: _b, ...x }) => (x.section === e.section ? (ev.target.value ? { ...x, background: ev.target.value } : x) : { ...x, ...(_b ? { background: _b } : {}) })) })}>
|
||||
onChange={(ev) => save({ home: withBackground(design.home, e.section, ev.target.value) })}>
|
||||
{BACKGROUNDS.map((b) => <option key={b.id} value={b.id}>{b.id ? b.name : `Background: ${b.name.toLowerCase()}`}</option>)}
|
||||
</select>
|
||||
</span>
|
||||
)}
|
||||
<label className="flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" checked={!e.hidden} disabled={busy} onChange={(ev) => save({ home: design.home.map((x) => (x.section === e.section ? { ...x, hidden: !ev.target.checked } : x)) })} />
|
||||
<input type="checkbox" checked={!e.hidden} disabled={busy} onChange={(ev) => save({ home: withShown(design.home, e.section, ev.target.checked) })} />
|
||||
Show
|
||||
</label>
|
||||
<span className="ml-auto flex gap-1">
|
||||
|
||||
Reference in New Issue
Block a user