"use client"; // A FORUM THREAD'S SESSION — its host's profile state and Connect, which opens // that profile in a window on the machine running the editor, at the thread // (connectForumSessionAction). Drawn by the channel page's forum panel // (SocialChannelPanel, with its retry and import controls below it) and by the // /cookies screen's forum row, one per thread channel on the host: one // component, so the two places cannot drift. import { useState, useTransition } from "react"; import type { ForumSessionStatus } from "yt-dlp-transcript-common/social/forumSession"; import { connectForumSessionAction } from "../socialActions"; export function forumSessionLine(s: ForumSessionStatus | undefined): string { return s?.lastConnect ? `${s.host}: connected ${new Date(s.lastConnect.connectedAt).toLocaleString()}` + (s.lastConnect.cleared ? "" : " (the thread did not show)") : s?.hasProfile ? `${s.host}: profile in use, never connected by hand` : `${s?.host ?? "this forum"}: no profile yet`; } export function ForumSessionConnect({ slug, status, onChange, }: { slug: string; status?: ForumSessionStatus; // Told after a Connect ends (the /cookies screen re-reads its row). onChange?: () => void; }) { const [session, setSession] = useState(status); const [note, setNote] = useState(null); const [err, setErr] = useState(null); const [pending, start] = useTransition(); const connect = () => start(async () => { setNote(null); setErr(null); const res = await connectForumSessionAction(slug); if (res.ok) { if (session) setSession({ ...session, hasProfile: true, lastConnect: res.record }); setNote( res.record.cleared ? "Connected: the thread showed before the window closed. Fetch again." : "The window closed before a thread page showed; the profile kept what it had.", ); } else { setErr(res.error); } onChange?.(); }); return ( <>

Forum session

{forumSessionLine(session)}

The fetcher reads the thread in a headless browser that keeps one profile per forum host, so a browser check it clears once (Kiwi Farms' KiwiFlare, say) stays cleared. When a check will not clear by itself, or the thread needs a login, Connect opens that profile in a window on the machine running the editor, at the thread: clear it (or log in), wait for the thread to show, then close the window.

{note && (

{note}

)} {err && (

{err}

)} ); }