🐛 label podcast job stages instead of raw keys
Browse files at this commite0d51114ea293b9917749b12cd955d6e853931ebParent: 45f3d41- fix
- 🐛 label podcast job stages instead of raw keys
9 changed files +133 -24
- src/components/notes/podcast-panel.test.tsx +2 -1
- src/components/notes/podcast-panel.tsx +1 -2
- src/components/notes/podcast-stage-trail.test.tsx +27 -20
- src/components/notes/podcast-stage-trail.tsx +4 -1
- src/i18n/locales/en.ts +13 -0
- src/i18n/locales/tr.ts +13 -0
- src/i18n/messages.ts +13 -0
- src/lib/podcast-stage-labels.test.ts +24 -0
- src/lib/podcast-stage-labels.ts +36 -0
src/components/notes/podcast-panel.test.tsxmodified+2 -1
| @@ -49,7 +49,8 @@ describe("PodcastPanel", () => { | ||
| 49 | 49 | expect(podcastApi.postPodcastJob).toHaveBeenCalledWith({ source_id: "note-7", format: "tek_ogretici" }); |
| 50 | 50 | }); |
| 51 | 51 | expect(sessionStorage.getItem("hezarfen.podcast.note-7")).toBe("j1"); |
| 52 | - expect(screen.getByText("Waiting in queue")).toBeTruthy(); | |
| 52 | + expect(screen.getAllByText("Waiting in queue")).toHaveLength(2); | |
| 53 | + expect(screen.queryByText("queued")).toBeNull(); | |
| 53 | 54 | }); |
| 54 | 55 | |
| 55 | 56 | it("points the audio element at the job's audio door, not the artifact path", async () => { |
src/components/notes/podcast-panel.tsxmodified+1 -2
| @@ -233,8 +233,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl | ||
| 233 | 233 | </Show> |
| 234 | 234 | </span> |
| 235 | 235 | </div> |
| 236 | - {/* The stage names itself in the service's own vocabulary and is not | |
| 237 | - an enumerated set, so the values are shown as they came. */} | |
| 236 | + {/* Known stage keys are labeled; a stage newer than the map shows as sent. */} | |
| 238 | 237 | <Show when={stages().length > 0}> |
| 239 | 238 | <PodcastStageTrail entries={stages()} live={working()} label={t("podcast.stageLabel")} /> |
| 240 | 239 | </Show> |
src/components/notes/podcast-stage-trail.test.tsxmodified+27 -20
| @@ -1,37 +1,48 @@ | ||
| 1 | 1 | import { cleanup, render, screen } from "@solidjs/testing-library"; |
| 2 | -import { afterEach, describe, expect, it, vi } from "vitest"; | |
| 2 | +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | |
| 3 | 3 | import { PodcastStageTrail } from "@/components/notes/podcast-stage-trail"; |
| 4 | +import { PreferencesProvider } from "@/stores/preferences-context"; | |
| 4 | 5 | |
| 5 | 6 | const T = Date.UTC(2026, 0, 2, 10, 0, 0); |
| 6 | 7 | |
| 8 | +function trail(props: { entries: { stage: string; at: number }[]; live: boolean }) { | |
| 9 | + return ( | |
| 10 | + <PreferencesProvider> | |
| 11 | + <PodcastStageTrail entries={props.entries} live={props.live} label="Aşamalar" /> | |
| 12 | + </PreferencesProvider> | |
| 13 | + ); | |
| 14 | +} | |
| 15 | + | |
| 7 | 16 | describe("PodcastStageTrail", () => { |
| 17 | + beforeEach(() => { | |
| 18 | + localStorage.setItem("hezarfen.locale", "en"); | |
| 19 | + }); | |
| 20 | + | |
| 8 | 21 | afterEach(() => { |
| 9 | 22 | cleanup(); |
| 23 | + localStorage.removeItem("hezarfen.locale"); | |
| 10 | 24 | vi.useRealTimers(); |
| 11 | 25 | vi.restoreAllMocks(); |
| 12 | 26 | }); |
| 13 | 27 | |
| 14 | 28 | it("times each stage by the one that replaced it", () => { |
| 15 | - render(() => ( | |
| 16 | - <PodcastStageTrail | |
| 17 | - entries={[ | |
| 29 | + render(() => | |
| 30 | + trail({ | |
| 31 | + entries: [ | |
| 18 | 32 | { stage: "queued", at: T }, |
| 19 | 33 | { stage: "synthesizing", at: T + 12_000 }, |
| 20 | - ]} | |
| 21 | - live={false} | |
| 22 | - label="Aşamalar" | |
| 23 | - /> | |
| 24 | - )); | |
| 34 | + ], | |
| 35 | + live: false, | |
| 36 | + }), | |
| 37 | + ); | |
| 25 | 38 | |
| 26 | - expect(screen.getByText("queued")).toBeTruthy(); | |
| 39 | + expect(screen.getByText("Waiting in queue")).toBeTruthy(); | |
| 27 | 40 | expect(screen.getByText("synthesizing")).toBeTruthy(); |
| 28 | 41 | expect(screen.getByText("00:12")).toBeTruthy(); |
| 29 | 42 | }); |
| 30 | 43 | |
| 31 | 44 | it("leaves the last stage of a settled job without a span to guess at", () => { |
| 32 | - render(() => ( | |
| 33 | - <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live={false} label="Aşamalar" /> | |
| 34 | - )); | |
| 45 | + render(() => trail({ entries: [{ stage: "queued", at: T }], live: false })); | |
| 35 | 46 | |
| 36 | 47 | expect(screen.getByText("—")).toBeTruthy(); |
| 37 | 48 | }); |
| @@ -40,17 +51,13 @@ describe("PodcastStageTrail", () => { | ||
| 40 | 51 | vi.useFakeTimers(); |
| 41 | 52 | vi.setSystemTime(T + 7_000); |
| 42 | 53 | |
| 43 | - render(() => ( | |
| 44 | - <PodcastStageTrail entries={[{ stage: "queued", at: T }]} live label="Aşamalar" /> | |
| 45 | - )); | |
| 54 | + render(() => trail({ entries: [{ stage: "queued", at: T }], live: true })); | |
| 46 | 55 | |
| 47 | 56 | expect(screen.getByText("00:07")).toBeTruthy(); |
| 48 | 57 | }); |
| 49 | 58 | |
| 50 | - it("shows the service's own stage names verbatim", () => { | |
| 51 | - render(() => ( | |
| 52 | - <PodcastStageTrail entries={[{ stage: "some_unknown_stage", at: T }]} live label="Aşamalar" /> | |
| 53 | - )); | |
| 59 | + it("shows an unknown stage as the service sent it", () => { | |
| 60 | + render(() => trail({ entries: [{ stage: "some_unknown_stage", at: T }], live: true })); | |
| 54 | 61 | |
| 55 | 62 | expect(screen.getByText("some_unknown_stage")).toBeTruthy(); |
| 56 | 63 | }); |
src/components/notes/podcast-stage-trail.tsxmodified+4 -1
| @@ -1,6 +1,8 @@ | ||
| 1 | 1 | import { For, createSignal, onCleanup } from "solid-js"; |
| 2 | 2 | import { cn } from "@/lib/cn"; |
| 3 | 3 | import { formatDurationClock } from "@/lib/format"; |
| 4 | +import { podcastStageLabel } from "@/lib/podcast-stage-labels"; | |
| 5 | +import { useT } from "@/stores/preferences-context"; | |
| 4 | 6 | |
| 5 | 7 | export type PodcastStageEntry = { |
| 6 | 8 | /** The service's own stage name, stored as it came. */ |
| @@ -21,6 +23,7 @@ const TICK_MS = 1_000; | ||
| 21 | 23 | * inventing the steps before that would be making up a history we never saw. |
| 22 | 24 | */ |
| 23 | 25 | export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: boolean; label: string }) { |
| 26 | + const t = useT(); | |
| 24 | 27 | const [now, setNow] = createSignal(Date.now()); |
| 25 | 28 | const timer = window.setInterval(() => setNow(Date.now()), TICK_MS); |
| 26 | 29 | onCleanup(() => window.clearInterval(timer)); |
| @@ -51,7 +54,7 @@ export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: b | ||
| 51 | 54 | )} |
| 52 | 55 | /> |
| 53 | 56 | <span class={cn("min-w-0 flex-1 truncate", running() ? "font-medium text-foreground" : "text-muted-foreground")}> |
| 54 | - {entry.stage} | |
| 57 | + {podcastStageLabel(entry.stage, t)} | |
| 55 | 58 | </span> |
| 56 | 59 | <span class="shrink-0 tabular-nums text-muted-foreground"> |
| 57 | 60 | {spanOf(index()) == null ? "—" : formatDurationClock(spanOf(index())!)} |
src/i18n/locales/en.tsmodified+13 -0
| @@ -1043,6 +1043,19 @@ export const en: Dict = { | ||
| 1043 | 1043 | "podcast.noNotesHint": "Add a note to one of your courses before creating audio.", |
| 1044 | 1044 | "podcast.format": "Narration style", |
| 1045 | 1045 | "podcast.stageLabel": "Stages", |
| 1046 | + "podcast.stage.queued": "Waiting in queue", | |
| 1047 | + "podcast.stage.ocr": "Reading the document", | |
| 1048 | + "podcast.stage.plan": "Planning the episode", | |
| 1049 | + "podcast.stage.kaynak": "Reading the source", | |
| 1050 | + "podcast.stage.metin": "Extracting the text", | |
| 1051 | + "podcast.stage.ingest": "Taking in the source", | |
| 1052 | + "podcast.stage.script": "Writing the script", | |
| 1053 | + "podcast.stage.scriptler": "Writing the script", | |
| 1054 | + "podcast.stage.quiz": "Adding questions", | |
| 1055 | + "podcast.stage.tts": "Narrating", | |
| 1056 | + "podcast.stage.ses": "Narrating", | |
| 1057 | + "podcast.stage.mux": "Mixing", | |
| 1058 | + "podcast.stage.done": "Ready", | |
| 1046 | 1059 | "podcast.etaHint": "Estimated time: about {secs}s", |
| 1047 | 1060 | "podcast.format.duz_okuma": "Straight reading", |
| 1048 | 1061 | "podcast.format.tek_ogretici": "Single instructor", |
src/i18n/locales/tr.tsmodified+13 -0
| @@ -1039,6 +1039,19 @@ export const tr: Dict = { | ||
| 1039 | 1039 | "podcast.noNotesHint": "Ses oluşturmadan önce derslerinizden birine not ekleyin.", |
| 1040 | 1040 | "podcast.format": "Anlatım biçimi", |
| 1041 | 1041 | "podcast.stageLabel": "Aşamalar", |
| 1042 | + "podcast.stage.queued": "Sırada bekliyor", | |
| 1043 | + "podcast.stage.ocr": "Belge okunuyor", | |
| 1044 | + "podcast.stage.plan": "Bölüm planlanıyor", | |
| 1045 | + "podcast.stage.kaynak": "Kaynak okunuyor", | |
| 1046 | + "podcast.stage.metin": "Metin çıkarılıyor", | |
| 1047 | + "podcast.stage.ingest": "Kaynak alınıyor", | |
| 1048 | + "podcast.stage.script": "Metin yazılıyor", | |
| 1049 | + "podcast.stage.scriptler": "Metin yazılıyor", | |
| 1050 | + "podcast.stage.quiz": "Sorular ekleniyor", | |
| 1051 | + "podcast.stage.tts": "Seslendiriliyor", | |
| 1052 | + "podcast.stage.ses": "Seslendiriliyor", | |
| 1053 | + "podcast.stage.mux": "Birleştiriliyor", | |
| 1054 | + "podcast.stage.done": "Hazır", | |
| 1042 | 1055 | "podcast.etaHint": "Tahmini süre: yaklaşık {secs} sn", |
| 1043 | 1056 | "podcast.format.duz_okuma": "Düz okuma", |
| 1044 | 1057 | "podcast.format.tek_ogretici": "Tek öğretici", |
src/i18n/messages.tsmodified+13 -0
| @@ -1030,6 +1030,19 @@ export type MessageKey = | ||
| 1030 | 1030 | | "podcast.noNotesHint" |
| 1031 | 1031 | | "podcast.format" |
| 1032 | 1032 | | "podcast.stageLabel" |
| 1033 | + | "podcast.stage.queued" | |
| 1034 | + | "podcast.stage.ocr" | |
| 1035 | + | "podcast.stage.plan" | |
| 1036 | + | "podcast.stage.kaynak" | |
| 1037 | + | "podcast.stage.metin" | |
| 1038 | + | "podcast.stage.ingest" | |
| 1039 | + | "podcast.stage.script" | |
| 1040 | + | "podcast.stage.scriptler" | |
| 1041 | + | "podcast.stage.quiz" | |
| 1042 | + | "podcast.stage.tts" | |
| 1043 | + | "podcast.stage.ses" | |
| 1044 | + | "podcast.stage.mux" | |
| 1045 | + | "podcast.stage.done" | |
| 1033 | 1046 | | "podcast.etaHint" |
| 1034 | 1047 | | "podcast.format.duz_okuma" |
| 1035 | 1048 | | "podcast.format.tek_ogretici" |
src/lib/podcast-stage-labels.test.tsadded+24 -0
| @@ -0,0 +1,24 @@ | ||
| 1 | +import { expect, test } from "vitest"; | |
| 2 | +import { en } from "@/i18n/locales/en"; | |
| 3 | +import { tr } from "@/i18n/locales/tr"; | |
| 4 | +import type { MessageKey } from "@/i18n/messages"; | |
| 5 | +import { PODCAST_STAGE_KEYS, podcastStageLabel } from "./podcast-stage-labels"; | |
| 6 | + | |
| 7 | +const locales = { en, tr } as const; | |
| 8 | + | |
| 9 | +test("every known stage has a non-empty label in both locales", () => { | |
| 10 | + for (const stage of Object.keys(PODCAST_STAGE_KEYS)) { | |
| 11 | + for (const [name, dict] of Object.entries(locales)) { | |
| 12 | + const label = podcastStageLabel(stage, (key) => dict[key]); | |
| 13 | + expect(label, `${name}:${stage}`).not.toBe(""); | |
| 14 | + expect(label, `${name}:${stage}`).not.toBe(stage); | |
| 15 | + } | |
| 16 | + } | |
| 17 | +}); | |
| 18 | + | |
| 19 | +test("an unknown stage falls back to the raw key", () => { | |
| 20 | + const t = (key: MessageKey) => key; | |
| 21 | + expect(podcastStageLabel("synthesizing", t)).toBe("synthesizing"); | |
| 22 | + expect(podcastStageLabel("toString", t)).toBe("toString"); | |
| 23 | + expect(podcastStageLabel("", t)).toBe(""); | |
| 24 | +}); |
src/lib/podcast-stage-labels.tsadded+36 -0
| @@ -0,0 +1,36 @@ | ||
| 1 | +import type { MessageKey } from "@/i18n/messages"; | |
| 2 | + | |
| 3 | +type Translate = (key: MessageKey, params?: Record<string, string>) => string; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Pipeline stage keys the job trail can show. | |
| 7 | + * | |
| 8 | + * The backend forwards `stage` as a free string (`PodcastJobStatus.stage`). | |
| 9 | + * The frontend records `queued` itself before the first poll; the service | |
| 10 | + * then reports one of its mode tuples and `done` when the job finishes: | |
| 11 | + * simulate `ocr → plan → script → tts → mux`, API `kaynak → metin → script → | |
| 12 | + * tts → mux`, local `ingest → scriptler → quiz → ses`. `failed` / `cancelled` | |
| 13 | + * are job states, not stages — a cancel clears the stage, a failure keeps | |
| 14 | + * the last one. | |
| 15 | + */ | |
| 16 | +export const PODCAST_STAGE_KEYS = { | |
| 17 | + queued: "podcast.stage.queued", | |
| 18 | + ocr: "podcast.stage.ocr", | |
| 19 | + plan: "podcast.stage.plan", | |
| 20 | + kaynak: "podcast.stage.kaynak", | |
| 21 | + metin: "podcast.stage.metin", | |
| 22 | + ingest: "podcast.stage.ingest", | |
| 23 | + script: "podcast.stage.script", | |
| 24 | + scriptler: "podcast.stage.scriptler", | |
| 25 | + quiz: "podcast.stage.quiz", | |
| 26 | + tts: "podcast.stage.tts", | |
| 27 | + ses: "podcast.stage.ses", | |
| 28 | + mux: "podcast.stage.mux", | |
| 29 | + done: "podcast.stage.done", | |
| 30 | +} as const satisfies Record<string, MessageKey>; | |
| 31 | + | |
| 32 | +/** Display label for a podcast stage key; an unknown key shows as sent. */ | |
| 33 | +export function podcastStageLabel(stage: string, t: Translate): string { | |
| 34 | + if (!Object.hasOwn(PODCAST_STAGE_KEYS, stage)) return stage; | |
| 35 | + return t(PODCAST_STAGE_KEYS[stage as keyof typeof PODCAST_STAGE_KEYS]); | |
| 36 | +} |