From c923286e3fdee822637a7f30569cc28d43e72024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Wed, 23 Sep 2026 07:20:21 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20studio=20library=20rows=20o?= =?UTF-8?q?pen=20their=20own=20note=20page=20-=20new=20route=20/ai/studio/?= =?UTF-8?q?$noteId=20(search:=20episode)=20for=20one=20note's=20summary=20?= =?UTF-8?q?=20=20and=20episodes;=20the=20landing=20page=20keeps=20the=20ti?= =?UTF-8?q?tle,=20note=20picker=20and=20library=20-=20picking=20a=20note?= =?UTF-8?q?=20or=20a=20library=20row=20navigates=20there=20instead=20of=20?= =?UTF-8?q?opening=20the=20=20=20note=20in=20place;=20an=20episode=20row?= =?UTF-8?q?=20opens=20its=20note=20page=20with=20that=20episode=20=20=20lo?= =?UTF-8?q?aded=20in=20the=20player=20-=20the=20note=20page=20has=20no=20p?= =?UTF-8?q?icker=20or=20library,=20only=20a=20"Kitapl=C4=B1=C4=9Fa=20d?= =?UTF-8?q?=C3=B6n"=20link=20back=20-=20the=20run=20inspector=20side=20pan?= =?UTF-8?q?el=20is=20removed=20with=20its=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ai/note-studio-panel.tsx | 208 +++++++++--------- .../ai/studio-output-library.test.tsx | 8 +- src/components/ai/studio-output-library.tsx | 20 +- src/components/ai/studio-run-inspector.tsx | 89 -------- src/components/notes/podcast-history.tsx | 4 +- src/components/notes/podcast-panel.tsx | 3 +- src/i18n/locales/en.ts | 5 - src/i18n/locales/tr.ts | 5 - src/i18n/messages.ts | 5 - src/pages/ai-studio-note-page.tsx | 13 ++ src/routes/router.tsx | 12 + 11 files changed, 145 insertions(+), 227 deletions(-) delete mode 100644 src/components/ai/studio-run-inspector.tsx create mode 100644 src/pages/ai-studio-note-page.tsx diff --git a/src/components/ai/note-studio-panel.tsx b/src/components/ai/note-studio-panel.tsx index 2cfb26c..ad5c7d2 100644 --- a/src/components/ai/note-studio-panel.tsx +++ b/src/components/ai/note-studio-panel.tsx @@ -1,13 +1,15 @@ -import { Show, Suspense, createMemo, createSignal } from "solid-js"; +import { Show, Suspense, createMemo } from "solid-js"; +import { Link, useNavigate } from "@tanstack/solid-router"; 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 { formatApiError, type CourseNote, type Role } 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 { Button } from "@/components/ui/button"; +import { RecordNotFound } from "@/components/layout/record-not-found"; +import { buttonVariants } from "@/components/ui/button"; import { EmptyState } from "@/components/ui/empty-state"; import { ErrorAlert } from "@/components/ui/error-alert"; import { IconChevronLeft } from "@/components/ui/icons"; @@ -22,44 +24,44 @@ 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. */ +/** Every lesson note the account can produce from, with its course. */ +async function loadStudioNotes(role: Role): Promise { + 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(); +} + +function useStudioNotes() { + const auth = useAuth(); + return createResource(() => auth.user()?.role ?? null, loadStudioNotes); +} + +/** + * The studio's landing page: what it makes, a picker to start on any note, + * and the library of everything produced so far. Picking a note or a row + * opens that note's own page (`/ai/studio/$noteId`); nothing opens in place. + */ 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 navigate = useNavigate(); + const [notes, { refetch }] = useStudioNotes(); 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" })); + const open = (noteId: string, episode?: string) => { + if (!noteId) return; + void navigate({ to: "/ai/studio/$noteId", params: { noteId }, search: { episode } }); }; return ( @@ -72,14 +74,11 @@ export function NoteStudioPanel() { when={(notes()?.length ?? 0) > 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. */} + {/* A studio home: a plain title and one line saying what it makes, + the way to start on a note, then everything produced so far. + Flat hairline cards, no banner and no shadow stack. */}
- {/* On a phone an open note needs the screen more than the page - title does; the picker below still says where you are. */} -
+

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

{t("aiStudio.heading")}

@@ -89,70 +88,77 @@ export function NoteStudioPanel() { open(noteId)} options={options()} placeholder={t("podcast.selectNote")} />
- -

{t("aiStudio.pickPrompt")}

-

{t("aiStudio.pickPromptHint")}

