Video frame stills for featured cards; newsletter Pick from fix
- Image fields take frameFrom/frameWhen: "Frame at" saves a still from the row's YouTube or Facebook link to /uploads/thumbnails/ (POST /api/admin/video-frame, grabFrame in clips.js). Used on video featured cards. - clock/parseClock moved to src/lib/clock.ts, shared with Video clips. - Newsletter: new drafts no longer store source 'events' (the Pick from select's blank choice), which showed as "events no longer exists"; older drafts load it as blank. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3b45944094
commit
b8012c75e9
9 changed files with 172 additions and 25 deletions
|
|
@ -44,6 +44,7 @@ import { useLocation } from "react-router-dom";
|
|||
|
||||
import { ApiError, get, post, upload } from "../../lib/api.ts";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { clock, parseClock } from "../../lib/clock.ts";
|
||||
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
|
||||
import { useSmallImage } from "../../lib/useSmallImage.ts";
|
||||
|
||||
|
|
@ -524,6 +525,7 @@ export function ImageInput({
|
|||
value,
|
||||
resolve,
|
||||
folder,
|
||||
videoUrl,
|
||||
locked,
|
||||
className,
|
||||
onChange,
|
||||
|
|
@ -533,6 +535,8 @@ export function ImageInput({
|
|||
resolve?: (file?: string | null) => string | null;
|
||||
/** The field's `folder` (logos for logo fields); default images. */
|
||||
folder?: string;
|
||||
/** A video link to take a frame from (the field's `frameFrom`). */
|
||||
videoUrl?: string | null;
|
||||
locked: boolean;
|
||||
className: string;
|
||||
onChange: (value: string) => void;
|
||||
|
|
@ -587,6 +591,7 @@ export function ImageInput({
|
|||
)}
|
||||
</div>
|
||||
)}
|
||||
{editable && videoUrl && <FrameFromVideo url={videoUrl} className={className} onSaved={onChange} />}
|
||||
</div>
|
||||
|
||||
{picking && (
|
||||
|
|
@ -601,6 +606,55 @@ export function ImageInput({
|
|||
);
|
||||
}
|
||||
|
||||
/* ── Frame from a video ──────────────────────────────────────── */
|
||||
|
||||
/* A link's own start time (YouTube's t=83 or t=83s), so a link
|
||||
copied at the moment wanted starts the picker there. */
|
||||
function startOf(url: string): number {
|
||||
try {
|
||||
const t = new URL(url).searchParams.get("t") ?? "";
|
||||
return /^\d+s?$/.test(t) ? parseInt(t, 10) : 0;
|
||||
} catch {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
function FrameFromVideo({ url, className, onSaved }: { url: string; className: string; onSaved: (value: string) => void }) {
|
||||
const [text, setText] = useState(() => clock(startOf(url)));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const timeId = useId();
|
||||
const seconds = parseClock(text);
|
||||
|
||||
async function take() {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const { media } = await post("/admin/video-frame", { url, seconds });
|
||||
onSaved(media.url);
|
||||
} catch (err) {
|
||||
setError(err instanceof ApiError ? err.message : "Couldn't take that frame.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<label htmlFor={timeId} className="text-sm text-muted">
|
||||
Frame at
|
||||
</label>
|
||||
<div className="w-24">
|
||||
<input id={timeId} type="text" value={text} onChange={(e) => setText(e.target.value)} placeholder="eg. 1:23" className={className} />
|
||||
</div>
|
||||
<button type="button" className={button} disabled={busy || seconds == null} onClick={take}>
|
||||
{busy ? "Taking…" : "Use this frame"}
|
||||
</button>
|
||||
{error && <span className="text-xs text-danger">{error}</span>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/* ── Link preview field ──────────────────────────────────────── */
|
||||
|
||||
/* Fills only what's empty: a title somebody already typed is theirs,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue