diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f8b1db..a34c2ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ Each package and app has its own section and its own tags (`contracts@1.0.0`, `accounts@1.0.0`, …). +## website@1.10.0 - 2026-12-01 + +The home page laid out from its editor, and photos that match the layout (Joshua, 2026-12-01). +Frontend only: no migration, no contracts change. + +- **Website 1.10.0:** each homepage section's layout, background, order and showing in Pages → + Home (still under Template and style too); a section offers only the photo fields its layout + shows, with a slot for each photo (1 for Photo, Video and Split, 3 for Collage, none for Text + only), keeping photos for other layouts. +- Checked: the Website frontend's typecheck and lint, and the admin e2e suite (13 tests, one new). + ## events@3.9.0 + website@1.9.0 + accounts@1.10.0 - 2026-12-01 The church's details from Accounts on every site, section backgrounds, one colour picker (Joshua, diff --git a/apps/website/CHANGELOG.md b/apps/website/CHANGELOG.md index c1ccfbd..ab14bc9 100644 --- a/apps/website/CHANGELOG.md +++ b/apps/website/CHANGELOG.md @@ -1,5 +1,27 @@ # Changelog — Church Website +## [1.10.0] — 2026-12-01 + +No migration, no new environment settings, no backend change. + +### Added + +- **The home page's layouts in its editor** (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 (`PUT /design`), as under Template and style → Home page layout, which keeps them too; + the preview reloads on either a page or a design change. The layout and background lists are + shared in `frontend/src/admin/layouts.ts`. + +### Changed + +- **A section's photo fields follow its layout.** `DataForm` takes the section's `layout`; a + field's `layouts` limits it to some (Welcome's photo: Image and text; its pastor: With pastor; + the Invitation's photo: Image background), and a photo list's `count` gives a slot for each photo + the layout shows, chosen or not (the hero: 1 for Photo, Video and Split, 3 for Collage, none for + Text only). Photos past the slots stay saved for a layout that shows more. +- The e2e test opens the hero with `/^Top of the page/` (the new buttons' names contain it), and a + new test covers the layout, background, order and showing from the editor. + ## [1.9.0] — 2026-12-01 No migration, no new environment settings. Needs `@crosscode/ui` 0.4.0 (built with the Website). diff --git a/apps/website/WHATS-NEW.md b/apps/website/WHATS-NEW.md index 899baf8..0257eb7 100644 --- a/apps/website/WHATS-NEW.md +++ b/apps/website/WHATS-NEW.md @@ -3,6 +3,17 @@ What each version changes for the church, in plain language (read by the Hub like Cross Events' WHATS-NEW.md; a section shows once its version is tagged). +## 1.10.0 + +- **Lay out your home page while you edit it.** In **Pages → Home**, open a section to choose its + layout and background right there. Use the arrows to move a section up or down, and the eye to + show or hide it. No more switching back and forth to **Template and style** (it still has the + same settings, if you prefer it there). +- **The photos match the layout.** A section now asks for exactly the photos its layout shows: one + for Photo and Split, three for Collage, none for Text only. The Welcome's photo and the pastor's + photo and quote, and the Invitation's background photo, only appear for the layouts that use + them. Photos you added for another layout are kept, so switching back brings them back. + ## 1.9.0 - **Choose a background for each homepage section.** In **Template and style → Home page layout**, diff --git a/apps/website/backend/package.json b/apps/website/backend/package.json index d4da95a..c3d5840 100644 --- a/apps/website/backend/package.json +++ b/apps/website/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-backend", - "version": "1.9.0", + "version": "1.10.0", "description": "Church Website: the public site's content API, the admin API, publishing and uploads", "private": true, "type": "module", diff --git a/apps/website/e2e/admin.spec.ts b/apps/website/e2e/admin.spec.ts index 1d30d69..578ab00 100644 --- a/apps/website/e2e/admin.spec.ts +++ b/apps/website/e2e/admin.spec.ts @@ -191,7 +191,7 @@ test("move and zoom a photo in its frame, then delete a photo nothing uses", asy await page.goto("/admin/pages"); await page.getByRole("link", { name: /^Home\b/ }).first().click(); await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/); - await page.getByRole("button", { name: /Top of the page/ }).click(); + await page.getByRole("button", { name: /^Top of the page/ }).click(); await page.getByRole("button", { name: "Move and zoom" }).first().click(); const dialog = page.getByRole("dialog", { name: "Move and zoom the photo" }); await expect(dialog).toBeVisible(); @@ -245,3 +245,51 @@ test("move and zoom a ministry's, a leader's and an event's photo", async ({ pag await expect(page.getByText("Moved and zoomed to 200%")).toBeVisible(); } }); + +test("on the home page: each section's layout, background, place and showing, and only the photos its layout shows", async ({ page, context }) => { + await signIn(context); + await page.goto("/admin/pages"); + await page.getByRole("link", { name: /^Home\b/ }).first().click(); + await expect(page).toHaveURL(/\/admin\/pages\/[0-9a-f-]+$/); + const preview = page.frameLocator('iframe[title="Live preview of this page"]'); + + // The top of the page: a slot for each photo the layout shows (the demo has three photos). + await page.getByRole("button", { name: /^Top of the page/ }).click(); + const layout = page.getByLabel("Top of the page (hero): layout"); + await layout.selectOption("collage"); + await expect(page.getByText("Photo 3 of 3")).toBeVisible(); + await layout.selectOption("photo"); + await expect(page.getByText("Photo 1 of 3")).toHaveCount(0); + await expect(page.getByText("2 more photos are kept for a layout that shows more.")).toBeVisible(); + await layout.selectOption("text"); + await expect(page.getByText("This layout shows no photos.")).toBeVisible(); + await expect(preview.locator(".cc-section-hero img")).toHaveCount(0); + + // The welcome: its photo fields follow its layout, and it takes a background. + await page.getByRole("button", { name: /^Welcome/ }).click(); + const welcome = page.locator("section").filter({ has: page.getByRole("button", { name: /^Welcome/ }) }).last(); + await page.getByLabel("Welcome: layout").selectOption("text"); + await expect(welcome.getByText("Pastor's photo and quote")).toHaveCount(0); + await page.getByLabel("Welcome: layout").selectOption("pastor"); + await expect(welcome.getByText("Pastor's photo and quote")).toBeVisible(); + await page.getByLabel("Welcome: background").selectOption("brand"); + await expect(page.getByLabel("Welcome: background")).toHaveValue("brand"); + await page.screenshot({ path: "e2e/test-results/home-sections.png", fullPage: true }); + + // Hide it, show it, and move it. + await page.getByRole("button", { name: "Hide Welcome" }).click(); + await expect(welcome.getByText("Not shown")).toBeVisible(); + await page.getByRole("button", { name: "Show Welcome" }).click(); + await expect(welcome.getByText("Not shown")).toHaveCount(0); + const order = async () => page.locator("main section > div > button").evaluateAll((els) => els.map((e) => e.textContent?.split("·")[0]?.trim() ?? "")); + const before = await order(); + const at = before.findIndex((t) => t.startsWith("Welcome")); + await page.getByRole("button", { name: "Move Welcome up" }).click(); + await expect.poll(async () => (await order()).findIndex((t) => t.startsWith("Welcome"))).toBe(at - 1); + + // Template and style shows the same. + await page.goto("/admin/template"); + await page.getByRole("tab", { name: "Home page layout" }).click(); + await expect(page.getByLabel("Top of the page layout")).toHaveValue("text"); + await expect(page.getByLabel("Welcome background")).toHaveValue("brand"); +}); diff --git a/apps/website/frontend/package.json b/apps/website/frontend/package.json index 1c1ae13..57a6faa 100644 --- a/apps/website/frontend/package.json +++ b/apps/website/frontend/package.json @@ -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": { diff --git a/apps/website/frontend/src/admin/fields.tsx b/apps/website/frontend/src/admin/fields.tsx index 582d60c..698c8af 100644 --- a/apps/website/frontend/src/admin/fields.tsx +++ b/apps/website/frontend/src/admin/fields.tsx @@ -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; labels?: Record } | { 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 = 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 = 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 = 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 = { @@ -58,11 +65,15 @@ type Data = Record; * 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; 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; 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 = (
- {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
set(f.key, id)} />{err &&

{err}

}
; 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