- - } - > - {(note) => ( -
- {/* The library steps aside while a note is open; this is the - way back to it without emptying the picker by hand. */} -
- -
-

{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} - /> - + ({ id: note.id, title: note.title, courseTitle: note.courseTitle }))} + selectedId="" + onSelect={open} + /> ); } + +/** + * One note's studio page: its summary and its episodes, nothing else — no + * picker, no library. "Kitaplığa dön" is the way back. `episode` preselects + * an episode opened from the library. + */ +export function NoteStudioDetail(props: { noteId: string; episode?: string }) { + const t = useT(); + const auth = useAuth(); + const [notes, { refetch }] = useStudioNotes(); + const note = createMemo(() => (notes() ?? []).find((row) => row.id === props.noteId) ?? null); + const canManage = () => { + const current = note(); + const user = auth.user(); + return !!current && !!user && (hasMinRole(user.role, "manager") || current.courseCreatorId === user.id); + }; + + return ( + }> + + void refetch()} /> + + + }> + {(current) => ( +
+
+ + + {t("aiStudio.backToLibrary")} + +
+

{current().title}

+

{current().courseTitle}

+
+
+
+ + +
+
+ )} +
+
+
+ ); +} diff --git a/src/components/ai/studio-output-library.test.tsx b/src/components/ai/studio-output-library.test.tsx index 7d6bae1..0806539 100644 --- a/src/components/ai/studio-output-library.test.tsx +++ b/src/components/ai/studio-output-library.test.tsx @@ -120,14 +120,13 @@ describe("StudioOutputLibrary", () => { expect(screen.queryByText("Bölüm 12")).toBeNull(); }); - it("opens the run inspector for an episode instead of selecting its note", async () => { + it("opens an episode's note page with that episode picked", async () => { const onSelect = renderLibrary(); await waitFor(() => expect(screen.getAllByText("Hücre").length).toBe(2)); fireEvent.click(screen.getAllByRole("button", { name: /Hücre/ })[0]!); - await waitFor(() => expect(screen.getByText("Üretim ayrıntısı")).toBeTruthy()); - expect(onSelect).not.toHaveBeenCalled(); + expect(onSelect).toHaveBeenCalledWith("note-1", expect.any(String)); }); it("opens the note for a summary row, which has no artifact of its own", async () => { @@ -136,7 +135,6 @@ describe("StudioOutputLibrary", () => { await waitFor(() => expect(screen.getByText("Kuvvet")).toBeTruthy()); fireEvent.click(screen.getByRole("button", { name: /Kuvvet/ })); - expect(onSelect).toHaveBeenCalledWith("note-2"); - expect(screen.queryByText("Üretim ayrıntısı")).toBeNull(); + expect(onSelect).toHaveBeenCalledWith("note-2", undefined); }); }); diff --git a/src/components/ai/studio-output-library.tsx b/src/components/ai/studio-output-library.tsx index 288e455..0ba48ce 100644 --- a/src/components/ai/studio-output-library.tsx +++ b/src/components/ai/studio-output-library.tsx @@ -3,7 +3,6 @@ import { createResource } from "@/lib/create-resource"; import { getCourseNoteRag } from "@/api/course-notes"; import { listPodcastJobs } from "@/api/podcast"; import type { PodcastJobSummary } from "@/api/client"; -import { StudioRunInspector } from "@/components/ai/studio-run-inspector"; import { Badge } from "@/components/ui/badge"; import { EmptyInline } from "@/components/ui/empty-inline"; import { IconSparkles, IconWaveform } from "@/components/ui/icons"; @@ -41,11 +40,11 @@ const LIBRARY_PAGE_SIZE = 10; export function StudioOutputLibrary(props: { notes: StudioLibraryNote[]; selectedId: string; - onSelect: (noteId: string) => void; + /** Opens the row's own page: the note, with the episode picked for a podcast row. */ + onSelect: (noteId: string, episodeId?: string) => void; }) { const t = useT(); const { locale } = usePreferences(); - const [inspecting, setInspecting] = createSignal(null); const source = createMemo(() => props.notes.map((note) => note.id).join(",")); const stateVariant = (state: string) => { @@ -131,10 +130,9 @@ export function StudioOutputLibrary(props: { }); const open = (item: StudioArtifact) => { - // A produced episode has an artifact of its own to inspect; a summary is - // rendered by the note's own producer panel, so that row opens the note. - if (item.job) setInspecting(item.job); - else props.onSelect(item.noteId); + // Every row opens a page of its own; an episode opens its note's page + // with that episode loaded in the player. + props.onSelect(item.noteId, item.job?.job_id); }; return ( @@ -232,14 +230,6 @@ export function StudioOutputLibrary(props: { - { if (!next) setInspecting(null); }} - formatLabel={formatLabel} - stateLabel={stateLabel} - stateVariant={stateVariant} - title={t("aiStudio.run.title")} - /> ); } diff --git a/src/components/ai/studio-run-inspector.tsx b/src/components/ai/studio-run-inspector.tsx deleted file mode 100644 index d11a300..0000000 --- a/src/components/ai/studio-run-inspector.tsx +++ /dev/null @@ -1,89 +0,0 @@ -import { Show } from "solid-js"; -import type { PodcastJobSummary } from "@/api/client"; -import { PodcastPlayer } from "@/components/notes/podcast-player"; -import { Alert } from "@/components/ui/alert"; -import { Badge } from "@/components/ui/badge"; -import { SidePanel } from "@/components/ui/side-panel"; -import { formatDateTime, formatDurationClock } from "@/lib/format"; -import { usePreferences, useT } from "@/stores/preferences-context"; - -/** One label/value line of run metadata. */ -function MetaRow(props: { label: string; value: string }) { - return ( -
-
{props.label}
-
{props.value}
-
- ); -} - -/** - * One produced episode, opened from the studio library. - * - * Everything here comes off the job row the list already holds — state, the - * narration the service settled on, when it started and finished, how long the - * audio runs — plus the audio door, which is addressed by job id. A job that - * never finished has no player, and says why instead. - */ -export function StudioRunInspector(props: { - job: PodcastJobSummary | null; - onOpenChange: (open: boolean) => void; - /** Resolves the narration's label; unknown formats come back verbatim. */ - formatLabel: (format: string | null) => string; - stateLabel: (state: string) => string; - stateVariant: (state: string) => "success" | "destructive" | "secondary" | "warning"; - title: string; -}) { - const t = useT(); - const { locale } = usePreferences(); - const job = () => props.job; - const sourceName = () => job()?.source_title ?? job()?.source_id ?? ""; - - return ( - - - {(row) => ( -
-
- {props.stateLabel(row().state)} - - {(label) => {label()}} - -
- -
- - - - - - - - -
- - - {(code) => {code()}} - - - {t("podcast.history.emptyHint")}

} - > - -
-
- )} -
-
- ); -} diff --git a/src/components/notes/podcast-history.tsx b/src/components/notes/podcast-history.tsx index 4880e08..80cc1c5 100644 --- a/src/components/notes/podcast-history.tsx +++ b/src/components/notes/podcast-history.tsx @@ -40,6 +40,8 @@ export function PodcastHistory(props: { noteId?: string; active?: boolean; refetchKey?: string | number; + /** An episode to open with, e.g. one picked in the studio library. */ + episode?: string; /** The transcript of the episode the panel just produced, if the service sent one. */ transcript?: { jobId: string; segments: PodcastTranscriptSegment[] } | null; }) { @@ -56,7 +58,7 @@ export function PodcastHistory(props: { props.noteId; pageSize(); setPage(0); - setSelected(""); + setSelected(props.episode ?? ""); setAutoplay(false); }); diff --git a/src/components/notes/podcast-panel.tsx b/src/components/notes/podcast-panel.tsx index c013eb3..55a3cd1 100644 --- a/src/components/notes/podcast-panel.tsx +++ b/src/components/notes/podcast-panel.tsx @@ -15,7 +15,7 @@ import { useT } from "@/stores/preferences-context"; const POLL_MS = 2_000; -export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitle?: string }) { +export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitle?: string; episode?: string }) { const t = useT(); const [format, setFormat] = createSignal("duz_okuma"); const [jobId, setJobId] = createSignal(""); @@ -241,6 +241,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl + + + ); +} diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 790bc42..3e505a9 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -74,6 +74,7 @@ const PaymentStatementPage = lazyRoute(() => import("@/pages/payment-statement-p const WhiteboardsPage = lazyRoute(() => import("@/pages/whiteboards-page")); const WhiteboardPage = lazyRoute(() => import("@/pages/whiteboard-page")); const AiStudioPage = lazyRoute(() => import("@/pages/ai-studio-page")); +const AiStudioNotePage = lazyRoute(() => import("@/pages/ai-studio-note-page")); const AiStudyPage = lazyRoute(() => import("@/pages/ai-study-page")); const AiInsightsPage = lazyRoute(() => import("@/pages/ai-insights-page")); const AiInsightStudentPage = lazyRoute(() => import("@/pages/ai-insight-student-page")); @@ -477,6 +478,16 @@ const aiStudioRoute = createRoute({ component: AiStudioPage, }); +// One note's studio page; `episode` preselects an episode from the library. +const aiStudioNoteRoute = createRoute({ + getParentRoute: () => rootRoute, + path: "/ai/studio/$noteId", + validateSearch: (search: Record) => ({ + episode: typeof search.episode === "string" && search.episode ? search.episode : undefined, + }), + component: AiStudioNotePage, +}); + const aiStudyRoute = createRoute({ getParentRoute: () => rootRoute, path: "/ai/study", @@ -624,6 +635,7 @@ const routeTree = rootRoute.addChildren([ whiteboardRoute, aiRoute, aiStudioRoute, + aiStudioNoteRoute, aiStudyRoute, aiInsightsRoute, aiInsightStudentRoute,