fix(chat): add history loading skeletons
This commit is contained in:
@@ -27,6 +27,7 @@ export const useAgentChatSession = ({
|
||||
const [chatSessions, setChatSessions] = useState<ChatSessionSummary[]>([]);
|
||||
const [isStreaming, setIsStreaming] = useState(false);
|
||||
const [isHydrating, setIsHydrating] = useState(true);
|
||||
const [loadingSessionId, setLoadingSessionId] = useState<string | undefined>(undefined);
|
||||
const abortRef = useRef<AbortController | null>(null);
|
||||
const sessionIdRef = useRef<string | undefined>(undefined);
|
||||
const messagesRef = useRef<Message[]>([]);
|
||||
@@ -756,12 +757,17 @@ export const useAgentChatSession = ({
|
||||
}, [isHydrating, isStreaming]);
|
||||
|
||||
const switchSession = useCallback(
|
||||
async (nextSessionId: string) => {
|
||||
async (nextSessionId: string, optimisticTitle?: string) => {
|
||||
if (isHydrating || isStreaming || sessionIdRef.current === nextSessionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
setIsHydrating(true);
|
||||
setLoadingSessionId(nextSessionId);
|
||||
const nextTitle = optimisticTitle?.trim();
|
||||
if (nextTitle) {
|
||||
setSessionTitle(nextTitle);
|
||||
}
|
||||
try {
|
||||
const [nextState, sessions] = await Promise.all([
|
||||
loadChatSessionById(nextSessionId),
|
||||
@@ -785,6 +791,7 @@ export const useAgentChatSession = ({
|
||||
} catch (error) {
|
||||
console.error("[GlobalChatbox] Failed to switch chat session:", error);
|
||||
} finally {
|
||||
setLoadingSessionId(undefined);
|
||||
setIsHydrating(false);
|
||||
}
|
||||
},
|
||||
@@ -932,6 +939,7 @@ export const useAgentChatSession = ({
|
||||
chatSessions,
|
||||
activeSessionId: sessionIdRef.current,
|
||||
isHydrating,
|
||||
loadingSessionId,
|
||||
isStreaming,
|
||||
sessionTitle,
|
||||
sessionId,
|
||||
|
||||
Reference in New Issue
Block a user