File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import { ChatInputUI } from "@/components/chat/ChatInputGroup";
1010import { ChatMessagesUI } from "@/components/chat/ChatMessages" ;
1111import { useChatAPI } from "@/hooks/use-chat" ;
1212import type { Document } from "@/hooks/use-documents" ;
13+ import { usePodcast } from "@/hooks/use-podcast" ;
1314import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer" ;
1415
1516interface ChatInterfaceProps {
@@ -59,11 +60,21 @@ export default function ChatInterface({
5960 chatDetails,
6061 } ;
6162
63+ const { getPodcastByChatId } = usePodcast ( ) ;
64+
6265 const { fetchChatDetails } = useChatAPI ( {
6366 token : localStorage . getItem ( "surfsense_bearer_token" ) ,
6467 search_space_id : search_space_id as string ,
6568 } ) ;
6669
70+ const getPodcast = useCallback (
71+ async ( id : string ) => {
72+ const podcast = await getPodcastByChatId ( Number ( id ) ) ;
73+ setPodcast ( podcast ) ;
74+ } ,
75+ [ getPodcastByChatId ]
76+ ) ;
77+
6778 const getChat = useCallback (
6879 async ( id : string ) => {
6980 const chat = await fetchChatDetails ( id ) ;
@@ -76,6 +87,7 @@ export default function ChatInterface({
7687 const id = typeof chat_id === "string" ? chat_id : chat_id ? chat_id [ 0 ] : "" ;
7788 if ( ! id ) return ;
7889 getChat ( id ) ;
90+ getPodcast ( id ) ;
7991 } , [ chat_id , search_space_id ] ) ;
8092
8193 return (
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export function ConfigModal(props: ConfigModalProps) {
3939 >
4040 < Pencil strokeWidth = { 1 } className = "h-4 w-4" />
4141 </ PopoverTrigger >
42- < PopoverContent align = "end" className = "bg-sidebar w-96 " >
42+ < PopoverContent onClick = { ( e ) => e . stopPropagation ( ) } align = "end" className = "bg-sidebar w-96 " >
4343 < form className = "flex flex-col gap-3 w-full" >
4444 < label className = "text-sm font-medium" htmlFor = "prompt" >
4545 What subjects should the AI cover in this podcast ?
Original file line number Diff line number Diff line change 1+ import { useCallback } from "react" ;
2+ import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client" ;
3+
4+ export function usePodcast ( ) {
5+ const getPodcastByChatId = useCallback ( async ( chatId : number ) => {
6+ try {
7+ const response = await fetch (
8+ `${ process . env . NEXT_PUBLIC_FASTAPI_BACKEND_URL } /api/v1/podcasts/by-chat/${ chatId } ` ,
9+ {
10+ headers : {
11+ Authorization : `Bearer ${ localStorage . getItem ( "surfsense_bearer_token" ) } ` ,
12+ } ,
13+ method : "GET" ,
14+ }
15+ ) ;
16+
17+ if ( ! response . ok ) {
18+ const errorData = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
19+ throw new Error ( errorData . detail || "Failed to fetch podcast" ) ;
20+ }
21+
22+ return ( await response . json ( ) ) as PodcastItem ;
23+ } catch ( err : any ) {
24+ console . error ( "Error fetching podcast:" , err ) ;
25+ throw err ;
26+ }
27+ } , [ ] ) ;
28+
29+ return { getPodcastByChatId } ;
30+ }
You can’t perform that action at this time.
0 commit comments