diff --git a/src/api/__tests__/podcast/podcast.test.ts b/src/api/__tests__/podcast/podcast.test.ts index 683501e..59451ca 100644 --- a/src/api/__tests__/podcast/podcast.test.ts +++ b/src/api/__tests__/podcast/podcast.test.ts @@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest"; import { getPodcastJobById, getPodcastJobResultById, + listPodcastJobs, podcastAudioUrl, postPodcastJob, postPodcastJobCancel, @@ -87,4 +88,28 @@ describe("podcast API", () => { it("podcastAudioUrl addresses the job's own audio door, encoded", () => { expect(podcastAudioUrl("j 1")).toBe("/api/podcast/jobs/j%201/audio"); }); + + it("listPodcastJobs asks for the whole history when no note is given", async () => { + mockFetchSuccess({ items: [], total: 0, limit: 10, offset: 0 }); + + await listPodcastJobs({ limit: 10 }); + + expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?limit=10"); + }); + + it("listPodcastJobs narrows to one note, encoded", async () => { + mockFetchSuccess({ items: [], total: 0, limit: 10, offset: 0 }); + + await listPodcastJobs({ limit: 10, sourceId: "not 1" }); + + expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?limit=10&source_id=not%201"); + }); + + it("listPodcastJobs opens the query with the note when no page is given", async () => { + mockFetchSuccess({ items: [], total: 0, limit: null, offset: 0 }); + + await listPodcastJobs({ sourceId: "cn1" }); + + expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?source_id=cn1"); + }); }); diff --git a/src/api/podcast/listPodcastJobs.ts b/src/api/podcast/listPodcastJobs.ts index 5ea30f9..c48e4b8 100644 --- a/src/api/podcast/listPodcastJobs.ts +++ b/src/api/podcast/listPodcastJobs.ts @@ -1,10 +1,22 @@ import { client, pageQuery, type Page, type PageParams, type PodcastJobSummary } from "../client"; +/** + * A history call, optionally narrowed to one course note. `sourceId` is the + * note the studio panel is open on; leaving it out asks for the whole history, + * which is what the section's "All" scope does. + */ +export type PodcastJobListParams = PageParams & { sourceId?: string }; + /** * The caller's own episodes, newest first — every job the backend ever minted * for this user, whatever state it stopped in. A reading door: it answers from * the rows alone, so it still lists the history with the service down. */ -export function listPodcastJobs(params?: PageParams, signal?: AbortSignal): Promise> { - return client>(`/podcast/jobs${pageQuery(params)}`, { signal }); +export function listPodcastJobs(params?: PodcastJobListParams, signal?: AbortSignal): Promise> { + const { sourceId, ...page } = params ?? {}; + const query = pageQuery(page); + // Absent drops the key and asks for the whole history; an empty value never + // reaches the door, since the API 400s on a present-but-empty query param. + const scope = sourceId ? `${query ? "&" : "?"}source_id=${encodeURIComponent(sourceId)}` : ""; + return client>(`/podcast/jobs${query}${scope}`, { signal }); } diff --git a/src/components/notes/podcast-history.test.tsx b/src/components/notes/podcast-history.test.tsx index 062b145..fcab128 100644 --- a/src/components/notes/podcast-history.test.tsx +++ b/src/components/notes/podcast-history.test.tsx @@ -44,17 +44,17 @@ describe("PodcastHistory", () => { vi.clearAllMocks(); }); - const renderHistory = () => + const renderHistory = (noteId?: string) => render(() => ( - + )); it("renders a finished row's title, state and duration, and plays it by job id", async () => { podcastApi.listPodcastJobs.mockResolvedValue(page([job({})])); - renderHistory(); + renderHistory("note-1"); await waitFor(() => expect(screen.getByText("Hücre")).toBeTruthy()); expect(screen.getByText("Hazır")).toBeTruthy(); @@ -70,25 +70,65 @@ describe("PodcastHistory", () => { page([job({ state: "running", duration_secs: null, finished_at: null })]), ); - renderHistory(); + renderHistory("note-1"); await waitFor(() => expect(screen.getByText("Hazırlanıyor")).toBeTruthy()); expect(screen.queryByRole("button", { name: "Bölümü oynat" })).toBeNull(); expect(document.querySelector("audio")).toBeNull(); }); + it("asks the door about the open note only", async () => { + podcastApi.listPodcastJobs.mockResolvedValue(page([job({})])); + + renderHistory("note-1"); + + await waitFor(() => + expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 10, sourceId: "note-1" }), + ); + expect(screen.getByText("Yalnızca bu notun bölümleri gösteriliyor.")).toBeTruthy(); + }); + + it("widens to the whole history when Tümü is picked", async () => { + podcastApi.listPodcastJobs.mockResolvedValue(page([job({})])); + + renderHistory("note-1"); + await waitFor(() => expect(podcastApi.listPodcastJobs).toHaveBeenCalledTimes(1)); + + fireEvent.click(screen.getByRole("button", { name: "Tümü" })); + + await waitFor(() => expect(podcastApi.listPodcastJobs).toHaveBeenCalledTimes(2)); + expect(podcastApi.listPodcastJobs).toHaveBeenLastCalledWith({ limit: 10, sourceId: undefined }); + expect(screen.getByRole("button", { name: "Tümü" }).getAttribute("aria-pressed")).toBe("true"); + expect(screen.getByRole("button", { name: "Bu not" }).getAttribute("aria-pressed")).toBe("false"); + expect(screen.getByText("Tüm notlarınızdaki bölümler gösteriliyor.")).toBeTruthy(); + }); + + it("tells an empty note apart from an empty history", async () => { + podcastApi.listPodcastJobs.mockResolvedValue(page([])); + + renderHistory("note-1"); + await waitFor(() => expect(screen.getByText("Bu not için henüz bölüm yok")).toBeTruthy()); + expect(screen.queryByText("Henüz bölüm oluşturulmadı")).toBeNull(); + + fireEvent.click(screen.getByRole("button", { name: "Tümü" })); + + await waitFor(() => expect(screen.getByText("Henüz bölüm oluşturulmadı")).toBeTruthy()); + expect(screen.queryByText("Bu not için henüz bölüm yok")).toBeNull(); + }); + it("shows the empty state when the caller has no episodes", async () => { podcastApi.listPodcastJobs.mockResolvedValue(page([])); renderHistory(); await waitFor(() => expect(screen.getByText("Henüz bölüm oluşturulmadı")).toBeTruthy()); + expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 10, sourceId: undefined }); }); it("falls back to the note id when the note is gone", async () => { podcastApi.listPodcastJobs.mockResolvedValue(page([job({ source_id: "note-gone", source_title: null })])); - renderHistory(); + renderHistory("note-1"); await waitFor(() => expect(screen.getByText("note-gone")).toBeTruthy()); }); @@ -99,7 +139,7 @@ describe("PodcastHistory", () => { render(() => ( - + )); diff --git a/src/components/notes/podcast-history.tsx b/src/components/notes/podcast-history.tsx index 79f0b53..a8c15b0 100644 --- a/src/components/notes/podcast-history.tsx +++ b/src/components/notes/podcast-history.tsx @@ -8,25 +8,39 @@ import { Button } from "@/components/ui/button"; import { EmptyInline } from "@/components/ui/empty-inline"; import { PageSpinner } from "@/components/ui/page-spinner"; import { IconWaveform } from "@/components/ui/icons"; +import { cn } from "@/lib/cn"; import { formatDate, formatDurationClock } from "@/lib/format"; import { usePreferences, useT } from "@/stores/preferences-context"; const HISTORY_PAGE_SIZE = 10; +type Scope = "note" | "all"; + /** * The caller's own episodes, under the Ses Atölyesi panel. One-directional: * the studio produces, this only reads. A finished episode plays through the * same job-id audio door the panel's own player uses. + * + * The list follows the note the panel is open on by default, so opening one + * note's studio never shows another's episodes; the header switch widens it to + * the whole history and states which of the two is on screen. */ -export function PodcastHistory(props: { active?: boolean; refetchKey?: string | number }) { +export function PodcastHistory(props: { noteId?: string; active?: boolean; refetchKey?: string | number }) { const t = useT(); const { locale } = usePreferences(); const [playing, setPlaying] = createSignal(""); + const [scope, setScope] = createSignal("note"); const active = () => props.active !== false; + // The source is the scope string, not a fresh object: an identity-stable + // value keeps the resource from refetching when nothing about it changed. const [list, { refetch }] = createResource( - () => (active() ? true : null), - () => listPodcastJobs({ limit: HISTORY_PAGE_SIZE }), + () => (active() ? (props.noteId ? scope() : "all") : null), + (current) => + listPodcastJobs({ + limit: HISTORY_PAGE_SIZE, + sourceId: current === "note" ? props.noteId : undefined, + }), ); // The panel bumps the key ("", then the job id) when a generation finishes; @@ -53,7 +67,49 @@ export function PodcastHistory(props: { active?: boolean; refetchKey?: string | return (
-

{t("podcast.history.title")}

+
+

{t("podcast.history.title")}

+ +
+ + +
+
+
+ +

+ {props.noteId && scope() === "note" + ? t("podcast.history.scope.noteCaption") + : t("podcast.history.scope.allCaption")} +

{formatApiError(list.error)} @@ -65,7 +121,11 @@ export function PodcastHistory(props: { active?: boolean; refetchKey?: string | when={jobs().length > 0} fallback={ } diff --git a/src/components/notes/podcast-panel.tsx b/src/components/notes/podcast-panel.tsx index 65afc83..5dde8c7 100644 --- a/src/components/notes/podcast-panel.tsx +++ b/src/components/notes/podcast-panel.tsx @@ -214,7 +214,11 @@ export function PodcastPanel(props: { noteId: string; active?: boolean }) { )} - + ); } diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index b150089..823cd37 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -909,8 +909,14 @@ export type MessageKey = | "podcast.history.state.failed" | "podcast.history.state.cancelled" | "podcast.history.empty" + | "podcast.history.emptyNote" | "podcast.history.emptyHint" | "podcast.history.play" + | "podcast.history.scope.label" + | "podcast.history.scope.note" + | "podcast.history.scope.all" + | "podcast.history.scope.noteCaption" + | "podcast.history.scope.allCaption" | "insights.title" | "insights.subtitle" | "insights.student" @@ -3027,8 +3033,14 @@ const en: Dict = { "podcast.history.state.failed": "Failed", "podcast.history.state.cancelled": "Cancelled", "podcast.history.empty": "No episodes created yet", + "podcast.history.emptyNote": "No episodes for this note yet", "podcast.history.emptyHint": "Episodes appear here once the studio produces one.", "podcast.history.play": "Play episode", + "podcast.history.scope.label": "Episode scope", + "podcast.history.scope.note": "This note", + "podcast.history.scope.all": "All", + "podcast.history.scope.noteCaption": "Showing this note's episodes only.", + "podcast.history.scope.allCaption": "Showing episodes from every note.", "insights.title": "Hezarfen Intelligence", "insights.subtitle": "Review student signals, recommendations, and nightly analysis runs.", "insights.student": "Student", @@ -5147,8 +5159,14 @@ const tr: Dict = { "podcast.history.state.failed": "Başarısız", "podcast.history.state.cancelled": "İptal edildi", "podcast.history.empty": "Henüz bölüm oluşturulmadı", + "podcast.history.emptyNote": "Bu not için henüz bölüm yok", "podcast.history.emptyHint": "Stüdyo bir bölüm ürettiğinde burada görünür.", "podcast.history.play": "Bölümü oynat", + "podcast.history.scope.label": "Bölüm kapsamı", + "podcast.history.scope.note": "Bu not", + "podcast.history.scope.all": "Tümü", + "podcast.history.scope.noteCaption": "Yalnızca bu notun bölümleri gösteriliyor.", + "podcast.history.scope.allCaption": "Tüm notlarınızdaki bölümler gösteriliyor.", "insights.title": "Hezarfen Zeka", "insights.subtitle": "Öğrenci sinyallerini, önerileri ve gece analizlerini inceleyin.", "insights.student": "Öğrenci",