diff --git a/server/src/routes/admin-entities.js b/server/src/routes/admin-entities.js index f8dec83..f7ff12f 100644 --- a/server/src/routes/admin-entities.js +++ b/server/src/routes/admin-entities.js @@ -63,12 +63,15 @@ function visible(c, entity, row) { return row; } -/* Everything the select inputs need, in one request. Small enough - that paging it would cost more than it saves. */ +/* What the select inputs need, in one request: the lists a form + names in ?only=people,events (src/lib/adminSchema.ts, optionsPath), + or every list without it. */ entities.get("/options", (c) => { const db = c.get("db"); + const only = c.req.query("only")?.split(","); const options = {}; for (const [key, sql] of Object.entries(OPTION_QUERIES)) { + if (only && !only.includes(key)) continue; options[key] = db.prepare(sql).all(); } return c.json({ options }, 200, NO_STORE); diff --git a/server/src/routes/blog.js b/server/src/routes/blog.js index 7c20922..420134a 100644 --- a/server/src/routes/blog.js +++ b/server/src/routes/blog.js @@ -24,7 +24,7 @@ import { Hono } from "hono"; -import { asBool, json, loadBlocks, loadFeaturedCards, marks, paragraphs } from "../shape.js"; +import { asBool, json, loadBlocks, loadFeaturedCards, marks } from "../shape.js"; import { readFeeds } from "../feeds.js"; const blog = new Hono(); @@ -64,12 +64,32 @@ function loadAuthors(db, ids) { return byPost; } -function shapeSummary(row, authors, body) { +/* The first paragraph of each post with no excerpt of its own, the + card's fallback text, by post id. Only that one row per post: a + card doesn't need the rest of the body. */ +function firstParagraphs(db, rows) { + const ids = rows.filter((row) => !row.excerpt).map((row) => row.id); + if (ids.length === 0) return new Map(); + const found = db + .prepare( + `SELECT owner_id, text FROM ( + SELECT owner_id, text, ROW_NUMBER() OVER (PARTITION BY owner_id ORDER BY sort_order) AS n + FROM content_blocks + WHERE owner_kind = 'blog_post' AND slot = 'body' AND type = 'paragraph' + AND text IS NOT NULL AND text <> '' + AND owner_id IN (${marks(ids.length)}) + ) WHERE n = 1`, + ) + .all(...ids); + return new Map(found.map((row) => [row.owner_id, row.text])); +} + +function shapeSummary(row, authors, firstParagraph) { return { id: row.id, title: row.title, // The card's text: the excerpt, else the body's first paragraph. - excerpt: row.excerpt || paragraphs(body)[0] || null, + excerpt: row.excerpt || firstParagraph || null, cover_image: row.cover_image, published_on: row.published_on, tags: splitTags(row.tags), @@ -94,8 +114,8 @@ export function postsBy(db, personId) { .all(personId); const ids = rows.map((row) => row.id); const authors = loadAuthors(db, ids); - const bodies = loadBlocks(db, "blog_post", ids, "body"); - return rows.map((row) => shapeSummary(row, authors.get(row.id) ?? [], bodies.get(row.id) ?? [])); + const first = firstParagraphs(db, rows); + return rows.map((row) => shapeSummary(row, authors.get(row.id) ?? [], first.get(row.id))); } /* ── One post ──────────────────────────────────────────────── */ @@ -164,7 +184,7 @@ blog.get("/community-blog", async (c) => { const posts = [...pinned, ...newest]; const ids = posts.map((row) => row.id); const authors = loadAuthors(db, ids); - const bodies = loadBlocks(db, "blog_post", ids, "body"); + const first = firstParagraphs(db, posts); // Theirs: pinned cards, then the feeds' newest. const cards = loadFeaturedCards(db, "community_page", PAGE_ID); @@ -194,7 +214,7 @@ blog.get("/community-blog", async (c) => { internal: { title: page.internal_title, posts: posts.map((row) => - shapeSummary(row, authors.get(row.id) ?? [], bodies.get(row.id) ?? []), + shapeSummary(row, authors.get(row.id) ?? [], first.get(row.id)), ), }, external: { diff --git a/src/components/OptionFilter.tsx b/src/components/OptionFilter.tsx new file mode 100644 index 0000000..d052182 --- /dev/null +++ b/src/components/OptionFilter.tsx @@ -0,0 +1,53 @@ +/* ═══════════════════════════════════════════════════════════════ + OPTION FILTER + + A select over hundreds of records (every person, every event) + only matches first letters as you type, so finding one means + scrolling. Past FILTER_FROM options, a small box above it narrows + the list to the options whose label holds what's typed: + + const [needle, setNeedle] = useState('') + const shown = narrow(list, needle, ([, label]) => label, ([id]) => id === value) + {list.length > FILTER_FROM && } + + `keep` holds an option in whatever the box says (the one chosen), + so narrowing never blanks the select's value. + ═══════════════════════════════════════════════════════════════ */ + +import { MagnifyingGlass } from '@phosphor-icons/react' + +export const FILTER_FROM = 50 + +export function narrow(items: T[], needle: string, text: (item: T) => string, keep?: (item: T) => boolean): T[] { + const term = needle.trim().toLowerCase() + if (!term) return items + return items.filter((item) => keep?.(item) || String(text(item) ?? '').toLowerCase().includes(term)) +} + +type OptionFilterProps = { + value: string + onChange: (value: string) => void + label: string + className?: string +} + +export function OptionFilter({ value, onChange, label, className = 'mb-1.5' }: OptionFilterProps) { + return ( +
+
+ ) +} diff --git a/src/components/PageShell.tsx b/src/components/PageShell.tsx index 0da8629..3e08689 100644 --- a/src/components/PageShell.tsx +++ b/src/components/PageShell.tsx @@ -294,10 +294,13 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P clipping sideways only, so nothing reaches the content or the screen's edge. clip, not hidden: hidden would make it a scroll container, and the sticky layers in - it would stop sticking. */} + it would stop sticking. z-20: in front of everything in the + sections, such as a carousel's arrows (z-10), which as later + siblings would otherwise draw over it; it takes no clicks + itself, only its list does. */}