From 31d9f78120474a9f6a812c3d19f2aeaf3da93b78 Mon Sep 17 00:00:00 2001 From: Aidan Dona Date: Wed, 7 Oct 2026 17:24:10 -0500 Subject: [PATCH] Front page: set the featured cards' grid by hand, columns and a size per card (migration 073) Front page editor: Featured Content > Columns (2, 3 or 4 across on a wide screen) and a Size on each card (normal, wide, tall, large). Blank keeps today's layout: 3 across, the first of three or more large. Regions and the Community blog stay automatic. Co-Authored-By: Claude Opus 5.5 --- docs/updating-data-in-code.md | 2 + server/src/admin-schema/columns.js | 2 + server/src/admin-schema/frontPage.js | 1 + server/src/migrations/073_featured_grid.sql | 21 +++++++ server/src/routes/home.js | 2 + server/src/shape.js | 5 +- src/components/FeaturedCards.tsx | 66 +++++++++++++++------ src/lib/adminSchema/frontPage.ts | 38 +++++++++++- src/lib/useFrontPage.ts | 7 +++ src/pages/Home.tsx | 2 +- src/pages/sections/home/FeaturedBand.tsx | 7 ++- 11 files changed, 130 insertions(+), 23 deletions(-) create mode 100644 server/src/migrations/073_featured_grid.sql diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index fd27b57..a82a52c 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -189,6 +189,8 @@ also in `server/src/admin-schema/` and a CHECK): | Front page → Sections → Section | countdown, retreats, calendar, stats, timeline, connect, featured | **yes**, `FRONT_PAGE_SECTIONS` | `SECTIONS` in `src/pages/Home.tsx`; see [below](#front-page-section-names) | | Front page → Stats → Number Source | manual, years_since, regions, … | **yes**, `STAT_SOURCES` | `STAT_QUERIES` in `server/src/routes/home.js`; see [below](#front-page-stat-sources) | | Front page → Featured cards → Card type (Community → Community blog: pinned community posts offers link and video only) | record, link, video | **yes**, `FEATURED_KINDS` | `FeaturedCards.tsx` (how each kind draws), `loadFeaturedCards` in `server/src/shape.js` | +| Front page → Featured Content → Columns (073) | 2, 3, 4 | **yes**, inline in `src/lib/adminSchema/frontPage.ts` | `GRID_COLUMNS` in `FeaturedCards.tsx`; the CHECK on `front_page.featured_columns` | +| Front page → Featured cards → Size (073; front page only, regions and the Community blog stay automatic) | normal, wide, tall, large | **yes**, inline in `src/lib/adminSchema/frontPage.ts` | `SPANS` and `sizeOf` in `FeaturedCards.tsx`; the CHECK on `featured_cards.size` | | Front page → Featured cards → Record type | event, organization, person, team, award | no | `FEATURED_REFS` in `server/src/shape.js` (what each fills the card with); the triggers in `030_featured_cards.sql` | | Pages → Sections → Preset | community_blog, group_map, region_list, partner_list, events, timeline, people_directory | **yes**, `PRESETS` in `src/lib/adminSchema/sitePages.ts` (which pages offer which, the list passed to each `sitePage`) | `PRESETS` in `src/pages/SitePage.tsx`. A People directory shows its tag's first `DIRECTORY_PREVIEW` people (`src/pages/sections/PeopleDirectory.tsx`), linking to `/directory/`. | | Pages → Sections → Cards: list (organization cards preset, 067) | partner, ministry, partner,ministry | **yes**, inline in `src/lib/adminSchema/sitePages.ts` | `partner_list` in `PRESETS` in `src/pages/SitePage.tsx` passes it as the kind to `OrgListCards`; a section's hand-picked Cards: organizations (`page_section_orgs`) replace it | diff --git a/server/src/admin-schema/columns.js b/server/src/admin-schema/columns.js index bda56ea..da5ec75 100644 --- a/server/src/admin-schema/columns.js +++ b/server/src/admin-schema/columns.js @@ -105,6 +105,8 @@ export const featuredCardsChild = (ownerKind) => ({ text("title"), text("blurb"), text("image"), + // Its shape in the grid (073); only the Front page editor sets it. + enumeration("size", ["normal", "wide", "tall", "large"]), ], }); diff --git a/server/src/admin-schema/frontPage.js b/server/src/admin-schema/frontPage.js index 3d11224..0edc04d 100644 --- a/server/src/admin-schema/frontPage.js +++ b/server/src/admin-schema/frontPage.js @@ -48,6 +48,7 @@ export const frontPage = { text("countdown_event_id"), text("countdown_scope_id"), enumeration("countdown_event_type", ["retreat", "class", "workshop", "meeting", "other"]), + int("featured_columns"), ], children: [ diff --git a/server/src/migrations/073_featured_grid.sql b/server/src/migrations/073_featured_grid.sql new file mode 100644 index 0000000..4c92afe --- /dev/null +++ b/server/src/migrations/073_featured_grid.sql @@ -0,0 +1,21 @@ +-- ═══════════════════════════════════════════════════════════════ +-- 073 FEATURED GRID +-- +-- The front page's featured cards get a hand-set shape: +-- +-- front_page.featured_columns 2, 3 or 4 across on a wide screen; +-- null is 3, as before +-- featured_cards.size normal, wide (2 columns), tall +-- (2 rows) or large (both); null is +-- automatic, as before: the first of +-- three or more cards is large +-- +-- Only the Front page editor offers them. A region's or the +-- Community blog's cards keep a null size, so they lay out as before. +-- ═══════════════════════════════════════════════════════════════ + +ALTER TABLE front_page ADD COLUMN featured_columns INTEGER + CHECK (featured_columns IN (2, 3, 4)); + +ALTER TABLE featured_cards ADD COLUMN size TEXT + CHECK (size IN ('normal', 'wide', 'tall', 'large')); diff --git a/server/src/routes/home.js b/server/src/routes/home.js index 054a450..2b67d19 100644 --- a/server/src/routes/home.js +++ b/server/src/routes/home.js @@ -233,6 +233,8 @@ home.get("/front-page", (c) => { stats, paths, featured: loadFeaturedCards(db, "front_page", PAGE_ID), + // 2, 3 or 4 across (073); null is the grid's own default. + featured_columns: page.featured_columns, countdown: shapeCountdown(next), }, }); diff --git a/server/src/shape.js b/server/src/shape.js index 762f9d5..e79c939 100644 --- a/server/src/shape.js +++ b/server/src/shape.js @@ -238,7 +238,8 @@ export function shapeSeries(row) { tables keep bare filenames in different public/ directories, and logoForKind in media.ts knows which is which. The kinds are the ref kinds, plus 'event-photo' and 'featured' (the - card's own image). An unpublished + card's own image). `size` is its shape in the grid (073), null + for automatic. An unpublished record's card is dropped; an unlisted one's stays, since featuring it is attaching it by hand. ───────────────────────────────────────────────────────────── */ @@ -329,6 +330,7 @@ export function loadFeaturedCardsFor(db, ownerKind, ownerIds) { title: row.title ?? record.title, blurb: row.blurb ?? record.blurb ?? null, image: own(row) ?? FEATURED_REFS[row.ref_kind].image(record), + size: row.size, }); } else { cards.push({ @@ -339,6 +341,7 @@ export function loadFeaturedCardsFor(db, ownerKind, ownerIds) { title: row.title, blurb: row.blurb, image: own(row), + size: row.size, }); } } diff --git a/src/components/FeaturedCards.tsx b/src/components/FeaturedCards.tsx index da018ea..9f95836 100644 --- a/src/components/FeaturedCards.tsx +++ b/src/components/FeaturedCards.tsx @@ -25,6 +25,13 @@ one, two rows tall, and the next two stack beside it, so it no longer stretches its neighbor. + The front page sets the shape by hand (073): `columns` is how many + across on a wide screen (2, 3 or 4; default 3), and a card's + `size` makes it wide (2 columns), tall (2 rows), large (both) or + normal. A card with no size is automatic, the rule above, so + cards nobody has sized lay out as they always have. Cards stay in + their list order; a shape that leaves a hole leaves it. + Reading mode (readingMode.ts) gets each card as a linked heading and its words, a video card linking to its video. `level` is that heading's level, one under the heading above the cards. @@ -35,7 +42,7 @@ import HomeLink from '../pages/sections/home/HomeLink.tsx' import VideoPlayer from './VideoPlayer.tsx' import { refHref } from '../lib/hrefs.ts' import { mediaUrl } from '../lib/media.ts' -import type { FeaturedCard } from '../lib/useFrontPage.ts' +import type { FeaturedCard, FeaturedColumns, FeaturedSize } from '../lib/useFrontPage.ts' import { useReadingMode } from '../lib/readingMode.ts' import { useSmallImage } from '../lib/useSmallImage.ts' @@ -86,7 +93,30 @@ function VideoPicture({ card }: { card: FeaturedCard }) { const RULE = 'border-brand' -function Card({ card, large, level }: { card: FeaturedCard; large: boolean; level: 3 | 4 | 5 }) { +/* Columns across, by setting. Two columns start at sm; three and + four take over at lg. Written out whole so Tailwind sees them. */ +const GRID_COLUMNS: Record = { + 2: 'sm:grid-cols-2', + 3: 'sm:grid-cols-2 lg:grid-cols-3', + 4: 'sm:grid-cols-2 lg:grid-cols-4', +} + +/* A card's spans, from the breakpoint its grid reaches its full + width: sm for a two column grid, lg otherwise. Below that every + card is one cell, so a wide card can't overflow a narrow grid. */ +const SPANS: Record<'sm' | 'lg', Record> = { + sm: { normal: '', wide: 'sm:col-span-2', tall: 'sm:row-span-2', large: 'sm:col-span-2 sm:row-span-2' }, + lg: { normal: '', wide: 'lg:col-span-2', tall: 'lg:row-span-2', large: 'lg:col-span-2 lg:row-span-2' }, +} + +/* A card's size, or for one with none, the automatic rule: the first + of three or more is large. */ +function sizeOf(card: FeaturedCard, index: number, count: number): FeaturedSize { + return card.size ?? (index === 0 && count >= 3 ? 'large' : 'normal') +} + +function Card({ card, size, spans, level }: { card: FeaturedCard; size: FeaturedSize; spans: string; level: 3 | 4 | 5 }) { + const large = size === 'large' const href = hrefFor(card) const Title = `h${level}` as const @@ -119,9 +149,7 @@ function Card({ card, large, level }: { card: FeaturedCard; large: boolean; leve return (
  • {card.kind === 'video' ? ( // Above the stretched link, which a video card doesn't have @@ -138,7 +166,7 @@ function Card({ card, large, level }: { card: FeaturedCard; large: boolean; leve ) } -type FeaturedCardsProps = { cards: FeaturedCard[]; level?: 3 | 4 | 5 } +type FeaturedCardsProps = { cards: FeaturedCard[]; level?: 3 | 4 | 5; columns?: FeaturedColumns } function ReadingCards({ cards, level = 3 }: FeaturedCardsProps) { const Title = `h${level}` as const @@ -158,21 +186,25 @@ function ReadingCards({ cards, level = 3 }: FeaturedCardsProps) { ) } -export default function FeaturedCards({ cards, level = 3 }: FeaturedCardsProps) { +export default function FeaturedCards({ cards, level = 3, columns = 3 }: FeaturedCardsProps) { const reading = useReadingMode() if (reading) return - const leadLarge = cards.length >= 3 + const spans = SPANS[columns === 2 ? 'sm' : 'lg'] return (
    -
      - {cards.map((card, index) => ( - - ))} +
        + {cards.map((card, index) => { + const size = sizeOf(card, index, cards.length) + return ( + + ) + })}
    ) diff --git a/src/lib/adminSchema/frontPage.ts b/src/lib/adminSchema/frontPage.ts index 6219462..58e76f2 100644 --- a/src/lib/adminSchema/frontPage.ts +++ b/src/lib/adminSchema/frontPage.ts @@ -163,6 +163,24 @@ export const frontPage = { }, ], }, + { + legend: "Featured Content", + note: "The cards themselves are under Featured cards below, each with its own Size.", + fields: [ + { + path: "featured_columns", + label: "Columns", + widget: "select", + options: [ + ["2", "2 across"], + ["3", "3 across"], + ["4", "4 across"], + ], + blankLabel: "Default: 3 across", + help: "On a wide screen. Tablets show 2, phones 1", + }, + ], + }, ], children: [ @@ -222,7 +240,25 @@ export const frontPage = { { path: "note", label: "Note", full: true }, ], }, - featuredCardsChild, + { + ...featuredCardsChild, + fields: [ + ...featuredCardsChild.fields, + { + path: "size", + label: "Size", + widget: "select", + options: [ + ["normal", "Normal: one cell"], + ["wide", "Wide: two columns"], + ["tall", "Tall: two rows"], + ["large", "Large: two columns, two rows"], + ], + blankLabel: "Default: automatic (the first of three or more is large)", + help: "On a wide screen. Phones show one card per row", + }, + ], + }, { key: "paths", label: "Connect Nav", diff --git a/src/lib/useFrontPage.ts b/src/lib/useFrontPage.ts index bb2cc81..065d2e0 100644 --- a/src/lib/useFrontPage.ts +++ b/src/lib/useFrontPage.ts @@ -106,8 +106,13 @@ export type FeaturedCard = { blurb?: string | null /** Resolve the file with mediaUrl in media.ts. */ image: { file: string; kind: string } | null + /** Its shape in the grid; null is automatic (FeaturedCards). */ + size?: FeaturedSize | null } +export type FeaturedSize = 'normal' | 'wide' | 'tall' | 'large' +export type FeaturedColumns = 2 | 3 | 4 + /** The countdown's event plus what the hero's event card draws. */ export type HeroEvent = CountdownEvent & { tagline?: string | null @@ -123,6 +128,8 @@ export type FrontPage = { stats: FrontPageStat[] paths: FrontPagePath[] featured: FeaturedCard[] + /** Columns across on a wide screen; null is the grid's default. */ + featured_columns: FeaturedColumns | null countdown: CountdownEvent | null } diff --git a/src/pages/Home.tsx b/src/pages/Home.tsx index 8c217ac..22b1e35 100644 --- a/src/pages/Home.tsx +++ b/src/pages/Home.tsx @@ -70,7 +70,7 @@ const BANDS: Record ReactNode> = { ), featured: ({ page, section, title }) => ( - + ), } diff --git a/src/pages/sections/home/FeaturedBand.tsx b/src/pages/sections/home/FeaturedBand.tsx index c13c0b6..6834786 100644 --- a/src/pages/sections/home/FeaturedBand.tsx +++ b/src/pages/sections/home/FeaturedBand.tsx @@ -8,23 +8,24 @@ ═══════════════════════════════════════════════════════════════ */ import FeaturedCards from '../../../components/FeaturedCards.tsx' -import type { FeaturedCard } from '../../../lib/useFrontPage.ts' +import type { FeaturedCard, FeaturedColumns } from '../../../lib/useFrontPage.ts' type FeaturedBandProps = { id: string title: string blurb?: string | null cards: FeaturedCard[] + columns?: FeaturedColumns | null } -export default function FeaturedBand({ id, title, blurb, cards }: FeaturedBandProps) { +export default function FeaturedBand({ id, title, blurb, cards, columns }: FeaturedBandProps) { return (

    {title}

    {blurb &&

    {blurb}

    }
    - +