mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-22 23:31:12 +02:00
- Updated all hooks to import and use AUTH_TOKEN_KEY constant from lib/constants - Updated all components to use AUTH_TOKEN_KEY instead of hardcoded string - Updated all atoms to use AUTH_TOKEN_KEY - Updated all app pages to use AUTH_TOKEN_KEY - Made CORS origin configurable via CORS_ORIGINS environment variable - Added CORS_ORIGINS to .env.example with documentation This improves maintainability by centralizing the auth token key string, preventing typos and making it easier to change the key name if needed.
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
"use client";
|
|
import { useAtom, useAtomValue } from "jotai";
|
|
import { LoaderIcon, PanelRight, TriangleAlert } from "lucide-react";
|
|
import { toast } from "sonner";
|
|
import { activeChatAtom, activeChatIdAtom } from "@/atoms/chats/chat-querie.atoms";
|
|
import { activeChathatUIAtom } from "@/atoms/chats/ui.atoms";
|
|
import { generatePodcast } from "@/lib/apis/podcasts.api";
|
|
import { cn } from "@/lib/utils";
|
|
import { ChatPanelView } from "./ChatPanelView";
|
|
import { AUTH_TOKEN_KEY } from "@/lib/constants";
|
|
|
|
export interface GeneratePodcastRequest {
|
|
type: "CHAT" | "DOCUMENT";
|
|
ids: number[];
|
|
search_space_id: number;
|
|
podcast_title?: string;
|
|
user_prompt?: string;
|
|
}
|
|
|
|
export function ChatPanelContainer() {
|
|
const {
|
|
data: activeChatState,
|
|
isLoading: isChatLoading,
|
|
error: chatError,
|
|
} = useAtomValue(activeChatAtom);
|
|
const activeChatIdState = useAtomValue(activeChatIdAtom);
|
|
const authToken = localStorage.getItem(AUTH_TOKEN_KEY);
|
|
const { isChatPannelOpen } = useAtomValue(activeChathatUIAtom);
|
|
|
|
const handleGeneratePodcast = async (request: GeneratePodcastRequest) => {
|
|
try {
|
|
if (!authToken) {
|
|
throw new Error("Authentication error. Please log in again.");
|
|
}
|
|
await generatePodcast(request, authToken);
|
|
toast.success(`Podcast generation started!`);
|
|
} catch (error) {
|
|
toast.error("Error generating podcast. Please log in again.");
|
|
console.error("Error generating podcast:", error);
|
|
}
|
|
};
|
|
|
|
return activeChatIdState ? (
|
|
<div
|
|
className={cn(
|
|
"shrink-0 bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 flex flex-col h-full transition-all",
|
|
isChatPannelOpen ? "w-96" : "w-0"
|
|
)}
|
|
>
|
|
{isChatLoading || chatError ? (
|
|
<div className="border-b p-2">
|
|
{isChatLoading ? (
|
|
<div title="Loading chat" className="flex items-center justify-center h-full">
|
|
<LoaderIcon strokeWidth={1.5} className="h-5 w-5 animate-spin" />
|
|
</div>
|
|
) : chatError ? (
|
|
<div title="Failed to load chat" className="flex items-center justify-center h-full">
|
|
<TriangleAlert strokeWidth={1.5} className="h-5 w-5 text-red-600" />
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
) : null}
|
|
|
|
{!isChatLoading && !chatError && activeChatState?.chatDetails && (
|
|
<ChatPanelView generatePodcast={handleGeneratePodcast} />
|
|
)}
|
|
</div>
|
|
) : null;
|
|
}
|