Region featured cards, featured grid, video stills, media naming (v1.13.2-region-cards) #30

Merged
ngu-git-admin merged 6 commits from region-featured-cards into main 2026-10-16 20:13:17 +01:00
11 changed files with 130 additions and 23 deletions
Showing only changes of commit 31d9f78120 - Show all commits

View file

@ -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/<tag>`. |
| 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 |

View file

@ -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"]),
],
});

View file

@ -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: [

View file

@ -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'));

View file

@ -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),
},
});

View file

@ -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,
});
}
}

View file

@ -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<FeaturedColumns, string> = {
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<FeaturedSize, string>> = {
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 (
<li
className={`relative flex flex-col overflow-hidden border-r-4 border-b-4 ${RULE} bg-raised transition-colors hover:bg-tint-soft ${
large ? 'lg:col-span-2 lg:row-span-2' : ''
}`}
className={`relative flex flex-col overflow-hidden border-r-4 border-b-4 ${RULE} bg-raised transition-colors hover:bg-tint-soft ${spans}`}
>
{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 <ReadingCards cards={cards} level={level} />
const leadLarge = cards.length >= 3
const spans = SPANS[columns === 2 ? 'sm' : 'lg']
return (
<div className="overflow-hidden shadow-md">
<ul className="-mr-[4px] -mb-[4px] grid sm:grid-cols-2 lg:grid-cols-3">
{cards.map((card, index) => (
<ul className={`-mr-[4px] -mb-[4px] grid ${GRID_COLUMNS[columns]}`}>
{cards.map((card, index) => {
const size = sizeOf(card, index, cards.length)
return (
<Card
key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}
card={card}
large={leadLarge && index === 0}
size={size}
spans={spans[size]}
level={level}
/>
))}
)
})}
</ul>
</div>
)

View file

@ -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",

View file

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

View file

@ -70,7 +70,7 @@ const BANDS: Record<FrontPageSectionKey, (props: BandProps) => ReactNode> = {
<Pathfinder id={id('connect')!} title={title} blurb={section.blurb} paths={page.paths} />
),
featured: ({ page, section, title }) => (
<FeaturedBand id={id('featured')!} title={title} blurb={section.blurb} cards={page.featured} />
<FeaturedBand id={id('featured')!} title={title} blurb={section.blurb} cards={page.featured} columns={page.featured_columns} />
),
}

View file

@ -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 (
<section id={id} className="py-24">
<div className="mx-auto max-w-6xl px-6">
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{title}</h2>
{blurb && <p className="mt-4 max-w-2xl text-lg text-muted">{blurb}</p>}
<div className="mt-12">
<FeaturedCards cards={cards} />
<FeaturedCards cards={cards} columns={columns ?? undefined} />
</div>
</div>
</section>