mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
Add use podcasts
This commit is contained in:
parent
666ea87a9d
commit
13342eb823
3 changed files with 43 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ import { ChatInputUI } from "@/components/chat/ChatInputGroup";
|
||||||
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
|
import { ChatMessagesUI } from "@/components/chat/ChatMessages";
|
||||||
import { useChatAPI } from "@/hooks/use-chat";
|
import { useChatAPI } from "@/hooks/use-chat";
|
||||||
import type { Document } from "@/hooks/use-documents";
|
import type { Document } from "@/hooks/use-documents";
|
||||||
|
import { usePodcast } from "@/hooks/use-podcast";
|
||||||
import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer";
|
import { ChatPanelContainer } from "./ChatPanel/ChatPanelContainer";
|
||||||
|
|
||||||
interface ChatInterfaceProps {
|
interface ChatInterfaceProps {
|
||||||
|
|
@ -55,11 +56,21 @@ export default function ChatInterface({
|
||||||
chatDetails,
|
chatDetails,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { getPodcastByChatId } = usePodcast();
|
||||||
|
|
||||||
const { fetchChatDetails } = useChatAPI({
|
const { fetchChatDetails } = useChatAPI({
|
||||||
token: localStorage.getItem("surfsense_bearer_token"),
|
token: localStorage.getItem("surfsense_bearer_token"),
|
||||||
search_space_id: search_space_id as string,
|
search_space_id: search_space_id as string,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getPodcast = useCallback(
|
||||||
|
async (id: string) => {
|
||||||
|
const podcast = await getPodcastByChatId(Number(id));
|
||||||
|
setPodcast(podcast);
|
||||||
|
},
|
||||||
|
[getPodcastByChatId]
|
||||||
|
);
|
||||||
|
|
||||||
const getChat = useCallback(
|
const getChat = useCallback(
|
||||||
async (id: string) => {
|
async (id: string) => {
|
||||||
const chat = await fetchChatDetails(id);
|
const chat = await fetchChatDetails(id);
|
||||||
|
|
@ -72,6 +83,7 @@ export default function ChatInterface({
|
||||||
const id = typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "";
|
const id = typeof chat_id === "string" ? chat_id : chat_id ? chat_id[0] : "";
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
getChat(id);
|
getChat(id);
|
||||||
|
getPodcast(id);
|
||||||
}, [chat_id, search_space_id]);
|
}, [chat_id, search_space_id]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export function ConfigModal(props: ConfigModalProps) {
|
||||||
>
|
>
|
||||||
<Pencil strokeWidth={1} className="h-4 w-4" />
|
<Pencil strokeWidth={1} className="h-4 w-4" />
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent align="end" className="bg-sidebar w-96 ">
|
<PopoverContent onClick={(e) => e.stopPropagation()} align="end" className="bg-sidebar w-96 ">
|
||||||
<form className="flex flex-col gap-3 w-full">
|
<form className="flex flex-col gap-3 w-full">
|
||||||
<label className="text-sm font-medium" htmlFor="prompt">
|
<label className="text-sm font-medium" htmlFor="prompt">
|
||||||
What subjects should the AI cover in this podcast ?
|
What subjects should the AI cover in this podcast ?
|
||||||
|
|
|
||||||
30
surfsense_web/hooks/use-podcast.ts
Normal file
30
surfsense_web/hooks/use-podcast.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import type { PodcastItem } from "@/app/dashboard/[search_space_id]/podcasts/podcasts-client";
|
||||||
|
|
||||||
|
export function usePodcast() {
|
||||||
|
const getPodcastByChatId = useCallback(async (chatId: number) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${process.env.NEXT_PUBLIC_FASTAPI_BACKEND_URL}/api/v1/podcasts/by-chat/${chatId}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${localStorage.getItem("surfsense_bearer_token")}`,
|
||||||
|
},
|
||||||
|
method: "GET",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorData = await response.json().catch(() => ({}));
|
||||||
|
throw new Error(errorData.detail || "Failed to fetch podcast");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (await response.json()) as PodcastItem;
|
||||||
|
} catch (err: any) {
|
||||||
|
console.error("Error fetching podcast:", err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { getPodcastByChatId };
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue