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
|
|
@ -11,6 +11,11 @@
|
|||
(pages/admin/AdminMedia.tsx) draw.
|
||||
UploadButton a file input dressed as a button, with the
|
||||
"keep original" choice beside it.
|
||||
LinkPreviewInput
|
||||
the `widget: "linkPreview"` field: a URL box and a
|
||||
"Fetch preview" button that reads the page's title,
|
||||
description and preview image (the image lands in
|
||||
the library) and fills the row's empty fields.
|
||||
|
||||
An image field stores a path, not a media id: '/uploads/<file>'
|
||||
for an upload, or, as before, a bare filename in the field's
|
||||
|
|
@ -26,7 +31,7 @@
|
|||
|
||||
import { useCallback, useEffect, useId, useRef, useState, type ReactNode } from "react";
|
||||
|
||||
import { ApiError, get, upload } from "../../lib/api.ts";
|
||||
import { ApiError, get, post, upload } from "../../lib/api.ts";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
|
||||
|
||||
|
|
@ -405,3 +410,85 @@ export function ImageInput({
|
|||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Link preview field ──────────────────────────────────────── */
|
||||
|
||||
/* Fills only what's empty: a title somebody already typed is theirs,
|
||||
not the page's. Which fields it fills is the row's title, blurb and
|
||||
image, the featured card's names. */
|
||||
export function LinkPreviewInput({
|
||||
id,
|
||||
value,
|
||||
row,
|
||||
locked,
|
||||
className,
|
||||
showButton,
|
||||
onChange,
|
||||
onPatch,
|
||||
}: {
|
||||
id: string;
|
||||
value: string | null | undefined;
|
||||
row: Record<string, any>;
|
||||
locked: boolean;
|
||||
className: string;
|
||||
showButton: boolean;
|
||||
onChange: (value: string) => void;
|
||||
onPatch?: (patch: Record<string, any>) => void;
|
||||
}) {
|
||||
const { user } = useAuth();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<{ tone: "ok" | "error"; text: string } | null>(null);
|
||||
|
||||
async function fetchPreview() {
|
||||
if (!value || !onPatch) return;
|
||||
setBusy(true);
|
||||
setNote(null);
|
||||
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;
|
||||
onPatch(patch);
|
||||
|
||||
const filled = Object.keys(patch).length;
|
||||
setNote(
|
||||
preview.image_error
|
||||
? { tone: "error", text: `Filled ${filled} field${filled === 1 ? "" : "s"}. ${preview.image_error}` }
|
||||
: filled
|
||||
? { tone: "ok", text: `Filled ${filled} empty field${filled === 1 ? "" : "s"}.` }
|
||||
: { tone: "ok", text: "Nothing to fill: those fields already have values, or the page has none." },
|
||||
);
|
||||
} catch (err) {
|
||||
setNote({ tone: "error", text: err instanceof ApiError ? err.message : "Couldn't read that page." });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<input
|
||||
id={id}
|
||||
type="text"
|
||||
value={value ?? ""}
|
||||
readOnly={locked}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder="https://"
|
||||
className={className}
|
||||
/>
|
||||
{showButton && !locked && roleCanWrite(user) && (
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<button type="button" className={button} disabled={busy || !value} onClick={fetchPreview}>
|
||||
{busy ? "Fetching…" : "Fetch preview"}
|
||||
</button>
|
||||
{note && (
|
||||
<span className={`text-xs ${note.tone === "ok" ? "text-[#138ba0]" : "text-[#b3261e]"}`}>
|
||||
{note.text}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue