Content display, requests and Google Workspace (v1.9.5 to v1.9.11-content-display) #15
8 changed files with 123 additions and 18 deletions
|
|
@ -149,6 +149,7 @@ export const blocksChild = (ownerKind) => ({
|
|||
"callout",
|
||||
"schedule",
|
||||
"table",
|
||||
"cards",
|
||||
],
|
||||
{ required: true },
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
-- ═══════════════════════════════════════════════════════════════
|
||||
-- 044 TABLE BLOCKS
|
||||
-- 044 TABLE AND CARD BLOCKS
|
||||
--
|
||||
-- A content block of type 'table': a grid of text, for comparison
|
||||
-- charts and the like (a blog post imported from Word, say). The
|
||||
-- grid is the block's text, one row per line, cells split by "|",
|
||||
-- the first row the header; cells take the same inline formatting as
|
||||
-- a paragraph (**bold**, *italic*, [link](url)). ContentBlocks.tsx
|
||||
-- draws it.
|
||||
-- Two content block types:
|
||||
--
|
||||
-- table a grid of text, for comparison charts and the like (a
|
||||
-- blog post imported from Word, say). The grid is the
|
||||
-- block's text, one row per line, cells split by "|", the
|
||||
-- first row the header; cells take the same inline
|
||||
-- formatting as a paragraph (**bold**, *italic*,
|
||||
-- [link](url)).
|
||||
-- cards link cards, one per item, like a link shared in a chat:
|
||||
-- the item's text is the title, detail the description,
|
||||
-- url the link and media the picture (all as today's item
|
||||
-- columns). Fetch preview in the admin fills them.
|
||||
--
|
||||
-- ContentBlocks.tsx draws both.
|
||||
--
|
||||
-- Only the type's CHECK changes, and SQLite can't alter a CHECK, so
|
||||
-- the table is rebuilt the way 031, 032 and 034 did it
|
||||
|
|
@ -25,7 +33,7 @@ CREATE TABLE content_blocks_new (
|
|||
type TEXT NOT NULL
|
||||
CHECK (type IN ('heading', 'subheading', 'paragraph',
|
||||
'list', 'links', 'quote', 'image', 'divider',
|
||||
'video', 'button', 'callout', 'schedule', 'table')),
|
||||
'video', 'button', 'callout', 'schedule', 'table', 'cards')),
|
||||
text TEXT,
|
||||
media TEXT,
|
||||
href TEXT,
|
||||
|
|
|
|||
|
|
@ -132,6 +132,18 @@ const ALL_BLOCKS = [
|
|||
["subheading", { text: "Video" }],
|
||||
["video", { href: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", text: "A YouTube video, with its own thumbnail" }],
|
||||
["video", { href: "https://vimeo.com/76979871", media: IMAGE, text: "A Vimeo video with an uploaded still" }],
|
||||
["subheading", { text: "Table" }],
|
||||
["table", { text: [
|
||||
"Platform | Monthly cost | Best for | Notes",
|
||||
"[Zeffy](https://www.zeffy.com) | Free | Fee-free giving | **0%** to the church",
|
||||
"Breeze | $72 | Small churches | Flat price, all features",
|
||||
"A cell with a bar \\| in it | Blank cells follow | |",
|
||||
].join("\n") }],
|
||||
["subheading", { text: "Link cards" }],
|
||||
["cards", {}, [
|
||||
{ text: "A card with a picture", detail: "Its description, up to three lines, under the title. The whole card is the link.", url: "/retreats", media: IMAGE },
|
||||
{ text: "An outside link, text only", detail: "The card shows the site it goes to above the title.", url: "https://example.org" },
|
||||
]],
|
||||
];
|
||||
|
||||
/* A record page's body: a handful of types, so it reads like a
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
text, detail, url, location, person, and
|
||||
a fold-out of description, media, map);
|
||||
text is an optional intro. ScheduleBlock
|
||||
table text: a row per line, cells split by |
|
||||
cards items as link cards: text the title,
|
||||
detail, url, media the picture
|
||||
divider nothing
|
||||
|
||||
"Formatted" is InlineText.tsx: **bold**, *italic*, [text](url),
|
||||
|
|
@ -34,12 +37,14 @@
|
|||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import type { ContentBlock } from '../lib/useContent.ts'
|
||||
import { Anchor, Inline, Paragraphs } from './InlineText.tsx'
|
||||
import type { ContentBlock, ContentBlockItem } from '../lib/useContent.ts'
|
||||
import { Anchor, Inline, Paragraphs, isExternalUrl } from './InlineText.tsx'
|
||||
import VideoPlayer from './VideoPlayer.tsx'
|
||||
import ScheduleBlock from './ScheduleBlock.tsx'
|
||||
import { accentText, BRAND } from '../lib/color.ts'
|
||||
import { headingAnchors } from '../lib/contents.ts'
|
||||
import { SITE_NAME } from '../lib/site.ts'
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
|
||||
const BODY = 'var(--color-muted)'
|
||||
|
||||
|
|
@ -66,6 +71,37 @@ export default function ContentBlocks({
|
|||
)
|
||||
}
|
||||
|
||||
/* One link card: the whole card is the link. The site's name above
|
||||
the title says where it goes (the host for an outside link). */
|
||||
function LinkCard({ item }: { item: ContentBlockItem }) {
|
||||
const url = item.url ?? ''
|
||||
const img = useSmallImage(mediaUrl(item.media))
|
||||
const where = isExternalUrl(url)
|
||||
? (() => {
|
||||
try {
|
||||
return new URL(url).hostname.replace(/^www\./, '')
|
||||
} catch {
|
||||
return url
|
||||
}
|
||||
})()
|
||||
: SITE_NAME
|
||||
return (
|
||||
<Anchor
|
||||
href={url}
|
||||
className="group flex h-full flex-col overflow-hidden rounded-2xl border border-brand/15 bg-surface shadow-sm transition-shadow hover:shadow-lg"
|
||||
>
|
||||
{!img.failed && (
|
||||
<img src={img.src} alt="" loading="lazy" onError={img.onError} className="aspect-video w-full object-cover" />
|
||||
)}
|
||||
<span className="flex flex-1 flex-col gap-1 p-5">
|
||||
<span className="text-xs font-semibold text-muted">{where}</span>
|
||||
<span className="font-display text-lg font-bold leading-snug text-ink group-hover:text-link">{item.text}</span>
|
||||
{item.detail && <span className="line-clamp-3 text-sm text-body">{item.detail}</span>}
|
||||
</span>
|
||||
</Anchor>
|
||||
)
|
||||
}
|
||||
|
||||
/* A table block's text as rows of cells: one row per line, cells
|
||||
split by "|" (a literal bar is "\|"), blank lines skipped. A
|
||||
leading and trailing bar, as in Markdown, is allowed. */
|
||||
|
|
@ -182,6 +218,20 @@ function Block({ block, accent, anchor }: { block: ContentBlock; accent: string;
|
|||
</figure>
|
||||
)
|
||||
|
||||
case 'cards': {
|
||||
const cards = (block.items ?? []).filter((item) => item.url && item.text)
|
||||
if (cards.length === 0) return null
|
||||
return (
|
||||
<ul className={cards.length === 1 ? 'max-w-xl' : 'grid gap-4 sm:grid-cols-2'}>
|
||||
{cards.map((item, i) => (
|
||||
<li key={i}>
|
||||
<LinkCard item={item} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
case 'table': {
|
||||
const rows = tableRows(text)
|
||||
if (rows.length === 0) return null
|
||||
|
|
|
|||
|
|
@ -438,6 +438,7 @@ export function LinkPreviewInput({
|
|||
locked,
|
||||
className,
|
||||
showButton,
|
||||
fills = { title: "title", blurb: "blurb", image: "image" },
|
||||
onChange,
|
||||
onPatch,
|
||||
}: {
|
||||
|
|
@ -449,6 +450,9 @@ export function LinkPreviewInput({
|
|||
showButton: boolean;
|
||||
onChange: (value: string) => void;
|
||||
onPatch?: (patch: Record<string, any>) => void;
|
||||
/** Which of the row's fields the preview fills (a list item's are
|
||||
* text, detail and media). */
|
||||
fills?: { title: string; blurb: string; image: string };
|
||||
}) {
|
||||
const { user } = useAuth();
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
|
@ -461,9 +465,9 @@ export function LinkPreviewInput({
|
|||
try {
|
||||
const { preview } = await post("/admin/link-preview", { url: value });
|
||||
const patch: Record<string, any> = {};
|
||||
if (!row.title && preview.title) patch.title = preview.title;
|
||||
if (!row.blurb && preview.description) patch.blurb = preview.description;
|
||||
if (!row.image && preview.image) patch.image = preview.image.url;
|
||||
if (!row[fills.title] && preview.title) patch[fills.title] = preview.title;
|
||||
if (!row[fills.blurb] && preview.description) patch[fills.blurb] = preview.description;
|
||||
if (!row[fills.image] && preview.image) patch[fills.image] = preview.image.url;
|
||||
onPatch(patch);
|
||||
|
||||
const filled = Object.keys(patch).length;
|
||||
|
|
|
|||
|
|
@ -160,9 +160,13 @@ export function fieldShown(field, row, parent?) {
|
|||
the engine's deliberate clear, so it saves as NULL. */
|
||||
function withHiddenCleared(spec, row, parent?) {
|
||||
let next = row;
|
||||
// Two fields can share a path, each shown for a different kind of
|
||||
// row (a card's Description and a list item's Detail are both
|
||||
// `detail`); a value is only hidden when none of them is showing.
|
||||
const shownPaths = new Set(spec.fields.filter((f) => fieldShown(f, row, parent)).map((f) => f.path));
|
||||
for (const field of spec.fields) {
|
||||
const value = next[field.path];
|
||||
if (!fieldShown(field, next, parent) && value != null && value !== "") {
|
||||
if (!shownPaths.has(field.path) && value != null && value !== "") {
|
||||
next = { ...next, [field.path]: "" };
|
||||
}
|
||||
}
|
||||
|
|
@ -303,6 +307,7 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
locked={locked}
|
||||
className={locked ? inputLocked : common.className}
|
||||
showButton={!field.previewWhen || fieldShown({ when: field.previewWhen }, row)}
|
||||
fills={field.previewFills}
|
||||
onChange={onChange}
|
||||
onPatch={onPatch}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -279,11 +279,15 @@ export const BLOCK_TYPES = [
|
|||
["video", "Video", "A YouTube, Vimeo or Facebook video, or a video file, played in place."],
|
||||
["schedule", "Schedule", "Entries in one tab per day, each folding out for more. The text is an optional intro."],
|
||||
["table", "Table", "A grid of text, eg. a comparison chart: one row per line, cells split by |, the first row the header."],
|
||||
["cards", "Link cards", "Cards with a picture, title and description, each a link, like a link shared in a chat. Paste a link and press Fetch preview."],
|
||||
["divider", "Divider", "A thin line between parts."],
|
||||
];
|
||||
|
||||
/* An item field that only a schedule's entries have. */
|
||||
export const SCHEDULE_ENTRY = { scope: "parent", path: "type", value: "schedule" };
|
||||
/* Item fields for a link card, and for every other kind of item. */
|
||||
export const CARD_ITEM = { scope: "parent", path: "type", value: "cards" };
|
||||
export const NOT_CARD_ITEM = { scope: "parent", path: "type", value: ["list", "links", "schedule"] };
|
||||
|
||||
export const blockTypeLabel = (type) => BLOCK_TYPES.find(([value]) => value === type)?.[1] ?? type;
|
||||
|
||||
|
|
@ -384,7 +388,7 @@ export const blocksChild = {
|
|||
key: "items",
|
||||
label: "Items",
|
||||
addLabel: "Add item",
|
||||
when: { path: "type", value: ["list", "links", "schedule"] },
|
||||
when: { path: "type", value: ["list", "links", "schedule", "cards"] },
|
||||
title: (row) => [row.day, row.time, row.text].filter(Boolean).join(" · ") || "New item",
|
||||
blank: { text: "" },
|
||||
fields: [
|
||||
|
|
@ -395,7 +399,17 @@ export const blocksChild = {
|
|||
when: SCHEDULE_ENTRY,
|
||||
},
|
||||
{ path: "time", label: "Time", help: "eg. 7:00pm, or 9:00 to 10:30am", when: SCHEDULE_ENTRY },
|
||||
{ path: "text", label: "Text", required: true, help: "Schedules: the entry's title" },
|
||||
// A card: the link first, so Fetch preview can fill the rest.
|
||||
{
|
||||
path: "url",
|
||||
label: "Link",
|
||||
widget: "linkPreview",
|
||||
previewFills: { title: "text", blurb: "detail", image: "media" },
|
||||
full: true,
|
||||
help: "A page on this site (eg. /retreats) or anywhere else. Fetch preview fills the title, description and picture.",
|
||||
when: CARD_ITEM,
|
||||
},
|
||||
{ path: "text", label: "Text", required: true, help: "Schedules: the entry's title. Cards: the card's title" },
|
||||
{
|
||||
path: "location",
|
||||
label: "Location",
|
||||
|
|
@ -411,8 +425,18 @@ export const blocksChild = {
|
|||
help: "Who hosts or speaks: shown with their photo, linked to their page",
|
||||
when: SCHEDULE_ENTRY,
|
||||
},
|
||||
{ path: "detail", label: "Detail", help: "A line under the text. Lists: shown after the text" },
|
||||
{ path: "url", label: "URL", help: "Blank for plain text. Link buttons need one." },
|
||||
{ path: "detail", label: "Detail", help: "A line under the text. Lists: shown after the text", when: NOT_CARD_ITEM },
|
||||
{ path: "detail", label: "Description", widget: "textarea", full: true, when: CARD_ITEM },
|
||||
{ path: "url", label: "URL", help: "Blank for plain text. Link buttons need one.", when: NOT_CARD_ITEM },
|
||||
{
|
||||
path: "media",
|
||||
label: "Picture",
|
||||
widget: "image",
|
||||
resolve: mediaUrl,
|
||||
full: true,
|
||||
help: "Optional. Default: none, the card is text only.",
|
||||
when: CARD_ITEM,
|
||||
},
|
||||
{
|
||||
path: "description",
|
||||
label: "More",
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ export type ContentBlock = {
|
|||
| 'callout'
|
||||
| 'schedule'
|
||||
| 'table'
|
||||
| 'cards'
|
||||
text?: string | null
|
||||
media?: string | null
|
||||
href?: string | null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue