SurfSense/surfsense_web/hooks/use-chat.ts
Anish Sarkar 79e552520a refactor: remove old chat components and implement new sidebar structure
- Deleted `chats-client.tsx` and `page.tsx` as part of the chat management overhaul.
- Introduced `AllChatsSidebar` and `NavChats` components for improved chat navigation and management.
- Updated sidebar to integrate new chat components and removed the deprecated `NavProjects`.
- Enhanced chat deletion handling and added loading states for better user experience.
- Added new translation keys for chat-related UI strings.
2025-12-19 03:53:40 +05:30

43 lines
1.2 KiB
TypeScript

import { useEffect, useState } from "react";
import type { ResearchMode } from "@/components/chat";
import type { Document } from "@/contracts/types/document.types";
import { getBearerToken } from "@/lib/auth-utils";
interface UseChatStateProps {
search_space_id: string;
chat_id?: string;
}
export function useChatState({ chat_id }: UseChatStateProps) {
const [token, setToken] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [currentChatId, setCurrentChatId] = useState<string | null>(chat_id || null);
// Chat configuration state
const [researchMode, setResearchMode] = useState<ResearchMode>("QNA");
const [selectedConnectors, setSelectedConnectors] = useState<string[]>([]);
const [selectedDocuments, setSelectedDocuments] = useState<Document[]>([]);
const [topK, setTopK] = useState<number>(5);
useEffect(() => {
const bearerToken = getBearerToken();
setToken(bearerToken);
}, []);
return {
token,
setToken,
isLoading,
setIsLoading,
currentChatId,
setCurrentChatId,
researchMode,
setResearchMode,
selectedConnectors,
setSelectedConnectors,
selectedDocuments,
setSelectedDocuments,
topK,
setTopK,
};
}