From d6275aab4c5bf8cecf44147375229640d7fe2629 Mon Sep 17 00:00:00 2001 From: pedro-bento Date: Tue, 6 Oct 2026 11:57:27 +0100 Subject: [PATCH] feat(dashboard): add Channels tab to manage channel profiles New Channels section backed by the /api/channels CRUD API: - list rail plus a full editor for every profile field - chip inputs for string lists, reorderable thumbnail role order, presenter toggle - create/update/delete with inline confirm and server-error surfacing - JSON import/export (all profiles or one), with per-item import failures - responsive two-column layout in the app's design language Renumbers Settings to 04 and adds channels to the deep-link tabs. --- dashboard/src/App.jsx | 13 +- dashboard/src/components/ChannelProfiles.jsx | 1030 ++++++++++++++++++ 2 files changed, 1039 insertions(+), 4 deletions(-) create mode 100644 dashboard/src/components/ChannelProfiles.jsx diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 44a7c9c..502a97a 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -1,10 +1,11 @@ import React, { useState, useEffect, useRef, useMemo } from 'react'; -import { Youtube, Instagram, Share2, ChevronDown, Check, Activity, LayoutDashboard, Settings, Plus, X, Terminal, Shield, Image, RotateCcw, AlertTriangle, KeyRound, ExternalLink, Mail, Loader2, Download, Menu, Lock } from 'lucide-react'; +import { Youtube, Instagram, Share2, ChevronDown, Check, Activity, LayoutDashboard, Settings, Plus, X, Terminal, Shield, Image, Radio, RotateCcw, AlertTriangle, KeyRound, ExternalLink, Mail, Loader2, Download, Menu, Lock } from 'lucide-react'; import KeyInput from './components/KeyInput'; import MediaInput from './components/MediaInput'; import ResultCard from './components/ResultCard'; import ProcessingAnimation from './components/ProcessingAnimation'; import ThumbnailStudio from './components/ThumbnailStudio'; +import ChannelProfiles from './components/ChannelProfiles'; import ClipEditor from './components/ClipEditor'; import ReframeEditor from './components/ReframeEditor'; import StarBanner from './components/StarBanner'; @@ -575,7 +576,7 @@ function App() { // Read once per hash change, then the query is dropped so a reload does not // keep forcing the tab. useEffect(() => { - const DEEP_LINK_TABS = ['settings', 'thumbnails', 'dashboard']; + const DEEP_LINK_TABS = ['settings', 'thumbnails', 'channels', 'dashboard']; const apply = () => { const hash = window.location.hash || ''; if (!hash.startsWith('#app?')) return; @@ -810,7 +811,8 @@ function App() { const navItems = [ { id: 'dashboard', ord: '01', icon: LayoutDashboard, label: 'Clip Generator', short: 'clips', primary: true }, { id: 'thumbnails', ord: '02', icon: Image, label: 'YouTube Studio', short: 'studio', primary: true }, - { id: 'settings', ord: '03', icon: Settings, label: 'Settings', short: 'settings' }, + { id: 'channels', ord: '03', icon: Radio, label: 'Channels', short: 'channels' }, + { id: 'settings', ord: '04', icon: Settings, label: 'Settings', short: 'settings' }, ]; const activeNav = navItems.find((n) => n.id === activeTab); @@ -1102,12 +1104,15 @@ function App() { {/* Main Workspace */}
+ {/* View: Channels */} + {activeTab === 'channels' && } + {/* View: Settings */} {activeTab === 'settings' && (
-

03 · SETTINGS

+

04 · SETTINGS

Settings

diff --git a/dashboard/src/components/ChannelProfiles.jsx b/dashboard/src/components/ChannelProfiles.jsx new file mode 100644 index 0000000..2766867 --- /dev/null +++ b/dashboard/src/components/ChannelProfiles.jsx @@ -0,0 +1,1030 @@ +import { useCallback, useEffect, useRef, useState } from 'react'; +import { + AlertCircle, ArrowDown, ArrowUp, Check, ChevronDown, Download, + Loader2, Plus, Radio, Save, Trash2, Upload, X, +} from 'lucide-react'; +import { apiFetch, apiJson } from '../lib/api'; + +// Channel profiles (PLAN #1): one channel's packaging rules — the title +// constraints, hook patterns and thumbnail direction the pipeline reads. This +// panel is the CRUD surface over /api/channels; the backend owns validation, +// this only does enough up front to catch an obviously bad slug. + +// Enum mirrors the backend schema (clipwright/pipeline/profiles.py), kept in +// display order rather than sorted so the picker reads the way it is written. +const KEYWORD_POSITIONS = ['start', 'middle', 'end', 'any']; +const NUMBER_POLICIES = ['allow', 'avoid', 'require']; +const REQUIRED_SIGNALS = ['consequence', 'curiosity', 'either', 'none']; +const THUMBNAIL_ROLES = ['curiosity', 'emotion', 'technical']; + +// Same slug contract as the server: no separators, no traversal segments. +const SLUG_RE = /^[A-Za-z0-9][A-Za-z0-9_-]*$/; + +// A fresh profile. A function, not a constant, so nested arrays are never +// shared between two opens of the form. +const emptyForm = () => ({ + slug: '', + name: '', + language: 'en', + tone: '', + title_rules: { + max_chars: 70, + mobile_chars: 40, + banned_patterns: [], + keyword_position: 'start', + number_policy: 'allow', + required_signal: 'either', + banned_openers: [], + }, + hook_patterns: [], + hook_style: '', + description_template: '', + links: [], + thumbnail: { + role_order: ['curiosity', 'emotion', 'technical'], + palette: [], + presenter_photo: false, + }, + default_postiz_integration_id: '', + published_video_history: [], +}); + +// Backend profile -> editable form state. Every field is defaulted so a +// partially-specified profile (the schema makes them all optional) still +// renders a complete form. +const profileToForm = (data) => { + const t = data?.title_rules || {}; + const th = data?.thumbnail || {}; + return { + slug: data?.slug || '', + name: data?.name ?? '', + language: data?.language ?? 'en', + tone: data?.tone ?? '', + title_rules: { + max_chars: t.max_chars ?? 70, + mobile_chars: t.mobile_chars ?? 40, + banned_patterns: Array.isArray(t.banned_patterns) ? t.banned_patterns : [], + keyword_position: t.keyword_position || 'start', + number_policy: t.number_policy || 'allow', + required_signal: t.required_signal || 'either', + banned_openers: Array.isArray(t.banned_openers) ? t.banned_openers : [], + }, + hook_patterns: Array.isArray(data?.hook_patterns) ? data.hook_patterns : [], + hook_style: data?.hook_style ?? '', + description_template: data?.description_template ?? '', + links: Array.isArray(data?.links) ? data.links : [], + thumbnail: { + role_order: Array.isArray(th.role_order) && th.role_order.length + ? th.role_order + : ['curiosity', 'emotion', 'technical'], + palette: Array.isArray(th.palette) ? th.palette : [], + presenter_photo: !!th.presenter_photo, + }, + default_postiz_integration_id: data?.default_postiz_integration_id ?? '', + // Held verbatim: the panel never edits history, but a save must not + // drop it. + published_video_history: Array.isArray(data?.published_video_history) + ? data.published_video_history + : [], + }; +}; + +const toInt = (value, fallback) => { + const n = typeof value === 'number' ? value : parseInt(String(value).trim(), 10); + return Number.isFinite(n) ? n : fallback; +}; + +// Form state -> PUT/POST body. `slug` is handled by the caller: it is part of +// the create body only and never sent on update. +const formToPayload = (form) => ({ + name: form.name.trim(), + language: form.language.trim() || 'en', + tone: form.tone, + title_rules: { + max_chars: toInt(form.title_rules.max_chars, 70), + mobile_chars: toInt(form.title_rules.mobile_chars, 40), + banned_patterns: form.title_rules.banned_patterns, + keyword_position: form.title_rules.keyword_position, + number_policy: form.title_rules.number_policy, + required_signal: form.title_rules.required_signal, + banned_openers: form.title_rules.banned_openers, + }, + hook_patterns: form.hook_patterns, + hook_style: form.hook_style, + description_template: form.description_template, + links: form.links, + thumbnail: { + role_order: form.thumbnail.role_order, + palette: form.thumbnail.palette, + presenter_photo: !!form.thumbnail.presenter_photo, + }, + default_postiz_integration_id: form.default_postiz_integration_id.trim() || null, + published_video_history: form.published_video_history, +}); + +// Prefer the server's own explanation (FastAPI {"detail": "..."}) over a +// generic fallback, same convention as the rest of the app. +const errText = (err, fallback) => err?.detail || err?.message || fallback; + +const Field = ({ label, hint, className = '', children }) => ( +
+

{label}

+ {children} + {hint &&

{hint}

} +
+); + +// Numbered rule-of-thirds section: a mono ordinal, a label, then a hairline +// running to the edge. Breaks a long spec sheet into something scannable. +const Section = ({ n, title, children }) => ( +
+
+ {n} +

{title}

+
+ {children} +
+); + +// Chip input for every string-list field. Enter commits, Backspace on an empty +// draft removes the last chip, blur commits whatever is typed. +function TagInput({ values, onChange, placeholder = 'type and press enter' }) { + const [draft, setDraft] = useState(''); + + const commit = () => { + const v = draft.trim(); + if (!v) return; + if (!values.includes(v)) onChange([...values, v]); + setDraft(''); + }; + + return ( +
+ {values.map((v) => ( + + {v} + + + ))} + setDraft(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { e.preventDefault(); commit(); } + else if (e.key === 'Backspace' && !draft && values.length) { + onChange(values.slice(0, -1)); + } + }} + onBlur={commit} + placeholder={values.length ? '' : placeholder} + className="flex-1 min-w-[7rem] bg-transparent px-1.5 py-1 text-sm text-ink2 placeholder:text-muted/70 outline-none" + /> +
+ ); +} + +// Ordered list of thumbnail concept roles: reorder with the arrows, drop or +// re-add with the x / + controls. +function RoleOrderField({ value, onMove, onToggle }) { + const ordered = Array.isArray(value) ? value : []; + const missing = THUMBNAIL_ROLES.filter((r) => !ordered.includes(r)); + + return ( +
+
    + {ordered.map((role, i) => ( +
  • + {i + 1} + {role} + + + +
  • + ))} +
+ {missing.length > 0 && ( +
+ {missing.map((role) => ( + + ))} +
+ )} + {ordered.length === 0 && ( +

Add at least one role so thumbnails have a concept to follow.

+ )} +
+ ); +} + +// The app's standard pill switch (same markup as the subtitle editor). +function Toggle({ checked, onChange, label, hint }) { + return ( + + ); +} + +function EditorSkeleton() { + return ( +