import { useRef, useState } from "react"; import { SAMPLE_COMMENTS } from "../api"; import type { Health } from "../types"; type Tab = "youtube" | "paste" | "file" | "facebook"; export type Submit = | { kind: "youtube"; url: string; limit: number; order: "relevance" | "time" } | { kind: "paste"; texts: string[] } | { kind: "file"; file: File }; const TABS: { id: Tab; label: string }[] = [ { id: "youtube", label: "YouTube link" }, { id: "paste", label: "Paste text" }, { id: "file", label: "CSV / Excel" }, { id: "facebook", label: "Facebook Page" }, ]; export function InputPanel({ health, busy, onSubmit }: { health: Health | null; busy: boolean; onSubmit: (s: Submit) => void }) { const [tab, setTab] = useState("youtube"); const [url, setUrl] = useState(""); const [limit, setLimit] = useState(500); const [order, setOrder] = useState<"relevance" | "time">("relevance"); const [text, setText] = useState(""); const [file, setFile] = useState(null); const [drag, setDrag] = useState(false); const fileRef = useRef(null); const lines = text.split(/\r?\n/).map((l) => l.trim()).filter(Boolean); const ytReady = health?.youtube_enabled !== false; const canSubmit = !busy && ((tab === "youtube" && !!url.trim() && ytReady) || (tab === "paste" && lines.length > 0) || (tab === "file" && !!file)); const submit = (e: React.FormEvent) => { e.preventDefault(); if (!canSubmit) return; if (tab === "youtube") onSubmit({ kind: "youtube", url: url.trim(), limit, order }); else if (tab === "paste") onSubmit({ kind: "paste", texts: lines }); else if (file) onSubmit({ kind: "file", file }); }; return (
{TABS.map(({ id, label }) => ( ))}
{tab === "youtube" && (
setUrl(e.target.value)} inputMode="url" autoComplete="off" placeholder="https://www.youtube.com/watch?v=…" className="field h-11 px-3" />
≈ {Math.max(5, Math.round(limit / 100 + limit / 250))} s
{!ytReady && (

YouTube is not configured on this server. Add YOUTUBE_API_KEY to backend/.env and restart. You can still .

)}
)} {tab === "paste" && (