import { Show, Suspense, createMemo, createSignal } from "solid-js"; import { createResource } from "@/lib/create-resource"; import { getCourseNotes } from "@/api/course-notes"; import { getCourses } from "@/api/courses"; import { getMyCourses } from "@/api/reports"; import { formatApiError, type CourseNote } from "@/api/client"; import { PodcastPanel } from "@/components/notes/podcast-panel"; import { RagOutputsPanel } from "@/components/notes/rag-outputs-panel"; import { StudioOutputLibrary } from "@/components/ai/studio-output-library"; import { EmptyState } from "@/components/ui/empty-state"; import { ErrorAlert } from "@/components/ui/error-alert"; import { Label } from "@/components/ui/label"; import { PageSpinner } from "@/components/ui/page-spinner"; import { SearchableSelect } from "@/components/ui/searchable-select"; import { useAuth } from "@/stores/auth-context"; import { useT } from "@/stores/preferences-context"; import { courseNoteFiles } from "@/lib/note-source"; import { hasMinRole } from "@/lib/roles"; type StudioNote = CourseNote & { courseTitle: string; courseCreatorId: string }; /** Pick a lesson note, then read its AI outputs and produce its podcast — * the same two panels the note reader shows, gathered on the AI hub. */ export function NoteStudioPanel() { const t = useT(); const auth = useAuth(); const [selectedId, setSelectedId] = createSignal(""); let outputsSection: HTMLElement | undefined; const [notes, { refetch }] = createResource( () => auth.user()?.role ?? null, async (role) => { const courses = role === "student" ? await getMyCourses({ limit: 100 }) : await getCourses({ limit: 100 }); const rows = await Promise.all( courses.items.map(async (course) => { try { const page = await getCourseNotes(course.id, { limit: 100 }); return page.items.map((note) => ({ ...note, courseTitle: course.title, courseCreatorId: course.creator.id, })); } catch { return []; } }), ); return rows.flat(); }, ); const options = createMemo(() => (notes() ?? []).map((note) => ({ value: note.id, label: `${note.courseTitle} · ${note.title}` }))); const selected = createMemo(() => (notes() ?? []).find((note) => note.id === selectedId()) ?? null); const canManageSelected = () => { const note = selected(); const user = auth.user(); return !!note && !!user && (hasMinRole(user.role, "manager") || note.courseCreatorId === user.id); }; const selectLibraryNote = (noteId: string) => { setSelectedId(noteId); requestAnimationFrame(() => outputsSection?.scrollIntoView({ behavior: "smooth", block: "start" })); }; return ( }> void refetch()} /> 0} fallback={} > {/* Laid out the way a studio home reads: a plain title and one line saying what it makes, the source picker, the producers, then everything produced so far. Flat hairline cards, no banner and no shadow stack — the work is the content, not the chrome. */}

{t("aiHub.tab.studio")}

{t("aiStudio.heading")}

{t("aiStudio.pickPrompt")}

{t("aiStudio.pickPromptHint")}

} > {(note) => (

{note().title}

{note().courseTitle}
)}
{/* The library is the landing view. Once a note is open the page is about producing for that note, so the list of everything else steps out of the way. */} ({ id: note.id, title: note.title, courseTitle: note.courseTitle }))} selectedId={selectedId()} onSelect={selectLibraryNote} />
); }