From f93f8cb6ba14b412471fc7b8b98bafd736688699 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 10 Jun 2025 12:19:47 +0600 Subject: [PATCH] wip --- .../AIChatHistory/AIChatHistory.tsx | 54 +++++++++++++------ .../AIChatHistory/ListChatHistory.tsx | 38 ++++++++++++- .../AIChatHistory/ListChatHistorySkeleton.tsx | 6 +++ 3 files changed, 80 insertions(+), 18 deletions(-) diff --git a/src/components/AIChatHistory/AIChatHistory.tsx b/src/components/AIChatHistory/AIChatHistory.tsx index f365cc26c..790d3317c 100644 --- a/src/components/AIChatHistory/AIChatHistory.tsx +++ b/src/components/AIChatHistory/AIChatHistory.tsx @@ -18,6 +18,7 @@ export function AIChatHistory(props: AIChatHistoryProps) { const [keyTrigger, setKeyTrigger] = useState(0); const [isLoading, setIsLoading] = useState(true); + const [isChatHistoryLoading, setIsChatHistoryLoading] = useState(true); const [chatHistoryId, setChatHistoryId] = useState( defaultChatHistoryId || undefined, ); @@ -35,7 +36,8 @@ export function AIChatHistory(props: AIChatHistoryProps) { useEffect(() => { if (!defaultChatHistoryId) { - return setIsLoading(false); + setIsLoading(false); + return; } if (!data) { @@ -43,6 +45,7 @@ export function AIChatHistory(props: AIChatHistoryProps) { } setIsLoading(false); + setIsChatHistoryLoading(false); }, [data, defaultChatHistoryId]); const isDataLoading = isLoading || isBillingDetailsLoading; @@ -85,7 +88,16 @@ export function AIChatHistory(props: AIChatHistoryProps) { return; } - setIsLoading(true); + // 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, @@ -106,21 +118,29 @@ export function AIChatHistory(props: AIChatHistoryProps) { /> )} -
- { - setChatHistoryId(id); - window.history.replaceState(null, '', `/ai/chat/${id}`); - queryClient.invalidateQueries({ - predicate: (query) => { - return query.queryKey[0] === 'list-chat-history'; - }, - }); - }} - /> +
+ {isChatHistoryLoading && ( +
+ +
+ )} + + {!isChatHistoryLoading && ( + { + setChatHistoryId(id); + window.history.replaceState(null, '', `/ai/chat/${id}`); + queryClient.invalidateQueries({ + predicate: (query) => { + return query.queryKey[0] === 'list-chat-history'; + }, + }); + }} + /> + )}
)} diff --git a/src/components/AIChatHistory/ListChatHistory.tsx b/src/components/AIChatHistory/ListChatHistory.tsx index d4cc41689..39de0587d 100644 --- a/src/components/AIChatHistory/ListChatHistory.tsx +++ b/src/components/AIChatHistory/ListChatHistory.tsx @@ -8,6 +8,8 @@ import { ChatHistoryItem } from './ChatHistoryItem'; import { AlertCircleIcon, Loader2Icon, + PanelLeftCloseIcon, + PanelLeftIcon, PlusIcon, SearchIcon, } from 'lucide-react'; @@ -16,6 +18,7 @@ import { useEffect, useMemo, useState } from 'react'; import { useDebounceValue } from '../../hooks/use-debounce'; import { ListChatHistorySkeleton } from './ListChatHistorySkeleton'; import { ChatHistoryError } from './ChatHistoryError'; +import { cn } from '../../lib/classname'; type ListChatHistoryProps = { activeChatHistoryId?: string; @@ -26,6 +29,7 @@ type ListChatHistoryProps = { export function ListChatHistory(props: ListChatHistoryProps) { const { activeChatHistoryId, onChatHistoryClick, onDelete } = props; + const [isOpen, setIsOpen] = useState(true); const [query, setQuery] = useState(''); const { data, @@ -79,13 +83,45 @@ export function ListChatHistory(props: ListChatHistoryProps) { ); }, [data?.pages]); + if (!isOpen) { + return ( +
+ +
+ ); + } + return ( -
+
{isLoading && } {!isLoading && isError && } {!isLoading && !isError && ( <> +
+

Chat History

+ +
+