refactor: replace TranscriptEntry interface with PodcastTranscriptEntry type for improved type safety in podcast player

This commit is contained in:
Anish Sarkar 2025-12-21 20:37:30 +05:30
parent 4f2c9caac2
commit bc189a53cf
2 changed files with 11 additions and 12 deletions

View file

@ -10,6 +10,7 @@ import {
clearActivePodcastTaskId, clearActivePodcastTaskId,
setActivePodcastTaskId, setActivePodcastTaskId,
} from "@/lib/chat/podcast-state"; } from "@/lib/chat/podcast-state";
import type { PodcastTranscriptEntry } from "@/contracts/types/podcast.types";
/** /**
* Type definitions for the generate_podcast tool * Type definitions for the generate_podcast tool
@ -51,7 +52,7 @@ function PodcastGeneratingState({ title }: { title: string }) {
<MicIcon className="size-8 text-primary" /> <MicIcon className="size-8 text-primary" />
</div> </div>
{/* Animated rings */} {/* Animated rings */}
<div className="absolute inset-1.4 animate-ping rounded-full bg-primary/20" /> <div className="absolute inset-1 animate-ping rounded-full bg-primary/20" />
</div> </div>
<div className="flex-1"> <div className="flex-1">
<h3 className="font-semibold text-foreground text-lg">{title}</h3> <h3 className="font-semibold text-foreground text-lg">{title}</h3>
@ -112,14 +113,6 @@ function AudioLoadingState({ title }: { title: string }) {
); );
} }
/**
* Transcript entry type from the database
*/
interface TranscriptEntry {
speaker_id: number;
dialog: string;
}
/** /**
* Podcast Player Component - Fetches audio and transcript with authentication * Podcast Player Component - Fetches audio and transcript with authentication
*/ */
@ -135,7 +128,7 @@ function PodcastPlayer({
durationMs?: number; durationMs?: number;
}) { }) {
const [audioSrc, setAudioSrc] = useState<string | null>(null); const [audioSrc, setAudioSrc] = useState<string | null>(null);
const [transcript, setTranscript] = useState<TranscriptEntry[] | null>(null); const [transcript, setTranscript] = useState<PodcastTranscriptEntry[] | null>(null);
const [isLoading, setIsLoading] = useState(true); const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
const objectUrlRef = useRef<string | null>(null); const objectUrlRef = useRef<string | null>(null);
@ -181,7 +174,7 @@ function PodcastPlayer({
// Set transcript from podcast details // Set transcript from podcast details
if (podcastDetails?.podcast_transcript) { if (podcastDetails?.podcast_transcript) {
setTranscript(podcastDetails.podcast_transcript as TranscriptEntry[]); setTranscript(podcastDetails.podcast_transcript);
} }
} finally { } finally {
clearTimeout(timeoutId); clearTimeout(timeoutId);

View file

@ -1,12 +1,17 @@
import { z } from "zod"; import { z } from "zod";
import { paginationQueryParams } from "."; import { paginationQueryParams } from ".";
export const podcastTranscriptEntry = z.object({
speaker_id: z.number(),
dialog: z.string(),
});
export const podcast = z.object({ export const podcast = z.object({
id: z.number(), id: z.number(),
title: z.string(), title: z.string(),
created_at: z.string(), created_at: z.string(),
file_location: z.string(), file_location: z.string(),
podcast_transcript: z.array(z.any()), podcast_transcript: z.array(podcastTranscriptEntry),
search_space_id: z.number(), search_space_id: z.number(),
chat_state_version: z.number().nullable(), chat_state_version: z.number().nullable(),
}); });
@ -41,6 +46,7 @@ export const getPodcastsRequest = z.object({
queryParams: paginationQueryParams.nullish(), queryParams: paginationQueryParams.nullish(),
}); });
export type PodcastTranscriptEntry = z.infer<typeof podcastTranscriptEntry>;
export type GeneratePodcastRequest = z.infer<typeof generatePodcastRequest>; export type GeneratePodcastRequest = z.infer<typeof generatePodcastRequest>;
export type GetPodcastByChatIdRequest = z.infer<typeof getPodcastByChatIdRequest>; export type GetPodcastByChatIdRequest = z.infer<typeof getPodcastByChatIdRequest>;
export type GetPodcastByChatIdResponse = z.infer<typeof getPodcastByChaIdResponse>; export type GetPodcastByChatIdResponse = z.infer<typeof getPodcastByChaIdResponse>;