Files
ersatztv/design-system/templates/chicorytv-admin/MultiCollections.jsx
T
timothyandClaude Opus 4.8 586b075cc1
Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 5s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 14s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m18s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 41s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m29s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m43s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 14m6s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 17m34s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
docs(404): mirror the weight UI into the MultiCollections design prototype
Design-sync back-mirror of the #404 weight UI (PR #462) into the Claude Design
prototype so repo + Claude Design stay byte-identical (docs/design-sync.md step 7).
Pushed to the ChicoryTV Design System project via DesignSync in the same session.

The prototype's EditItemRow now shows a per-source Weight input (1..1000) + computed
% share, and the editor gains a "Reset to fair share" footer — a faithful mockup of
the shipped screen. Prototype-only (design-system/), no shipped code.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 13:05:07 +02:00

307 lines
14 KiB
React
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Multi-Collections screen — a flush-row list of named groups-of-collections
// (manual + smart, each optionally "scheduled as group"), with a full-bleed
// editor pane for building one out. List + editor share the same action-bar
// shell, mirroring Channels.jsx's density.
(function () {
const NS = window.ChicoryTVDesignSystem_eb3b61;
const { Button, IconButton, Badge, Card, Input, Select, Switch, Spinner } = NS;
const Ico = window.Ico;
const mono = { fontFamily: "var(--font-mono)", fontVariantNumeric: "tabular-nums" };
const MULTI_COLLECTIONS = [
{ id: 1, name: "Prime Time Sitcoms", items: 4 },
{ id: 2, name: "Weekend Cartoon Block", items: 6 },
{ id: 3, name: "Late Night Anthology", items: 3 },
{ id: 4, name: "Holiday Specials Rotation", items: 8 },
{ id: 5, name: "80s Action Marathon", items: 2 },
{ id: 6, name: "Kids After School", items: 5 },
];
const EDIT_ITEMS = [
{ kind: "manual", name: "Friends", scheduleAsGroup: true, weight: 3 },
{ kind: "manual", name: "Seinfeld", scheduleAsGroup: true, weight: 2 },
{ kind: "manual", name: "The Office (US)", scheduleAsGroup: false, weight: 1 },
{ kind: "smart", name: "Sitcoms — Unwatched, Short", scheduleAsGroup: false, weight: 1 },
];
// Per-source weight bounds mirror the API's MultiCollectionItemWeight validator (1..1000, #404).
const WEIGHT_MIN = 1;
const WEIGHT_MAX = 1000;
const clampWeight = (raw) => {
const n = Math.trunc(Number(raw));
return Number.isFinite(n) ? Math.min(WEIGHT_MAX, Math.max(WEIGHT_MIN, n)) : WEIGHT_MIN;
};
const flushRow = (first) => ({
display: "flex",
alignItems: "center",
gap: 12,
padding: "0 var(--pad-cell-x)",
height: 52,
borderTop: first ? "none" : "1px solid var(--border-hairline)",
});
function ListRow({ mc, first, onOpen }) {
const [hover, setHover] = React.useState(false);
return (
<div
style={{ ...flushRow(first), background: hover ? "var(--ctv-surface-2)" : "transparent", transition: "background var(--dur-fast)" }}
onMouseEnter={() => setHover(true)}
onMouseLeave={() => setHover(false)}
>
<Ico n="Layers" s={15} color="var(--ctv-accent)" />
<button
type="button"
onClick={onOpen}
style={{
flex: 1,
minWidth: 0,
textAlign: "left",
background: "none",
border: "none",
padding: 0,
cursor: "pointer",
font: "var(--weight-medium) var(--text-sm)/1.3 var(--font-sans)",
color: "var(--text-primary)",
textDecoration: hover ? "underline" : "none",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{mc.name}
</button>
<Badge tone="neutral">
{mc.items} item{mc.items === 1 ? "" : "s"}
</Badge>
<IconButton size="sm" title="Delete" variant="ghost">
<Ico n="Trash2" s={14} />
</IconButton>
</div>
);
}
function EditItemRow({ item, first, weight, pct, onWeight }) {
const [checked, setChecked] = React.useState(item.scheduleAsGroup);
return (
<div style={flushRow(first)}>
<Ico n="Layers" s={15} color="var(--ctv-accent)" />
<span
style={{
flex: 1,
minWidth: 0,
font: "var(--weight-medium) var(--text-sm)/1.3 var(--font-sans)",
color: "var(--text-primary)",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
}}
>
{item.name}
</span>
<Badge tone="neutral">{item.kind === "smart" ? "Smart" : "Manual"}</Badge>
{/* Per-source weight (#404): relative share of airtime under the Weighted Shuffle order.
Bounded 1..1000 (API validator); the % is a display of the integer share (3:1 → 75/25). */}
<div style={{ display: "inline-flex", alignItems: "center", gap: 6 }} title="Relative share of airtime under the Weighted Shuffle playback order">
<span style={{ font: "var(--text-xs)/1 var(--font-sans)", color: "var(--text-secondary)" }}>Weight</span>
<input
type="number"
min={WEIGHT_MIN}
max={WEIGHT_MAX}
value={weight}
aria-label={`Weight for ${item.name}`}
onChange={(e) => onWeight(e.target.value)}
onBlur={(e) => onWeight(String(clampWeight(e.target.value)))}
style={{
width: 62,
height: 30,
padding: "0 8px",
borderRadius: "var(--radius-sm)",
border: "1px solid var(--border-hairline)",
background: "var(--ctv-bg-sunken)",
color: "var(--text-primary)",
font: "var(--text-sm)/1 var(--font-sans)",
}}
/>
<span style={{ ...mono, minWidth: 34, textAlign: "right", font: "var(--text-2xs)/1 var(--font-mono)", color: "var(--text-faint)" }}>{pct}%</span>
</div>
<label style={{ display: "inline-flex", alignItems: "center", gap: 7, cursor: "pointer" }} title="Schedule as group">
<Switch checked={checked} onChange={setChecked} size="sm" />
<span style={{ font: "var(--text-xs)/1 var(--font-sans)", color: "var(--text-secondary)", whiteSpace: "nowrap" }}>Schedule as group</span>
</label>
<IconButton size="sm" title={`Remove ${item.name}`} variant="ghost">
<Ico n="Trash2" s={14} />
</IconButton>
</div>
);
}
function EditorPane({ existing, onBack }) {
const [name, setName] = React.useState(existing ? existing.name : "");
const [colSel, setColSel] = React.useState("");
const [smartSel, setSmartSel] = React.useState("");
const items = existing ? EDIT_ITEMS : [];
// Weights are held per-item (as strings, so the number field edits smoothly); the % share is a
// display of the integer weights, and "Reset to fair share" sets every weight back to 1 (#404).
const [weights, setWeights] = React.useState(items.map((it) => String(it.weight ?? WEIGHT_MIN)));
const totalWeight = weights.reduce((s, w) => s + clampWeight(w), 0);
const pctFor = (i) => (totalWeight > 0 ? Math.round((clampWeight(weights[i]) / totalWeight) * 100) : 0);
const setWeightAt = (i, v) => setWeights((cur) => cur.map((w, j) => (j === i ? v : w)));
const alreadyFairShare = items.length > 0 && weights.every((w) => clampWeight(w) === WEIGHT_MIN);
const resetToFairShare = () => setWeights(items.map(() => String(WEIGHT_MIN)));
const collectionOptions = [
{ label: "Select a collection…", value: "" },
{ label: "Action Movies", value: "1" },
{ label: "Classic Sitcoms", value: "2" },
{ label: "Documentaries", value: "3" },
{ label: "Kids — Shorts", value: "4" },
];
const smartOptions = [
{ label: "Select a smart collection…", value: "" },
{ label: "Unwatched, Short", value: "1" },
{ label: "Recently Added (30d)", value: "2" },
];
return (
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
<div style={{ display: "flex", alignItems: "center", gap: 12, padding: "12px 20px", borderBottom: "1px solid var(--border-hairline)", flex: "0 0 auto", minHeight: 58 }}>
<Button size="sm" variant="ghost" startIcon={<Ico n="ArrowLeft" s={14} />} onClick={onBack}>
All multi-collections
</Button>
<span style={{ font: "var(--weight-medium) var(--text-sm)/1 var(--font-sans)", color: "var(--text-primary)" }}>
{existing ? "Edit multi-collection" : "New multi-collection"}
</span>
<span style={{ flex: 1 }} />
<Button size="sm" startIcon={<Ico n="Check" s={14} />}>
{existing ? "Save multi-collection" : "Add multi-collection"}
</Button>
</div>
<div style={{ flex: 1, overflow: "auto", padding: "16px 20px", display: "flex", flexDirection: "column", gap: 16, maxWidth: 720 }}>
<Card title="Multi-collection">
<Input label="Name" value={name} onChange={(e) => setName(e.target.value)} placeholder="Multi-collection name" />
<div style={{ display: "flex", alignItems: "flex-end", gap: 8, marginTop: 16 }}>
<Select label="Collections" value={colSel} onChange={(e) => setColSel(e.target.value)} options={collectionOptions} fullWidth />
<Button size="sm" variant="secondary" startIcon={<Ico n="Plus" s={14} />} disabled={colSel === ""}>
Add Collection
</Button>
</div>
<div style={{ display: "flex", alignItems: "flex-end", gap: 8, marginTop: 12 }}>
<Select label="Smart Collections" value={smartSel} onChange={(e) => setSmartSel(e.target.value)} options={smartOptions} fullWidth />
<Button size="sm" variant="secondary" startIcon={<Ico n="Plus" s={14} />} disabled={smartSel === ""}>
Add Smart Collection
</Button>
</div>
</Card>
<Card padded={false}>
{items.length === 0 ? (
<div style={{ padding: "28px 16px", textAlign: "center", font: "var(--text-sm)/1.4 var(--font-sans)", color: "var(--text-faint)" }}>
No collections added yet.
</div>
) : (
<React.Fragment>
{items.map((item, i) => (
<EditItemRow
key={item.kind + ":" + item.name}
item={item}
first={i === 0}
weight={weights[i]}
pct={pctFor(i)}
onWeight={(v) => setWeightAt(i, v)}
/>
))}
{/* fair-share footer (#404): fair-share is not a separate mode — it is Weighted Shuffle
with all weights left at 1, so this resets rather than writing a different order. */}
<div style={{ display: "flex", alignItems: "center", gap: 12, padding: "10px var(--pad-cell-x)", borderTop: "1px solid var(--border-hairline)" }}>
<span style={{ flex: 1, minWidth: 0, font: "var(--text-xs)/1.4 var(--font-sans)", color: "var(--text-secondary)" }}>
Weights set each source’s share of airtime under the <strong>Weighted Shuffle</strong> playback order (set on the schedule item). Equal weights = fair share.
</span>
<Button size="sm" variant="ghost" disabled={alreadyFairShare} onClick={resetToFairShare}>
Reset to fair share
</Button>
</div>
</React.Fragment>
)}
</Card>
</div>
</div>
);
}
function MultiCollections() {
const [editing, setEditing] = React.useState(null); // null | { kind: "new" } | { kind: "edit", item }
const [demo, setDemo] = React.useState("populated"); // populated | empty | loading — mockup state switcher
if (editing) {
return <EditorPane existing={editing.kind === "edit" ? editing.item : null} onBack={() => setEditing(null)} />;
}
if (demo === "loading") {
return (
<div style={{ display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", height: "100%", gap: 10 }}>
<Spinner size={18} />
<span style={{ font: "var(--text-sm)/1 var(--font-sans)", color: "var(--text-secondary)" }}>Loading multi-collections…</span>
</div>
);
}
const rows = demo === "empty" ? [] : MULTI_COLLECTIONS;
return (
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
<div style={{ display: "flex", alignItems: "center", gap: 12, padding: "12px 20px", borderBottom: "1px solid var(--border-hairline)", flex: "0 0 auto", minHeight: 58 }}>
<Badge tone="neutral">{rows.length} multi-collections</Badge>
<span style={{ flex: 1 }} />
{/* mockup-only state switcher — not part of the live screen */}
<div style={{ display: "inline-flex", gap: 2, padding: 2, borderRadius: "var(--radius-sm)", background: "var(--ctv-bg-sunken)", border: "1px solid var(--border-hairline)" }}>
{[{ v: "populated", l: "Populated" }, { v: "empty", l: "Empty" }, { v: "loading", l: "Loading" }].map((o) => {
const on = o.v === demo;
return (
<button
key={o.v}
type="button"
onClick={() => setDemo(o.v)}
style={{
height: 24,
padding: "0 9px",
border: "none",
borderRadius: "var(--radius-xs)",
cursor: "pointer",
background: on ? "var(--ctv-surface-3)" : "transparent",
color: on ? "var(--text-primary)" : "var(--text-secondary)",
font: `${on ? "var(--weight-medium)" : "var(--weight-normal)"} var(--text-2xs)/1 var(--font-sans)`,
}}
>
{o.l}
</button>
);
})}
</div>
<Button size="sm" startIcon={<Ico n="Plus" s={14} />} onClick={() => setEditing({ kind: "new" })}>
New multi-collection
</Button>
</div>
<div style={{ flex: 1, overflow: "auto", padding: "16px 20px" }}>
<Card padded={false}>
{rows.length === 0 ? (
<div style={{ padding: "28px 16px", textAlign: "center", font: "var(--text-sm)/1.4 var(--font-sans)", color: "var(--text-faint)" }}>
No multi-collections yet.
</div>
) : (
rows.map((mc, i) => <ListRow key={mc.id} mc={mc} first={i === 0} onOpen={() => setEditing({ kind: "edit", item: mc })} />)
)}
</Card>
</div>
</div>
);
}
window.CTVMultiCollections = MultiCollections;
})();