Add a Featured Content section to the front page
Front page → Featured cards (migration 030) holds cards of three kinds: a record on the site, whose title, picture and link fill in from the record; a link, with a Fetch preview button that reads the page's title, description and preview image into the media library; and a video, drawn as a thumbnail that loads the player when pressed. A 'featured' section draws them. The cards are shared: featured_cards is owned polymorphically and FeaturedCards.tsx draws them, ready for the Community blog. Deleting a record removes its cards; an unpublished record's card is hidden. The preview fetch only goes to public http(s) addresses on standard ports, pinned to the vetted IP, with each redirect checked again. Along the way: repeater fields can show by another field's value (a hidden one is cleared), a CHECK named as a sentence is shown as the error, and the timeline's record list is now record_refs for both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
960c854611
commit
d4f65d93b4
17 changed files with 1140 additions and 50 deletions
|
|
@ -26,6 +26,16 @@
|
|||
that column in the server's admin-schema.js or the row will be
|
||||
saved as real input.
|
||||
|
||||
In a repeater row, `when: { path, value }` shows a field only
|
||||
while another field of the row holds that value (or one of them,
|
||||
given an array). A field that goes hidden is cleared, so a row
|
||||
can't keep a value for a choice it no longer makes: a featured
|
||||
card switched from "record" to "link" drops its record.
|
||||
|
||||
`widget: "linkPreview"` is a URL box with a "Fetch preview" button
|
||||
(LinkPreviewInput in MediaLibrary.tsx) that fills the row's empty
|
||||
title, blurb and image through `onPatch`.
|
||||
|
||||
`widget: "image"` is a text box with a preview and upload and
|
||||
library buttons beside it (ImageInput in MediaLibrary.tsx). Its
|
||||
`resolve` option is the media.ts helper for the field's public/
|
||||
|
|
@ -47,7 +57,7 @@
|
|||
|
||||
import { useRef, useState } from "react";
|
||||
|
||||
import { ImageInput } from "./MediaLibrary.tsx";
|
||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||
|
||||
const input =
|
||||
"w-full rounded-lg border border-[#4a6b72]/25 bg-white px-3 py-2 text-sm text-[#26454c] " +
|
||||
|
|
@ -84,9 +94,30 @@ export function setPath(object, path, value) {
|
|||
return { ...object, [head]: setPath(object?.[head] ?? {}, rest.join("."), value) };
|
||||
}
|
||||
|
||||
/* ── Conditional fields ──────────────────────────────────────── */
|
||||
|
||||
export function fieldShown(field, row) {
|
||||
if (!field.when) return true;
|
||||
const want = Array.isArray(field.when.value) ? field.when.value : [field.when.value];
|
||||
return want.includes(row?.[field.when.path]);
|
||||
}
|
||||
|
||||
/* A row after an edit, with any field the edit hid cleared. "" is
|
||||
the engine's deliberate clear, so it saves as NULL. */
|
||||
function withHiddenCleared(fields, row) {
|
||||
let next = row;
|
||||
for (const field of fields) {
|
||||
const value = next[field.path];
|
||||
if (!fieldShown(field, next) && value != null && value !== "") {
|
||||
next = { ...next, [field.path]: "" };
|
||||
}
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
/* ── Field ───────────────────────────────────────────────────── */
|
||||
|
||||
export function Field({ field, value, row, options, error, onChange }: any) {
|
||||
export function Field({ field, value, row, options, error, onChange, onPatch }: any) {
|
||||
const id = `f-${field.path.replace(/\./g, "-")}`;
|
||||
const widget = field.widget ?? "text";
|
||||
const locked = Boolean(field.readOnly);
|
||||
|
|
@ -183,6 +214,17 @@ export function Field({ field, value, row, options, error, onChange }: any) {
|
|||
className={locked ? inputLocked : common.className}
|
||||
/>
|
||||
</div>
|
||||
) : widget === "linkPreview" ? (
|
||||
<LinkPreviewInput
|
||||
id={id}
|
||||
value={value}
|
||||
row={row}
|
||||
locked={locked}
|
||||
className={locked ? inputLocked : common.className}
|
||||
showButton={!field.previewWhen || fieldShown({ when: field.previewWhen }, row)}
|
||||
onChange={onChange}
|
||||
onPatch={onPatch}
|
||||
/>
|
||||
) : widget === "image" ? (
|
||||
<ImageInput
|
||||
id={id}
|
||||
|
|
@ -298,7 +340,7 @@ export function Repeater({
|
|||
const rowRefs = useRef<any[]>([]);
|
||||
|
||||
const update = (index, next) =>
|
||||
onChange(list.map((row, i) => (i === index ? next : row)));
|
||||
onChange(list.map((row, i) => (i === index ? withHiddenCleared(spec.fields, next) : row)));
|
||||
|
||||
const move = (index, delta) => {
|
||||
const target = index + delta;
|
||||
|
|
@ -489,17 +531,20 @@ export function Repeater({
|
|||
{expanded && (
|
||||
<>
|
||||
<FieldGrid>
|
||||
{spec.fields.map((field) => (
|
||||
<Field
|
||||
key={field.path}
|
||||
field={field}
|
||||
row={row}
|
||||
value={row[field.path]}
|
||||
options={options}
|
||||
error={errors?.[`${errorPrefix}${index}.${field.path}`]}
|
||||
onChange={(value) => update(index, { ...row, [field.path]: value })}
|
||||
/>
|
||||
))}
|
||||
{spec.fields
|
||||
.filter((field) => fieldShown(field, row))
|
||||
.map((field) => (
|
||||
<Field
|
||||
key={field.path}
|
||||
field={field}
|
||||
row={row}
|
||||
value={row[field.path]}
|
||||
options={options}
|
||||
error={errors?.[`${errorPrefix}${index}.${field.path}`]}
|
||||
onChange={(value) => update(index, { ...row, [field.path]: value })}
|
||||
onPatch={(patch) => update(index, { ...row, ...patch })}
|
||||
/>
|
||||
))}
|
||||
</FieldGrid>
|
||||
|
||||
{(spec.children ?? []).map((nested) => (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue