forge
Explore
Log in

Don't you dare go Hollow

Scope the episode history to the open note

Browse files at this commit

d5ffe71c18b1510c0364d5780b4e84c61b461136Ahmet Kaan GümüşParent: bd81b90
  • feat
    • scope the episode history to the open note
Show full message
🎧 feat(podcast): scope the episode history to the open note

The section lived inside the note-scoped studio panel but listed every note's jobs, so picking another note looked like it kept the same results. It now asks the door for the open note's jobs and carries a `Bu not` / `Tümü` switch that widens to the whole history, with a caption naming the scope on screen and a scope-aware empty state.

`listPodcastJobs` gains an optional `sourceId`, appended url-encoded only when given; absent keeps today's query byte for byte.
src/api/__tests__/podcast/podcast.test.tsmodified+25 -0
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
2 import {2 import {
3 getPodcastJobById,3 getPodcastJobById,
4 getPodcastJobResultById,4 getPodcastJobResultById,
5+ listPodcastJobs,
5 podcastAudioUrl,6 podcastAudioUrl,
6 postPodcastJob,7 postPodcastJob,
7 postPodcastJobCancel,8 postPodcastJobCancel,
@@ -87,4 +88,28 @@ describe("podcast API", () => {
87 it("podcastAudioUrl addresses the job's own audio door, encoded", () => {88 it("podcastAudioUrl addresses the job's own audio door, encoded", () => {
88 expect(podcastAudioUrl("j 1")).toBe("/api/podcast/jobs/j%201/audio");89 expect(podcastAudioUrl("j 1")).toBe("/api/podcast/jobs/j%201/audio");
89 });90 });
91+
92+ it("listPodcastJobs asks for the whole history when no note is given", async () => {
93+ mockFetchSuccess({ items: [], total: 0, limit: 10, offset: 0 });
94+
95+ await listPodcastJobs({ limit: 10 });
96+
97+ expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?limit=10");
98+ });
99+
100+ it("listPodcastJobs narrows to one note, encoded", async () => {
101+ mockFetchSuccess({ items: [], total: 0, limit: 10, offset: 0 });
102+
103+ await listPodcastJobs({ limit: 10, sourceId: "not 1" });
104+
105+ expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?limit=10&source_id=not%201");
106+ });
107+
108+ it("listPodcastJobs opens the query with the note when no page is given", async () => {
109+ mockFetchSuccess({ items: [], total: 0, limit: null, offset: 0 });
110+
111+ await listPodcastJobs({ sourceId: "cn1" });
112+
113+ expect(lastFetchCall()[0]).toBe("/api/podcast/jobs?source_id=cn1");
114+ });
90 });115 });
src/api/podcast/listPodcastJobs.tsmodified+14 -2
@@ -1,10 +1,22 @@
1 import { client, pageQuery, type Page, type PageParams, type PodcastJobSummary } from "../client";1 import { client, pageQuery, type Page, type PageParams, type PodcastJobSummary } from "../client";
2 2
3+/**
4+ * A history call, optionally narrowed to one course note. `sourceId` is the
5+ * note the studio panel is open on; leaving it out asks for the whole history,
6+ * which is what the section's "All" scope does.
7+ */
8+export type PodcastJobListParams = PageParams & { sourceId?: string };
9+
3 /**10 /**
4 * The caller's own episodes, newest first — every job the backend ever minted11 * The caller's own episodes, newest first — every job the backend ever minted
5 * for this user, whatever state it stopped in. A reading door: it answers from12 * for this user, whatever state it stopped in. A reading door: it answers from
6 * the rows alone, so it still lists the history with the service down.13 * the rows alone, so it still lists the history with the service down.
7 */14 */
8-export function listPodcastJobs(params?: PageParams, signal?: AbortSignal): Promise<Page<PodcastJobSummary>> {15+export function listPodcastJobs(params?: PodcastJobListParams, signal?: AbortSignal): Promise<Page<PodcastJobSummary>> {
9- return client<Page<PodcastJobSummary>>(`/podcast/jobs${pageQuery(params)}`, { signal });16+ const { sourceId, ...page } = params ?? {};
17+ const query = pageQuery(page);
18+ // Absent drops the key and asks for the whole history; an empty value never
19+ // reaches the door, since the API 400s on a present-but-empty query param.
20+ const scope = sourceId ? `${query ? "&" : "?"}source_id=${encodeURIComponent(sourceId)}` : "";
21+ return client<Page<PodcastJobSummary>>(`/podcast/jobs${query}${scope}`, { signal });
10 }22 }
src/components/notes/podcast-history.test.tsxmodified+46 -6
@@ -44,17 +44,17 @@ describe("PodcastHistory", () => {
44 vi.clearAllMocks();44 vi.clearAllMocks();
45 });45 });
46 46
47- const renderHistory = () =>47+ const renderHistory = (noteId?: string) =>
48 render(() => (48 render(() => (
49 <PreferencesProvider>49 <PreferencesProvider>
50- <PodcastHistory active />50+ <PodcastHistory noteId={noteId} active />
51 </PreferencesProvider>51 </PreferencesProvider>
52 ));52 ));
53 53
54 it("renders a finished row's title, state and duration, and plays it by job id", async () => {54 it("renders a finished row's title, state and duration, and plays it by job id", async () => {
55 podcastApi.listPodcastJobs.mockResolvedValue(page([job({})]));55 podcastApi.listPodcastJobs.mockResolvedValue(page([job({})]));
56 56
57- renderHistory();57+ renderHistory("note-1");
58 58
59 await waitFor(() => expect(screen.getByText("Hücre")).toBeTruthy());59 await waitFor(() => expect(screen.getByText("Hücre")).toBeTruthy());
60 expect(screen.getByText("Hazır")).toBeTruthy();60 expect(screen.getByText("Hazır")).toBeTruthy();
@@ -70,25 +70,65 @@ describe("PodcastHistory", () => {
70 page([job({ state: "running", duration_secs: null, finished_at: null })]),70 page([job({ state: "running", duration_secs: null, finished_at: null })]),
71 );71 );
72 72
73- renderHistory();73+ renderHistory("note-1");
74 74
75 await waitFor(() => expect(screen.getByText("Hazırlanıyor")).toBeTruthy());75 await waitFor(() => expect(screen.getByText("Hazırlanıyor")).toBeTruthy());
76 expect(screen.queryByRole("button", { name: "Bölümü oynat" })).toBeNull();76 expect(screen.queryByRole("button", { name: "Bölümü oynat" })).toBeNull();
77 expect(document.querySelector("audio")).toBeNull();77 expect(document.querySelector("audio")).toBeNull();
78 });78 });
79 79
80+ it("asks the door about the open note only", async () => {
81+ podcastApi.listPodcastJobs.mockResolvedValue(page([job({})]));
82+
83+ renderHistory("note-1");
84+
85+ await waitFor(() =>
86+ expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 10, sourceId: "note-1" }),
87+ );
88+ expect(screen.getByText("Yalnızca bu notun bölümleri gösteriliyor.")).toBeTruthy();
89+ });
90+
91+ it("widens to the whole history when Tümü is picked", async () => {
92+ podcastApi.listPodcastJobs.mockResolvedValue(page([job({})]));
93+
94+ renderHistory("note-1");
95+ await waitFor(() => expect(podcastApi.listPodcastJobs).toHaveBeenCalledTimes(1));
96+
97+ fireEvent.click(screen.getByRole("button", { name: "Tümü" }));
98+
99+ await waitFor(() => expect(podcastApi.listPodcastJobs).toHaveBeenCalledTimes(2));
100+ expect(podcastApi.listPodcastJobs).toHaveBeenLastCalledWith({ limit: 10, sourceId: undefined });
101+ expect(screen.getByRole("button", { name: "Tümü" }).getAttribute("aria-pressed")).toBe("true");
102+ expect(screen.getByRole("button", { name: "Bu not" }).getAttribute("aria-pressed")).toBe("false");
103+ expect(screen.getByText("Tüm notlarınızdaki bölümler gösteriliyor.")).toBeTruthy();
104+ });
105+
106+ it("tells an empty note apart from an empty history", async () => {
107+ podcastApi.listPodcastJobs.mockResolvedValue(page([]));
108+
109+ renderHistory("note-1");
110+ await waitFor(() => expect(screen.getByText("Bu not için henüz bölüm yok")).toBeTruthy());
111+ expect(screen.queryByText("Henüz bölüm oluşturulmadı")).toBeNull();
112+
113+ fireEvent.click(screen.getByRole("button", { name: "Tümü" }));
114+
115+ await waitFor(() => expect(screen.getByText("Henüz bölüm oluşturulmadı")).toBeTruthy());
116+ expect(screen.queryByText("Bu not için henüz bölüm yok")).toBeNull();
117+ });
118+
80 it("shows the empty state when the caller has no episodes", async () => {119 it("shows the empty state when the caller has no episodes", async () => {
81 podcastApi.listPodcastJobs.mockResolvedValue(page([]));120 podcastApi.listPodcastJobs.mockResolvedValue(page([]));
82 121
83 renderHistory();122 renderHistory();
84 123
85 await waitFor(() => expect(screen.getByText("Henüz bölüm oluşturulmadı")).toBeTruthy());124 await waitFor(() => expect(screen.getByText("Henüz bölüm oluşturulmadı")).toBeTruthy());
125+ expect(podcastApi.listPodcastJobs).toHaveBeenCalledWith({ limit: 10, sourceId: undefined });
86 });126 });
87 127
88 it("falls back to the note id when the note is gone", async () => {128 it("falls back to the note id when the note is gone", async () => {
89 podcastApi.listPodcastJobs.mockResolvedValue(page([job({ source_id: "note-gone", source_title: null })]));129 podcastApi.listPodcastJobs.mockResolvedValue(page([job({ source_id: "note-gone", source_title: null })]));
90 130
91- renderHistory();131+ renderHistory("note-1");
92 132
93 await waitFor(() => expect(screen.getByText("note-gone")).toBeTruthy());133 await waitFor(() => expect(screen.getByText("note-gone")).toBeTruthy());
94 });134 });
@@ -99,7 +139,7 @@ describe("PodcastHistory", () => {
99 139
100 render(() => (140 render(() => (
101 <PreferencesProvider>141 <PreferencesProvider>
102- <PodcastHistory active refetchKey={key()} />142+ <PodcastHistory noteId="note-1" active refetchKey={key()} />
103 </PreferencesProvider>143 </PreferencesProvider>
104 ));144 ));
105 145
src/components/notes/podcast-history.tsxmodified+65 -5
@@ -8,25 +8,39 @@ import { Button } from "@/components/ui/button";
8 import { EmptyInline } from "@/components/ui/empty-inline";8 import { EmptyInline } from "@/components/ui/empty-inline";
9 import { PageSpinner } from "@/components/ui/page-spinner";9 import { PageSpinner } from "@/components/ui/page-spinner";
10 import { IconWaveform } from "@/components/ui/icons";10 import { IconWaveform } from "@/components/ui/icons";
11+import { cn } from "@/lib/cn";
11 import { formatDate, formatDurationClock } from "@/lib/format";12 import { formatDate, formatDurationClock } from "@/lib/format";
12 import { usePreferences, useT } from "@/stores/preferences-context";13 import { usePreferences, useT } from "@/stores/preferences-context";
13 14
14 const HISTORY_PAGE_SIZE = 10;15 const HISTORY_PAGE_SIZE = 10;
15 16
17+type Scope = "note" | "all";
18+
16 /**19 /**
17 * The caller's own episodes, under the Ses Atölyesi panel. One-directional:20 * The caller's own episodes, under the Ses Atölyesi panel. One-directional:
18 * the studio produces, this only reads. A finished episode plays through the21 * the studio produces, this only reads. A finished episode plays through the
19 * same job-id audio door the panel's own player uses.22 * same job-id audio door the panel's own player uses.
23+ *
24+ * The list follows the note the panel is open on by default, so opening one
25+ * note's studio never shows another's episodes; the header switch widens it to
26+ * the whole history and states which of the two is on screen.
20 */27 */
21-export function PodcastHistory(props: { active?: boolean; refetchKey?: string | number }) {28+export function PodcastHistory(props: { noteId?: string; active?: boolean; refetchKey?: string | number }) {
22 const t = useT();29 const t = useT();
23 const { locale } = usePreferences();30 const { locale } = usePreferences();
24 const [playing, setPlaying] = createSignal("");31 const [playing, setPlaying] = createSignal("");
32+ const [scope, setScope] = createSignal<Scope>("note");
25 const active = () => props.active !== false;33 const active = () => props.active !== false;
26 34
35+ // The source is the scope string, not a fresh object: an identity-stable
36+ // value keeps the resource from refetching when nothing about it changed.
27 const [list, { refetch }] = createResource(37 const [list, { refetch }] = createResource(
28- () => (active() ? true : null),38+ () => (active() ? (props.noteId ? scope() : "all") : null),
29- () => listPodcastJobs({ limit: HISTORY_PAGE_SIZE }),39+ (current) =>
40+ listPodcastJobs({
41+ limit: HISTORY_PAGE_SIZE,
42+ sourceId: current === "note" ? props.noteId : undefined,
43+ }),
30 );44 );
31 45
32 // The panel bumps the key ("", then the job id) when a generation finishes;46 // 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 |
53 67
54 return (68 return (
55 <div class="space-y-3 border-t border-border-line pt-4">69 <div class="space-y-3 border-t border-border-line pt-4">
56- <h3 class="text-sm font-semibold">{t("podcast.history.title")}</h3>70+ <div class="flex flex-wrap items-center justify-between gap-x-3 gap-y-2">
71+ <h3 class="text-sm font-semibold">{t("podcast.history.title")}</h3>
72+ <Show when={props.noteId}>
73+ <div
74+ class="flex shrink-0 rounded-lg bg-muted p-0.5"
75+ role="group"
76+ aria-label={t("podcast.history.scope.label")}
77+ >
78+ <button
79+ type="button"
80+ aria-pressed={scope() === "note"}
81+ onClick={() => setScope("note")}
82+ class={cn(
83+ "rounded-md px-2.5 py-1 text-xs font-medium transition-colors outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
84+ scope() === "note"
85+ ? "bg-background text-foreground shadow-xs"
86+ : "text-muted-foreground hover:text-foreground",
87+ )}
88+ >
89+ {t("podcast.history.scope.note")}
90+ </button>
91+ <button
92+ type="button"
93+ aria-pressed={scope() === "all"}
94+ onClick={() => setScope("all")}
95+ class={cn(
96+ "rounded-md px-2.5 py-1 text-xs font-medium transition-colors outline-hidden focus-visible:ring-2 focus-visible:ring-ring",
97+ scope() === "all"
98+ ? "bg-background text-foreground shadow-xs"
99+ : "text-muted-foreground hover:text-foreground",
100+ )}
101+ >
102+ {t("podcast.history.scope.all")}
103+ </button>
104+ </div>
105+ </Show>
106+ </div>
107+
108+ <p class="text-xs text-muted-foreground">
109+ {props.noteId && scope() === "note"
110+ ? t("podcast.history.scope.noteCaption")
111+ : t("podcast.history.scope.allCaption")}
112+ </p>
57 113
58 <Show when={list.error}>114 <Show when={list.error}>
59 <Alert variant="destructive">{formatApiError(list.error)}</Alert>115 <Alert variant="destructive">{formatApiError(list.error)}</Alert>
@@ -65,7 +121,11 @@ export function PodcastHistory(props: { active?: boolean; refetchKey?: string |
65 when={jobs().length > 0}121 when={jobs().length > 0}
66 fallback={122 fallback={
67 <EmptyInline123 <EmptyInline
68- title={t("podcast.history.empty")}124+ title={
125+ props.noteId && scope() === "note"
126+ ? t("podcast.history.emptyNote")
127+ : t("podcast.history.empty")
128+ }
69 hint={t("podcast.history.emptyHint")}129 hint={t("podcast.history.emptyHint")}
70 />130 />
71 }131 }
src/components/notes/podcast-panel.tsxmodified+5 -1
@@ -214,7 +214,11 @@ export function PodcastPanel(props: { noteId: string; active?: boolean }) {
214 )}214 )}
215 </Show>215 </Show>
216 216
217- <PodcastHistory active={active()} refetchKey={status()?.state === "done" ? jobId() : ""} />217+ <PodcastHistory
218+ noteId={props.noteId}
219+ active={active()}
220+ refetchKey={status()?.state === "done" ? jobId() : ""}
221+ />
218 </section>222 </section>
219 );223 );
220 }224 }
src/i18n/messages.tsmodified+18 -0
@@ -909,8 +909,14 @@ export type MessageKey =
909 | "podcast.history.state.failed"909 | "podcast.history.state.failed"
910 | "podcast.history.state.cancelled"910 | "podcast.history.state.cancelled"
911 | "podcast.history.empty"911 | "podcast.history.empty"
912+ | "podcast.history.emptyNote"
912 | "podcast.history.emptyHint"913 | "podcast.history.emptyHint"
913 | "podcast.history.play"914 | "podcast.history.play"
915+ | "podcast.history.scope.label"
916+ | "podcast.history.scope.note"
917+ | "podcast.history.scope.all"
918+ | "podcast.history.scope.noteCaption"
919+ | "podcast.history.scope.allCaption"
914 | "insights.title"920 | "insights.title"
915 | "insights.subtitle"921 | "insights.subtitle"
916 | "insights.student"922 | "insights.student"
@@ -3027,8 +3033,14 @@ const en: Dict = {
3027 "podcast.history.state.failed": "Failed",3033 "podcast.history.state.failed": "Failed",
3028 "podcast.history.state.cancelled": "Cancelled",3034 "podcast.history.state.cancelled": "Cancelled",
3029 "podcast.history.empty": "No episodes created yet",3035 "podcast.history.empty": "No episodes created yet",
3036+ "podcast.history.emptyNote": "No episodes for this note yet",
3030 "podcast.history.emptyHint": "Episodes appear here once the studio produces one.",3037 "podcast.history.emptyHint": "Episodes appear here once the studio produces one.",
3031 "podcast.history.play": "Play episode",3038 "podcast.history.play": "Play episode",
3039+ "podcast.history.scope.label": "Episode scope",
3040+ "podcast.history.scope.note": "This note",
3041+ "podcast.history.scope.all": "All",
3042+ "podcast.history.scope.noteCaption": "Showing this note's episodes only.",
3043+ "podcast.history.scope.allCaption": "Showing episodes from every note.",
3032 "insights.title": "Hezarfen Intelligence",3044 "insights.title": "Hezarfen Intelligence",
3033 "insights.subtitle": "Review student signals, recommendations, and nightly analysis runs.",3045 "insights.subtitle": "Review student signals, recommendations, and nightly analysis runs.",
3034 "insights.student": "Student",3046 "insights.student": "Student",
@@ -5147,8 +5159,14 @@ const tr: Dict = {
5147 "podcast.history.state.failed": "Başarısız",5159 "podcast.history.state.failed": "Başarısız",
5148 "podcast.history.state.cancelled": "İptal edildi",5160 "podcast.history.state.cancelled": "İptal edildi",
5149 "podcast.history.empty": "Henüz bölüm oluşturulmadı",5161 "podcast.history.empty": "Henüz bölüm oluşturulmadı",
5162+ "podcast.history.emptyNote": "Bu not için henüz bölüm yok",
5150 "podcast.history.emptyHint": "Stüdyo bir bölüm ürettiğinde burada görünür.",5163 "podcast.history.emptyHint": "Stüdyo bir bölüm ürettiğinde burada görünür.",
5151 "podcast.history.play": "Bölümü oynat",5164 "podcast.history.play": "Bölümü oynat",
5165+ "podcast.history.scope.label": "Bölüm kapsamı",
5166+ "podcast.history.scope.note": "Bu not",
5167+ "podcast.history.scope.all": "Tümü",
5168+ "podcast.history.scope.noteCaption": "Yalnızca bu notun bölümleri gösteriliyor.",
5169+ "podcast.history.scope.allCaption": "Tüm notlarınızdaki bölümler gösteriliyor.",
5152 "insights.title": "Hezarfen Zeka",5170 "insights.title": "Hezarfen Zeka",
5153 "insights.subtitle": "Öğrenci sinyallerini, önerileri ve gece analizlerini inceleyin.",5171 "insights.subtitle": "Öğrenci sinyallerini, önerileri ve gece analizlerini inceleyin.",
5154 "insights.student": "Öğrenci",5172 "insights.student": "Öğrenci",