Regions: featured cards in the region list and on the region's page (migration 072)

A region owns featured cards like the front page does, set in its
editor (shown when Kind is region). They show in its row of the
region list when opened, and in a Featured section on its page.
featured_cards takes an 'organization' owner kind; the table is
rebuilt, and a region's cards go when it does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aidan Dona 2026-10-07 16:56:14 -05:00
parent 07be48d770
commit 2977168af5
9 changed files with 181 additions and 17 deletions

View file

@ -226,7 +226,7 @@ export function shapeSeries(row) {
}
/* ── Featured cards ────────────────────────────────────────────
One owner's cards (the front page's, today), in order, with
One owner's cards (the front page's, a region's), in order, with
each record card filled in from its record. Shared so the
Community blog's cards will come out the same shape.
@ -285,13 +285,22 @@ const FEATURED_REFS = {
};
export function loadFeaturedCards(db, ownerKind, ownerId) {
return loadFeaturedCardsFor(db, ownerKind, [ownerId]).get(ownerId) ?? [];
}
/* Several owners' cards at once (every region in the region list),
as owner id → cards, in the same number of queries as one owner. */
export function loadFeaturedCardsFor(db, ownerKind, ownerIds) {
const byOwner = new Map();
if (ownerIds.length === 0) return byOwner;
const rows = db
.prepare(
`SELECT * FROM featured_cards
WHERE owner_kind = ? AND owner_id = ?
ORDER BY sort_order, id`,
WHERE owner_kind = ? AND owner_id IN (${placeholders(ownerIds.length)})
ORDER BY owner_id, sort_order, id`,
)
.all(ownerKind, ownerId);
.all(ownerKind, ...ownerIds);
// kind → id → record row
const records = new Map();
@ -306,8 +315,9 @@ export function loadFeaturedCards(db, ownerKind, ownerId) {
const own = (row) => (row.image ? { file: row.image, kind: "featured" } : null);
const cards = [];
for (const row of rows) {
let cards = byOwner.get(row.owner_id);
if (!cards) byOwner.set(row.owner_id, (cards = []));
if (row.kind === "record") {
const record = records.get(row.ref_kind)?.get(row.ref_id);
if (!record) continue; // unpublished, or its organization is
@ -332,7 +342,7 @@ export function loadFeaturedCards(db, ownerKind, ownerId) {
});
}
}
return cards;
return byOwner;
}
export { asBool };