Download src/components/study-chat/useChatSessions.ts from asnannp/DocDoeAI: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/components/study-chat/useChatSessions.ts
- Command line
-
hf download hf://spaces/asnannp/DocDoeAI/src/components/study-chat/useChatSessions.ts
-
curl -L -o useChatSessions.ts https://huggingface.co/spaces/asnannp/DocDoeAI/resolve/main/src/components/study-chat/useChatSessions.ts
916 Bytes
| "use client"; | |
| import { useCallback, useState } from "react"; | |
| import { listChatSessions, type ChatSessionOut } from "@/lib/api/chatHistory"; | |
| import { listLocalChatSessions } from "./local-chat-history"; | |
| export function useChatSessions() { | |
| const [chatSessions, setChatSessions] = useState<ChatSessionOut[]>([]); | |
| const [isHistoryLoading, setIsHistoryLoading] = useState(false); | |
| const [activeSessionId, setActiveSessionId] = useState<string | null>(null); | |
| const refreshChatHistory = useCallback(async () => { | |
| setIsHistoryLoading(true); | |
| try { | |
| const sessions = await listChatSessions(); | |
| setChatSessions(sessions); | |
| } catch { | |
| setChatSessions(listLocalChatSessions()); | |
| } finally { | |
| setIsHistoryLoading(false); | |
| } | |
| }, []); | |
| return { | |
| chatSessions, | |
| setChatSessions, | |
| isHistoryLoading, | |
| activeSessionId, | |
| setActiveSessionId, | |
| refreshChatHistory, | |
| }; | |
| } | |