From 71c23fca5c84d682e68551882ce857c9589c92fc Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 10 Jun 2025 11:39:10 +0600 Subject: [PATCH] wip --- .../AIChatHistory/ListChatHistory.tsx | 156 +++++++++++------- .../AIChatHistory/ListChatHistorySkeleton.tsx | 4 +- 2 files changed, 97 insertions(+), 63 deletions(-) diff --git a/src/components/AIChatHistory/ListChatHistory.tsx b/src/components/AIChatHistory/ListChatHistory.tsx index 599a1a0a3..37c781d55 100644 --- a/src/components/AIChatHistory/ListChatHistory.tsx +++ b/src/components/AIChatHistory/ListChatHistory.tsx @@ -5,7 +5,12 @@ import { } from '../../queries/chat-history'; import { queryClient } from '../../stores/query-client'; import { ChatHistoryItem } from './ChatHistoryItem'; -import { Loader2Icon, PlusIcon, SearchIcon } from 'lucide-react'; +import { + AlertCircleIcon, + Loader2Icon, + PlusIcon, + SearchIcon, +} from 'lucide-react'; import { DateTime } from 'luxon'; import { useEffect, useMemo, useState } from 'react'; import { useDebounceValue } from '../../hooks/use-debounce'; @@ -21,8 +26,16 @@ export function ListChatHistory(props: ListChatHistoryProps) { const { activeChatHistoryId, onChatHistoryClick, onDelete } = props; const [query, setQuery] = useState(''); - const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = - useInfiniteQuery(listChatHistoryOptions({ query }), queryClient); + const { + data, + fetchNextPage, + hasNextPage, + isFetchingNextPage, + isLoading, + isError, + error, + refetch, + } = useInfiniteQuery(listChatHistoryOptions({ query }), queryClient); const groupedChatHistory = useMemo(() => { const today = DateTime.now().startOf('day'); @@ -65,72 +78,75 @@ export function ListChatHistory(props: ListChatHistoryProps) { ); }, [data?.pages]); - if (isLoading) { - return ; - } - return (
- + {isLoading && } + {!isLoading && isError && } - - -
- {Object.entries(groupedChatHistory ?? {}).map(([key, value]) => { - if (value.histories.length === 0) { - return null; - } - - return ( -
-

{value.title}

- -
    - {value.histories.map((chatHistory) => { - return ( - { - onDelete?.(chatHistory._id); - }} - /> - ); - })} -
-
- ); - })} -
- - {hasNextPage && ( -
+ {!isLoading && !isError && ( + <> -
+ + + +
+ {Object.entries(groupedChatHistory ?? {}).map(([key, value]) => { + if (value.histories.length === 0) { + return null; + } + + return ( +
+

{value.title}

+ +
    + {value.histories.map((chatHistory) => { + return ( + { + onDelete?.(chatHistory._id); + }} + /> + ); + })} +
+
+ ); + })} +
+ + {hasNextPage && ( +
+ +
+ )} + )}
); @@ -180,3 +196,21 @@ function SearchInput(props: SearchInputProps) { ); } + +type ErrorStateProps = { + error: Error | null; +}; + +function ErrorState(props: ErrorStateProps) { + const { error } = props; + + return ( +
+ +

+ Something went wrong +

+

{error?.message}

+
+ ); +} diff --git a/src/components/AIChatHistory/ListChatHistorySkeleton.tsx b/src/components/AIChatHistory/ListChatHistorySkeleton.tsx index 070810d5b..add21017a 100644 --- a/src/components/AIChatHistory/ListChatHistorySkeleton.tsx +++ b/src/components/AIChatHistory/ListChatHistorySkeleton.tsx @@ -1,6 +1,6 @@ export function ListChatHistorySkeleton() { return ( -
+ <>
@@ -25,6 +25,6 @@ export function ListChatHistorySkeleton() {
))}
-
+ ); }