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:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@crosscode/website-frontend",
|
||||
"version": "1.9.0",
|
||||
"version": "1.10.0",
|
||||
"private": true,
|
||||
"description": "Church Website: the church's public site in its template, and the admin",
|
||||
"scripts": {
|
||||
|
||||
@@ -9,13 +9,18 @@ import { FramingContext, type Framing } from "./framing";
|
||||
import { ImagePicker } from "./media";
|
||||
import { Btn, Field, inputClass } from "./ui";
|
||||
|
||||
type Spec =
|
||||
/**
|
||||
* One field. `layouts`: the section's layouts that show it (left out, every one does); the form
|
||||
* only offers it when the section is in one of them. A photo list's `count` is how many photos each
|
||||
* layout shows, and `labels` what they're called in it.
|
||||
*/
|
||||
type Spec = { layouts?: string[] } & (
|
||||
| { key: string; kind: "text" | "textarea"; label: string; hint?: string; max?: number }
|
||||
| { key: string; kind: "number"; label: string; min: number; max: number }
|
||||
| { key: string; kind: "image"; label: string }
|
||||
| { key: string; kind: "images"; label: string; max: number }
|
||||
| { key: string; kind: "images"; label: string; max: number; count?: Record<string, number>; labels?: Record<string, string> }
|
||||
| { key: string; kind: "button"; label: string }
|
||||
| { key: string; kind: "group"; label: string; fields: Spec[] };
|
||||
| { key: string; kind: "group"; label: string; fields: Spec[] });
|
||||
|
||||
const heading: Spec = { key: "heading", kind: "text", label: "Heading", max: 120 };
|
||||
const button: Spec = { key: "button", kind: "button", label: "Button" };
|
||||
@@ -24,7 +29,9 @@ export const SECTION_FIELDS: Record<string, { name: string; fields: Spec[] }> =
|
||||
hero: { name: "Top of the page (hero)", fields: [
|
||||
{ key: "headline", kind: "text", label: "Headline", max: 120 },
|
||||
{ key: "subline", kind: "textarea", label: "Under the headline", max: 300 },
|
||||
{ key: "images", kind: "images", label: "Photos (the first for Photo and Split; up to three for Collage)", max: 3 },
|
||||
// As site/sections/Hero.tsx draws them: Photo, Video (its still) and Split one, Collage three.
|
||||
{ key: "images", kind: "images", label: "Photos", max: 3, count: { photo: 1, video: 1, split: 1, collage: 3, text: 0 },
|
||||
labels: { photo: "Photo", video: "Still photo (shown before the video plays, and on phones)", split: "Photo (beside the headline)", collage: "Photos (three, for the collage)" } },
|
||||
button,
|
||||
] },
|
||||
serviceTimes: { name: "Service times and location", fields: [heading, { key: "note", kind: "textarea", label: "A note for visitors", hint: "The times and address come from your church profile.", max: 300 }] },
|
||||
@@ -32,8 +39,8 @@ export const SECTION_FIELDS: Record<string, { name: string; fields: Spec[] }> =
|
||||
heading,
|
||||
{ key: "mission", kind: "text", label: "Mission (one line)", max: 200 },
|
||||
{ key: "body", kind: "textarea", label: "Introduction", hint: "Leave an empty line between paragraphs.", max: 4000 },
|
||||
{ key: "imageId", kind: "image", label: "Photo (Image and text layout)" },
|
||||
{ key: "pastor", kind: "group", label: "Pastor's photo and quote (With pastor layout)", fields: [
|
||||
{ key: "imageId", kind: "image", label: "Photo", layouts: ["image-text"] },
|
||||
{ key: "pastor", kind: "group", label: "Pastor's photo and quote", layouts: ["pastor"], fields: [
|
||||
{ key: "name", kind: "text", label: "Name", max: 120 }, { key: "role", kind: "text", label: "Role", max: 80 },
|
||||
{ key: "quote", kind: "textarea", label: "Quote", max: 400 }, { key: "photoId", kind: "image", label: "Photo" },
|
||||
] },
|
||||
@@ -42,7 +49,7 @@ export const SECTION_FIELDS: Record<string, { name: string; fields: Spec[] }> =
|
||||
team: { name: "Team", fields: [heading, { key: "intro", kind: "textarea", label: "Introduction", max: 400 }] },
|
||||
events: { name: "Upcoming events", fields: [heading, { key: "count", kind: "number", label: "How many to show", min: 2, max: 12 }] },
|
||||
latestMessage: { name: "Latest message", fields: [heading] },
|
||||
invitation: { name: "Invitation", fields: [heading, { key: "text", kind: "textarea", label: "Text", max: 400 }, button, { key: "imageId", kind: "image", label: "Background photo (Image background layout)" }] },
|
||||
invitation: { name: "Invitation", fields: [heading, { key: "text", kind: "textarea", label: "Text", max: 400 }, button, { key: "imageId", kind: "image", label: "Background photo", layouts: ["image"] }] },
|
||||
};
|
||||
|
||||
export const BLOCK_FIELDS: Record<string, { name: string; fields: Spec[] }> = {
|
||||
@@ -58,11 +65,15 @@ type Data = Record<string, unknown>;
|
||||
* A section's or block's fields. With `frame` (the top-level form of a section), its photos show in
|
||||
* the shape of their frame on the site and can be moved and zoomed (saved in `data.framing`).
|
||||
*/
|
||||
export function DataForm({ fields, value, onChange, errors, prefix = "", frame }: { fields: Spec[]; value: Data; onChange: (v: Data) => void; errors: Record<string, string>; prefix?: string; frame?: Framing["frame"] }) {
|
||||
export function DataForm({ fields, value, onChange, errors, prefix = "", frame, layout }: {
|
||||
fields: Spec[]; value: Data; onChange: (v: Data) => void; errors: Record<string, string>; prefix?: string; frame?: Framing["frame"];
|
||||
/** The section's layout: only the fields it shows are offered (left out, all of them are). */
|
||||
layout?: string;
|
||||
}) {
|
||||
const set = (k: string, v: unknown) => onChange({ ...value, [k]: v });
|
||||
const form = (
|
||||
<div className="space-y-4">
|
||||
{fields.map((f) => {
|
||||
{fields.filter((f) => !layout || !f.layouts || f.layouts.includes(layout)).map((f) => {
|
||||
const err = errors[`${prefix}${f.key}`];
|
||||
const v = value[f.key];
|
||||
switch (f.kind) {
|
||||
@@ -76,11 +87,22 @@ export function DataForm({ fields, value, onChange, errors, prefix = "", frame }
|
||||
return <div key={f.key}><ImagePicker label={f.label} slot={{ key: f.key }} value={(v as string) ?? null} onChange={(id) => set(f.key, id)} />{err && <p className="text-xs text-red-700">{err}</p>}</div>;
|
||||
case "images": {
|
||||
const list = Array.isArray(v) ? (v as string[]) : [];
|
||||
// A slot for each photo the layout shows, chosen or not. Photos past them (from a layout
|
||||
// that shows more) are kept, so switching back brings them back.
|
||||
const count = layout ? (f.count?.[layout] ?? f.max) : f.max;
|
||||
const label = (layout && f.labels?.[layout]) || f.label;
|
||||
if (count === 0) return <p key={f.key} className="text-sm text-gray-500">This layout shows no photos. Choose another layout above to add some.</p>;
|
||||
const extra = list.length - count;
|
||||
return (
|
||||
<div key={f.key} className="space-y-2">
|
||||
<p className="text-sm font-medium text-gray-800">{f.label}</p>
|
||||
{list.map((id, i) => <ImagePicker key={i} label={`Photo ${i + 1}`} slot={{ key: f.key, index: i }} value={id} onChange={(n) => set(f.key, n ? list.map((x, j) => (j === i ? n : x)) : list.filter((_, j) => j !== i))} />)}
|
||||
{list.length < f.max && <ImagePicker label={`Photo ${list.length + 1}`} slot={{ key: f.key, index: list.length }} value={null} onChange={(n) => n && set(f.key, [...list, n])} />}
|
||||
{count > 1 && <p className="text-sm font-medium text-gray-800">{label}</p>}
|
||||
{Array.from({ length: count }, (_, i) => {
|
||||
const id = list[i] ?? null;
|
||||
const name = count > 1 ? `Photo ${i + 1} of ${count}` : label;
|
||||
return <ImagePicker key={i} label={name} slot={{ key: f.key, index: i }} value={id}
|
||||
onChange={(n) => set(f.key, id ? (n ? list.map((x, j) => (j === i ? n : x)) : list.filter((_, j) => j !== i)) : n ? [...list, n] : list)} />;
|
||||
})}
|
||||
{extra > 0 && <p className="text-xs text-gray-500">{extra === 1 ? "1 more photo is" : `${extra} more photos are`} kept for a layout that shows more.</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* The homepage sections' layouts and backgrounds, shared by Template and style (Home page layout)
|
||||
* and the home page's editor (Pages), which both change them. The ids are the backend's
|
||||
* (src/site/variants.ts SECTION_VARIANTS and SECTION_BACKGROUNDS).
|
||||
*/
|
||||
|
||||
export type HomeEntry = { section: string; hidden: boolean; background?: string };
|
||||
export type Design = { template: string; variants: Record<string, string>; home: HomeEntry[]; style: Record<string, string> };
|
||||
export type DesignOptions = { variants: Record<string, Record<string, string[]>>; headers: Record<string, string[]> };
|
||||
|
||||
export const TEMPLATE_NAMES: Record<string, string> = { heritage: "Heritage", bold: "Bold", community: "Community", clean: "Clean" };
|
||||
|
||||
export const SECTION_NAMES: 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",
|
||||
};
|
||||
|
||||
export 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",
|
||||
};
|
||||
|
||||
export 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"],
|
||||
};
|
||||
|
||||
/** A section's layouts, the ones that suit the template first, and which those are. */
|
||||
export function layoutsFor(design: Design, options: DesignOptions | undefined, section: string): { ordered: string[]; recommended: string[] } {
|
||||
const recommended = options?.variants[design.template]?.[section] ?? [];
|
||||
return { ordered: [...recommended, ...(ALL_VARIANTS[section] ?? []).filter((v) => !recommended.includes(v))], recommended };
|
||||
}
|
||||
|
||||
/** A section's own background (backend variants.ts SECTION_BACKGROUNDS), each from the church's colours; "" follows Style → Section colour. */
|
||||
export 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))" },
|
||||
];
|
||||
|
||||
/** The home list with `section`'s background set ("" clears it, so it follows the style). */
|
||||
export const withBackground = (home: HomeEntry[], section: string, background: string): HomeEntry[] =>
|
||||
home.map(({ background: b, ...e }) => {
|
||||
const next = e.section === section ? background : b;
|
||||
return next ? { ...e, background: next } : e;
|
||||
});
|
||||
|
||||
/** The home list with `section` shown or not. */
|
||||
export const withShown = (home: HomeEntry[], section: string, shown: boolean): HomeEntry[] =>
|
||||
home.map((e) => (e.section === section ? { ...e, hidden: !shown } : e));
|
||||
|
||||
/** The home list with the entry at `i` moved one place up (-1) or down (1), or null at an end. */
|
||||
export function moved(home: HomeEntry[], i: number, d: -1 | 1): HomeEntry[] | null {
|
||||
const j = i + d;
|
||||
if (j < 0 || j >= home.length) return null;
|
||||
const next = [...home];
|
||||
[next[i], next[j]] = [next[j]!, next[i]!];
|
||||
return next;
|
||||
}
|
||||
@@ -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