DocDoeAI / src /components /study-chat /useChatSessions.ts
asnannp's picture
deploy: sync backend to Space root (learn-lesson HF cache fix)
65d68f5
Raw History Blame Contribute Delete
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,
};
}