This layout shows no photos. Choose another layout above to add some.

; + const extra = list.length - count; return (
-

{f.label}

- {list.map((id, i) => set(f.key, n ? list.map((x, j) => (j === i ? n : x)) : list.filter((_, j) => j !== i))} />)} - {list.length < f.max && n && set(f.key, [...list, n])} />} + {count > 1 &&

{label}

} + {Array.from({ length: count }, (_, i) => { + const id = list[i] ?? null; + const name = count > 1 ? `Photo ${i + 1} of ${count}` : label; + return set(f.key, id ? (n ? list.map((x, j) => (j === i ? n : x)) : list.filter((_, j) => j !== i)) : n ? [...list, n] : list)} />; + })} + {extra > 0 &&

{extra === 1 ? "1 more photo is" : `${extra} more photos are`} kept for a layout that shows more.

}
); } diff --git a/apps/website/frontend/src/admin/layouts.ts b/apps/website/frontend/src/admin/layouts.ts new file mode 100644 index 0000000..8febe73 --- /dev/null +++ b/apps/website/frontend/src/admin/layouts.ts @@ -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; home: HomeEntry[]; style: Record }; +export type DesignOptions = { variants: Record>; headers: Record }; + +export const TEMPLATE_NAMES: Record = { heritage: "Heritage", bold: "Bold", community: "Community", clean: "Clean" }; + +export const SECTION_NAMES: Record = { + 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 = { + 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 = { + 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; +} diff --git a/apps/website/frontend/src/app/admin/pages/[id]/page.tsx b/apps/website/frontend/src/app/admin/pages/[id]/page.tsx index c1cbdb9..7825ed5 100644 --- a/apps/website/frontend/src/app/admin/pages/[id]/page.tsx +++ b/apps/website/frontend/src/app/admin/pages/[id]/page.tsx @@ -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; 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; home: { section: string; hidden: boolean }[] }; const HOME_ORDER = ["hero", "serviceTimes", "welcome", "ministries", "team", "events", "latestMessage", "invitation"]; const LISTS: Record = { @@ -49,9 +50,11 @@ const summary = (data: Record) => { 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[0]["fields"]; initial: Record; frame?: Framing["frame"]; onSave: (data: Record) => Promise; 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 {title}{hidden} - {line ?? "Nothing written yet"} + {layout && `${VARIANT_NAMES[layout] ?? layout} · `}{line ?? "Nothing written yet"} {open ? : } {open ? "Close" : "Edit"} @@ -74,7 +77,8 @@ function SectionEditor({ type, title, fields, initial, onSave, hidden, extra, fr
{open && (
- + {settings} +
run(() => onSave(value), "Saved as a draft.")}>Save setOpen(false)}>Close @@ -135,18 +139,26 @@ export default function EditPage() { const router = useRouter(); const { data: page, error, setData } = useAdmin(`/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 ; const path = isHome ? "/" : `/${page.slug}`; const blockCall = (p: string, method: string, body?: unknown) => blocks.run(async () => setData(await api(`/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) => 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 ( @@ -167,13 +179,43 @@ export default function EditPage() {