From 0139d7c2ddee7dbdbaf71162e3481adff7a18595 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 25 Dec 2025 06:11:14 -0600 Subject: [PATCH] Chat history loading skeleton in ChatPane --- src/components/Shakespeare/ChatPane.tsx | 52 +++++++++++++++++++++++-- src/hooks/useAIChat.ts | 23 +++++++---- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/components/Shakespeare/ChatPane.tsx b/src/components/Shakespeare/ChatPane.tsx index 7b4ba44f..039ea930 100644 --- a/src/components/Shakespeare/ChatPane.tsx +++ b/src/components/Shakespeare/ChatPane.tsx @@ -288,6 +288,7 @@ export const ChatPane = forwardRef(({ messages, streamingMessage, isLoading: internalIsLoading, + isLoadingHistory, totalCost, lastInputTokens, addMessage, @@ -701,8 +702,53 @@ export const ChatPane = forwardRef(({ )} + {/* Loading skeleton while loading history */} + {isLoadingHistory && ( +
+ {/* User message skeleton */} +
+
+
+ + +
+
+
+ + {/* Assistant message skeleton */} +
+
+
+ + + +
+
+
+ + {/* Another user message skeleton */} +
+
+
+ +
+
+
+ + {/* Another assistant message skeleton */} +
+
+
+ + +
+
+
+
+ )} + {/* Empty state when no messages and not loading */} - {messages.length === 0 && !streamingMessage && !isLoading && ( + {!isLoadingHistory && messages.length === 0 && !streamingMessage && !isLoading && (
@@ -726,7 +772,7 @@ export const ChatPane = forwardRef(({
)} - {messages.map((message, index) => { + {!isLoadingHistory && messages.map((message, index) => { // Find the corresponding tool call for tool messages let toolCall: OpenAI.Chat.Completions.ChatCompletionMessageToolCall | undefined = undefined; if (message.role === 'tool') { @@ -749,7 +795,7 @@ export const ChatPane = forwardRef(({ ); })} - {renderStreamingMessage()} + {!isLoadingHistory && renderStreamingMessage()} {/* Error Alert (Console or AI) - Don't show while assistant is loading */} {displayError && !isLoading && ( diff --git a/src/hooks/useAIChat.ts b/src/hooks/useAIChat.ts index 74ac1435..925b8317 100644 --- a/src/hooks/useAIChat.ts +++ b/src/hooks/useAIChat.ts @@ -43,16 +43,22 @@ export function useAIChat({ const [isLoading, setIsLoading] = useState(false); const [totalCost, setTotalCost] = useState(0); const [lastInputTokens, setLastInputTokens] = useState(0); + const [isLoadingHistory, setIsLoadingHistory] = useState(true); const initSession = useCallback(async () => { - // Load or update session - const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps); - // Initialize individual state variables from existing session - setMessages([...session.messages]); - setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined); - setIsLoading(session.isLoading); - setTotalCost(session.totalCost || 0); - setLastInputTokens(session.lastInputTokens || 0); + setIsLoadingHistory(true); + try { + // Load or update session + const session = await sessionManager.loadSession(projectId, tools, customTools, maxSteps); + // Initialize individual state variables from existing session + setMessages([...session.messages]); + setStreamingMessage(session.streamingMessage ? { ...session.streamingMessage } : undefined); + setIsLoading(session.isLoading); + setTotalCost(session.totalCost || 0); + setLastInputTokens(session.lastInputTokens || 0); + } finally { + setIsLoadingHistory(false); + } }, [sessionManager, projectId, tools, customTools, maxSteps]); // Initialize session @@ -166,6 +172,7 @@ export function useAIChat({ messages, streamingMessage, isLoading, + isLoadingHistory, totalCost, lastInputTokens, sendMessage,