From ab888e8f738df176e87e972e5f59a0355b6ed2e5 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Wed, 11 Jun 2025 14:45:20 +0100 Subject: [PATCH] Chat history UI --- .../AIChatHistory/AIChatHistory.tsx | 160 +++++++++--------- 1 file changed, 81 insertions(+), 79 deletions(-) diff --git a/src/components/AIChatHistory/AIChatHistory.tsx b/src/components/AIChatHistory/AIChatHistory.tsx index 12982c9f2..1f365b623 100644 --- a/src/components/AIChatHistory/AIChatHistory.tsx +++ b/src/components/AIChatHistory/AIChatHistory.tsx @@ -61,91 +61,93 @@ export function AIChatHistory(props: AIChatHistoryProps) { setIsChatHistoryLoading(false); }, [hasError]); + if (isLoading || isBillingDetailsLoading) { + return ( + +
+
+ +
+
+
+ ); + } + return (
- {showGlobalLoader && ( -
- -
+ {isPaidUser && ( + { + setKeyTrigger((keyTrigger) => keyTrigger + 1); + + if (chatHistoryId === null) { + setChatHistoryId(undefined); + window.history.replaceState(null, '', '/ai/chat'); + return; + } + + // so that we can show the loading state when the chat history is not fetched yet + // it will help us to avoid the flash of content + const hasAlreadyFetched = queryClient.getQueryData( + chatHistoryOptions(chatHistoryId).queryKey, + ); + + if (!hasAlreadyFetched) { + setIsChatHistoryLoading(true); + } + + setChatHistoryId(chatHistoryId); + window.history.replaceState( + null, + '', + `/ai/chat/${chatHistoryId}`, + ); + }} + onDelete={(deletedChatHistoryId) => { + const isCurrentChatHistory = + deletedChatHistoryId === chatHistoryId; + if (!isCurrentChatHistory) { + return; + } + + setChatHistoryId(undefined); + window.history.replaceState(null, '', '/ai/chat'); + }} + /> )} - {!showGlobalLoader && ( - <> - {isPaidUser && ( - { - setKeyTrigger((keyTrigger) => keyTrigger + 1); - - if (chatHistoryId === null) { - setChatHistoryId(undefined); - window.history.replaceState(null, '', '/ai/chat'); - return; - } - - // so that we can show the loading state when the chat history is not fetched yet - // it will help us to avoid the flash of content - const hasAlreadyFetched = queryClient.getQueryData( - chatHistoryOptions(chatHistoryId).queryKey, - ); - - if (!hasAlreadyFetched) { - setIsChatHistoryLoading(true); - } - - setChatHistoryId(chatHistoryId); - window.history.replaceState( - null, - '', - `/ai/chat/${chatHistoryId}`, - ); - }} - onDelete={(deletedChatHistoryId) => { - const isCurrentChatHistory = - deletedChatHistoryId === chatHistoryId; - if (!isCurrentChatHistory) { - return; - } - - setChatHistoryId(undefined); - window.history.replaceState(null, '', '/ai/chat'); - }} - /> - )} - -
- {isChatHistoryLoading && !hasError && ( -
- -
- )} - - {!isChatHistoryLoading && hasError && ( -
- -
- )} - - {!isChatHistoryLoading && !hasError && ( - { - setChatHistoryId(id); - window.history.replaceState(null, '', `/ai/chat/${id}`); - queryClient.invalidateQueries({ - predicate: (query) => { - return query.queryKey[0] === 'list-chat-history'; - }, - }); - }} - /> - )} +
+ {isChatHistoryLoading && !hasError && ( +
+
- - )} + )} + + {!isChatHistoryLoading && hasError && ( +
+ +
+ )} + + {!isChatHistoryLoading && !hasError && ( + { + setChatHistoryId(id); + window.history.replaceState(null, '', `/ai/chat/${id}`); + queryClient.invalidateQueries({ + predicate: (query) => { + return query.queryKey[0] === 'list-chat-history'; + }, + }); + }} + /> + )} +
);