SurfSense/surfsense_web/components/chat/ChatPanel/ConfigModal.tsx

72 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-10-23 19:35:52 +02:00
"use client";
2025-11-11 04:02:04 +02:00
import { useAtomValue } from "jotai";
2025-10-23 19:35:52 +02:00
import { Pencil } from "lucide-react";
2025-10-23 21:42:39 +02:00
import { useCallback, useContext, useState } from "react";
2025-10-23 19:35:52 +02:00
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
2025-11-11 04:02:04 +02:00
import { activeChatAtom } from "@/stores/chat/active-chat.atom";
2025-10-23 21:42:39 +02:00
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
2025-10-23 19:35:52 +02:00
interface ConfigModalProps {
generatePodcast: (request: GeneratePodcastRequest) => Promise<void>;
}
export function ConfigModal(props: ConfigModalProps) {
2025-11-11 04:02:04 +02:00
const { data: activeChatState } = useAtomValue(activeChatAtom);
const chatDetails = activeChatState?.chatDetails;
const podcast = activeChatState?.podcast;
2025-10-23 19:35:52 +02:00
const { generatePodcast } = props;
2025-11-11 04:02:04 +02:00
const [podcastTitle, setPodcastTitle] = useState(podcast?.title || chatDetails?.title);
2025-10-23 21:42:39 +02:00
2025-10-23 19:35:52 +02:00
const handleGeneratePost = useCallback(async () => {
if (!chatDetails) return;
await generatePodcast({
type: "CHAT",
ids: [chatDetails.id],
search_space_id: chatDetails.search_space_id,
2025-11-11 04:02:04 +02:00
podcast_title: podcastTitle || podcast?.title || chatDetails.title,
2025-10-23 19:35:52 +02:00
});
2025-10-23 21:42:39 +02:00
}, [chatDetails, podcastTitle]);
2025-11-11 04:02:04 +02:00
2025-10-23 19:35:52 +02:00
return (
<Popover>
2025-10-23 21:42:39 +02:00
<PopoverTrigger
title="Edit the prompt"
className="rounded-full p-2 bg-slate-400/30 hover:bg-slate-400/40"
onClick={(e) => e.stopPropagation()}
>
<Pencil strokeWidth={1} className="h-4 w-4" />
2025-10-23 19:35:52 +02:00
</PopoverTrigger>
2025-10-23 23:50:45 +02:00
<PopoverContent onClick={(e) => e.stopPropagation()} align="end" className="bg-sidebar w-96 ">
2025-10-23 19:35:52 +02:00
<form className="flex flex-col gap-3 w-full">
<label className="text-sm font-medium" htmlFor="prompt">
What subjects should the AI cover in this podcast ?
</label>
<textarea
name="prompt"
id="prompt"
2025-10-23 21:42:39 +02:00
defaultValue={podcastTitle}
2025-10-23 19:35:52 +02:00
className="w-full rounded-md border border-slate-400/40 p-2"
2025-11-11 04:02:04 +02:00
onChange={(e) => {
e.stopPropagation();
setPodcastTitle(e.target.value);
}}
2025-10-23 19:35:52 +02:00
></textarea>
<button
type="button"
onClick={handleGeneratePost}
className="w-full rounded-md bg-foreground text-white dark:text-black p-2"
>
Generate Podcast
</button>
</form>
</PopoverContent>
</Popover>
);
}