"use client"; import type { SocialLink } from "yt-dlp-transcript-common/lib/settings"; import { socialLinksJson, type SocialRow } from "./socialLinksJson"; // Its controlled checkboxes sit inside action forms, whose reset they would not // survive alone (forms/Controlled.tsx). import { ControlledCheck } from "./forms/Controlled"; export type { SocialRow }; export function toSocialRow(s: SocialLink): SocialRow { return { label: s.label, url: s.url, svg: s.svg, ...(s.featured ? { featured: true } : {}), }; } type Props = { // Controlled rows + setter, owned by the parent form so it can also gate the // whole editor (e.g. behind an "inherit global" toggle). value: SocialRow[]; onChange: (rows: SocialRow[]) => void; // When set, a hidden carries the trimmed rows as JSON for the // server action (same shape both the sites and settings actions parse). name?: string; }; // Shared editor for a list of social links (label / URL / inline SVG), with // reorder + remove + add. Used by both the per-site form and the global // settings form. export function SocialLinksField({ value, onChange, name }: Props) { const move = (idx: number, delta: -1 | 1) => { const next = value.slice(); const j = idx + delta; if (j < 0 || j >= next.length) return; [next[idx], next[j]] = [next[j], next[idx]]; onChange(next); }; const update = (idx: number, patch: Partial) => onChange(value.map((row, i) => (i === idx ? { ...row, ...patch } : row))); const json = socialLinksJson(value); return ( <> {name && } {value.map((s, idx) => (
update(idx, { label: e.target.value })} placeholder="Label (e.g. GitHub)" className="rounded border border-border bg-card px-2 py-1 text-sm" /> update(idx, { url: e.target.value })} placeholder="https://…" className="rounded border border-border bg-card px-2 py-1 text-sm" />