mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-05 13:52:40 +02:00
stop propagation in the chat panelcl
This commit is contained in:
parent
9007436ff6
commit
e47b1cb4c5
4 changed files with 34 additions and 36 deletions
|
|
@ -26,8 +26,6 @@ interface ChatInterfaceContext {
|
||||||
isChatPannelOpen: boolean;
|
isChatPannelOpen: boolean;
|
||||||
setIsChatPannelOpen: (value: boolean) => void;
|
setIsChatPannelOpen: (value: boolean) => void;
|
||||||
chat_id: string;
|
chat_id: string;
|
||||||
podcast: PodcastItem | null;
|
|
||||||
setPodcast: (value: PodcastItem) => void;
|
|
||||||
chatDetails: ChatDetails | null;
|
chatDetails: ChatDetails | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ export function ChatPanelContainer() {
|
||||||
throw new Error("chatInterfaceContext must be used within a ChatProvider");
|
throw new Error("chatInterfaceContext must be used within a ChatProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isChatPannelOpen, setIsChatPannelOpen, chat_id: chatId, setPodcast } = context;
|
const { isChatPannelOpen, setIsChatPannelOpen, chat_id: chatId } = context;
|
||||||
|
|
||||||
const generatePodcast = async (request: GeneratePodcastRequest) => {
|
const generatePodcast = async (request: GeneratePodcastRequest) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -42,10 +42,6 @@ export function ChatPanelContainer() {
|
||||||
throw new Error(errorData.detail || "Failed to generate podcast");
|
throw new Error(errorData.detail || "Failed to generate podcast");
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
setPodcast(result);
|
|
||||||
|
|
||||||
toast.success(`Podcast generation started!`);
|
toast.success(`Podcast generation started!`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error generating podcast:", error);
|
console.error("Error generating podcast:", error);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Pencil, Podcast } from "lucide-react";
|
import { Pencil, Podcast } from "lucide-react";
|
||||||
import { useContext, useTransition } from "react";
|
import { useCallback, useContext, useTransition } from "react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { chatInterfaceContext } from "../ChatInterface";
|
import { chatInterfaceContext } from "../ChatInterface";
|
||||||
import type { GeneratePodcastRequest } from "./actions";
|
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||||
import { ConfigModal } from "./ConfigModal";
|
import { ConfigModal } from "./ConfigModal";
|
||||||
|
|
||||||
interface ChatPanelViewProps {
|
interface ChatPanelViewProps {
|
||||||
|
|
@ -17,37 +17,40 @@ export function ChatPanelView(props: ChatPanelViewProps) {
|
||||||
throw new Error("chatInterfaceContext must be used within a ChatProvider");
|
throw new Error("chatInterfaceContext must be used within a ChatProvider");
|
||||||
}
|
}
|
||||||
|
|
||||||
const { isChatPannelOpen, setIsChatPannelOpen } = context;
|
const { isChatPannelOpen, setIsChatPannelOpen, chatDetails } = context;
|
||||||
const { generatePodcast } = props;
|
const { generatePodcast } = props;
|
||||||
|
|
||||||
const [isGeneratingPodcast, startGeneratingPodcast] = useTransition();
|
const handleGeneratePost = useCallback(async () => {
|
||||||
|
if (!chatDetails) return;
|
||||||
const handleGeneratePodcast = () => {
|
await generatePodcast({
|
||||||
startGeneratingPodcast(() => {
|
type: "CHAT",
|
||||||
generatePodcast({
|
ids: [chatDetails.id],
|
||||||
type: "CHAT",
|
search_space_id: chatDetails.search_space_id,
|
||||||
ids: [1],
|
podcast_title: chatDetails.title,
|
||||||
search_space_id: 1,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
}, [chatDetails]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full h-full p-4 border-b",
|
"w-full cursor-pointer h-full p-4 border-b",
|
||||||
!isChatPannelOpen && "flex items-center justify-center"
|
!isChatPannelOpen && "flex items-center justify-center"
|
||||||
)}
|
)}
|
||||||
|
title="Generate Podcast"
|
||||||
>
|
>
|
||||||
{isChatPannelOpen ? (
|
{isChatPannelOpen ? (
|
||||||
<div className=" space-y-3 rounded-xl p-3 bg-gradient-to-r from-slate-400/50 to-slate-200/50 dark:from-slate-400/30 dark:to-slate-800/60">
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleGeneratePost}
|
||||||
|
className=" space-y-3 rounded-xl p-3 bg-gradient-to-r from-slate-400/50 to-slate-200/50 dark:from-slate-400/30 dark:to-slate-800/60"
|
||||||
|
>
|
||||||
<div className="w-full flex items-center justify-between">
|
<div className="w-full flex items-center justify-between">
|
||||||
<Podcast strokeWidth={1} />
|
<Podcast strokeWidth={1} />
|
||||||
<ConfigModal generatePodcast={generatePodcast} />
|
<ConfigModal generatePodcast={generatePodcast} />
|
||||||
</div>
|
</div>
|
||||||
<p>Generate Podcast</p>
|
<p>Generate Podcast</p>
|
||||||
</div>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
title="Generate Podcast"
|
title="Generate Podcast"
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Pencil } from "lucide-react";
|
import { Pencil } from "lucide-react";
|
||||||
import { useCallback, useContext } from "react";
|
import { useCallback, useContext, useState } from "react";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||||
import { chatInterfaceContext } from "../ChatInterface";
|
import { chatInterfaceContext } from "../ChatInterface";
|
||||||
import type { GeneratePodcastRequest } from "./actions";
|
import type { GeneratePodcastRequest } from "./ChatPanelContainer";
|
||||||
|
|
||||||
interface ConfigModalProps {
|
interface ConfigModalProps {
|
||||||
generatePodcast: (request: GeneratePodcastRequest) => Promise<void>;
|
generatePodcast: (request: GeneratePodcastRequest) => Promise<void>;
|
||||||
|
|
@ -19,25 +19,25 @@ export function ConfigModal(props: ConfigModalProps) {
|
||||||
const { chatDetails } = context;
|
const { chatDetails } = context;
|
||||||
const { generatePodcast } = props;
|
const { generatePodcast } = props;
|
||||||
|
|
||||||
|
const [podcastTitle, setPodcastTitle] = useState(chatDetails?.title);
|
||||||
|
|
||||||
const handleGeneratePost = useCallback(async () => {
|
const handleGeneratePost = useCallback(async () => {
|
||||||
if (!chatDetails) return;
|
if (!chatDetails) return;
|
||||||
await generatePodcast({
|
await generatePodcast({
|
||||||
type: "CHAT",
|
type: "CHAT",
|
||||||
ids: [chatDetails.id],
|
ids: [chatDetails.id],
|
||||||
search_space_id: chatDetails.search_space_id,
|
search_space_id: chatDetails.search_space_id,
|
||||||
podcast_title: chatDetails.title,
|
podcast_title: podcastTitle,
|
||||||
});
|
});
|
||||||
}, [chatDetails]);
|
}, [chatDetails, podcastTitle]);
|
||||||
return (
|
return (
|
||||||
<Popover>
|
<Popover>
|
||||||
<PopoverTrigger>
|
<PopoverTrigger
|
||||||
<button
|
title="Edit the prompt"
|
||||||
type="button"
|
className="rounded-full p-2 bg-slate-400/30 hover:bg-slate-400/40"
|
||||||
title="Edit the prompt"
|
onClick={(e) => e.stopPropagation()}
|
||||||
className="rounded-full p-2 bg-slate-400/30 hover:bg-slate-400/40"
|
>
|
||||||
>
|
<Pencil strokeWidth={1} className="h-4 w-4" />
|
||||||
<Pencil strokeWidth={1} className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent align="end" className="bg-sidebar w-96 ">
|
<PopoverContent 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">
|
||||||
|
|
@ -48,8 +48,9 @@ export function ConfigModal(props: ConfigModalProps) {
|
||||||
<textarea
|
<textarea
|
||||||
name="prompt"
|
name="prompt"
|
||||||
id="prompt"
|
id="prompt"
|
||||||
defaultValue={chatDetails?.title}
|
defaultValue={podcastTitle}
|
||||||
className="w-full rounded-md border border-slate-400/40 p-2"
|
className="w-full rounded-md border border-slate-400/40 p-2"
|
||||||
|
onChange={(e) => setPodcastTitle(e.target.value)}
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue