import { useCallback, useEffect, useRef, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import { api } from "../api/client"; import { artifactsApi, jobsApi, launchpadApi, notebooksApi, sourcesApi, voiceApi } from "../api/endpoints"; import type { Artifact, CalendarItem, Job, NotebookSummary, Source } from "../api/types"; import { CheckIcon } from "../components/icons/Icons"; import { formatDate, JobProgress, StatusPill } from "../components/ui"; import { useAuth } from "../hooks/useAuth"; import { useJobMap } from "../hooks/useJob"; import { AddSource } from "./Sources"; import { PENDING_SOURCE_KEY } from "./Landing"; import { ONBOARDED_KEY } from "./Welcome"; function onboarded(): boolean { try { return localStorage.getItem(ONBOARDED_KEY) === "1"; } catch { return true; } } type Plan = { name: string }; const JOB_LABELS: Record = { ingest: "Syncing a source", import_url: "Importing an article", import_upload: "Importing a file", topics: "Mapping topics", voice_profile: "Building your voice profile", voice_clone: "Cloning your voice", resurface_scan: "Scoring evergreen posts", summary: "Writing a summary", audio_overview: "Recording an audio overview", video: "Making a video", quote_card: "Rendering a quote card", carousel: "Rendering a carousel", launch_kit: "Building a Launch Kit", render: "Rendering", }; export default function MissionControl() { const { user } = useAuth(); const [sources, setSources] = useState([]); const [notebooks, setNotebooks] = useState([]); const [recent, setRecent] = useState([]); const [upcoming, setUpcoming] = useState([]); const [plan, setPlan] = useState(null); const [hasVoice, setHasVoice] = useState(false); const [error, setError] = useState(null); const started = useRef(false); const navigate = useNavigate(); const refresh = useCallback(async () => { const [s, n, p, a, c, v] = await Promise.all([ sourcesApi.list(), notebooksApi.list(), api<{ plan: Plan }>("/api/billing/me"), artifactsApi.list({ limit: 6 }), launchpadApi.items({ start: new Date().toISOString(), status: "scheduled,draft" }), voiceApi.get(), ]); setSources(s); // First visit with nothing connected: run the guided setup once. if (s.length === 0 && !onboarded()) { navigate("/welcome", { replace: true }); return; } setNotebooks(n); setPlan(p.plan); setRecent(a.items); setUpcoming(c.slice(0, 5)); setHasVoice(Boolean(v.profile)); }, [navigate]); const { jobs, watch } = useJobMap(() => refresh()); useEffect(() => { refresh().catch(() => setError("Could not reach Mission Control. Is the API running?")); jobsApi.active().then((active) => active.forEach((j) => watch(j.id, j))); if (started.current) return; started.current = true; let pending: string | null = null; try { pending = sessionStorage.getItem(PENDING_SOURCE_KEY); sessionStorage.removeItem(PENDING_SOURCE_KEY); } catch { /* ignore */ } if (pending) { sourcesApi.connect(pending).then( (res) => { watch(res.job.id, res.job); refresh(); }, (e) => setError(e instanceof Error ? e.message : "Could not add that source."), ); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [refresh]); const totalDocs = sources.reduce((n, s) => n + s.document_count, 0); const activeJobs = Object.values(jobs).filter((j: Job) => j.status === "queued" || j.status === "running" || j.status === "failed"); const checklist = [ { done: sources.length > 0 && totalDocs > 0, label: "Connect your archive", to: "/app/sources" }, { done: hasVoice, label: "Build your voice profile", to: "/app/voice" }, { done: notebooks.length > 0, label: "Open a research notebook", to: "/app/notebooks" }, { done: recent.some((a) => a.type === "launch_kit"), label: "Make your first Launch Kit", to: "/app/launch-kit" }, { done: upcoming.length > 0, label: "Schedule a launch", to: "/app/launchpad" }, ]; return (

Mission Control

Good to see you, {(user?.name ?? user?.email ?? "").split(/[ @]/)[0]}

{plan && {plan.name} plan · early access}
{error &&

{error}

} {checklist.some((c) => !c.done) && (

Pre-flight checklist

    {checklist.map((c) => (
  1. {c.done && } {c.label}
  2. ))}
)} {activeJobs.length > 0 && (

In flight

{activeJobs.map((j) => (

{JOB_LABELS[j.kind] ?? j.kind}

))}
)}

Sources

Manage
{ setSources((list) => [...list.filter((s) => s.id !== source.id), source]); watch(job.id, job); }} />
    {sources.map((s) => (
  • {s.title ?? s.feed_url} {s.is_imports ? "imports" : s.platform} · {s.document_count} posts
  • ))} {sources.length === 0 &&
  • No sources yet. A lone satellite, waiting for signal.
  • }

Notebooks

All

{totalDocs} posts indexed across your sources.

    {notebooks.slice(0, 6).map((n) => (
  • {n.title} {n.document_count} posts
  • ))}
{notebooks.length ? "Open notebooks" : "Create a notebook"}

Recent launches

Archive
{recent.length === 0 &&

Audio overviews, videos and launch kits will show up here.

}
    {recent.map((a) => (
  • {a.title} {formatDate(a.created_at)}
  • ))}

Launchpad

Calendar
{upcoming.length === 0 &&

Nothing scheduled. Quiet moon tonight.

}
    {upcoming.map((i) => (
  • {i.platform_label} {i.content.slice(0, 70)} {formatDate(i.scheduled_at, true)}
  • ))}
); }