mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 06:12:53 +02:00
wip
This commit is contained in:
@@ -49,7 +49,7 @@ export function AIChatHistory(props: AIChatHistoryProps) {
|
|||||||
setIsChatHistoryLoading(false);
|
setIsChatHistoryLoading(false);
|
||||||
}, [data, chatHistoryId]);
|
}, [data, chatHistoryId]);
|
||||||
|
|
||||||
const isDataLoading = isLoading || isBillingDetailsLoading;
|
const showGlobalLoader = isLoading || isBillingDetailsLoading;
|
||||||
const hasError = chatHistoryError || billingDetailsError;
|
const hasError = chatHistoryError || billingDetailsError;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -58,24 +58,19 @@ export function AIChatHistory(props: AIChatHistoryProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
setIsChatHistoryLoading(false);
|
||||||
}, [hasError]);
|
}, [hasError]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AIChatLayout>
|
<AIChatLayout>
|
||||||
<div className="relative flex grow">
|
<div className="relative flex grow">
|
||||||
{isDataLoading && !hasError && (
|
{showGlobalLoader && (
|
||||||
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
||||||
<Loader2Icon className="h-8 w-8 animate-spin stroke-[2.5]" />
|
<Loader2Icon className="h-8 w-8 animate-spin stroke-[2.5]" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isDataLoading && hasError && (
|
{!showGlobalLoader && (
|
||||||
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
|
||||||
<ChatHistoryError error={hasError} className="mt-0" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isDataLoading && !hasError && (
|
|
||||||
<>
|
<>
|
||||||
{isPaidUser && (
|
{isPaidUser && (
|
||||||
<ListChatHistory
|
<ListChatHistory
|
||||||
@@ -120,13 +115,19 @@ export function AIChatHistory(props: AIChatHistoryProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="relative flex grow">
|
<div className="relative flex grow">
|
||||||
{isChatHistoryLoading && (
|
{isChatHistoryLoading && !hasError && (
|
||||||
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
||||||
<Loader2Icon className="h-8 w-8 animate-spin stroke-[2.5]" />
|
<Loader2Icon className="h-8 w-8 animate-spin stroke-[2.5]" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isChatHistoryLoading && (
|
{!isChatHistoryLoading && hasError && (
|
||||||
|
<div className="absolute inset-0 z-20 flex items-center justify-center">
|
||||||
|
<ChatHistoryError error={hasError} className="mt-0" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isChatHistoryLoading && !hasError && (
|
||||||
<AIChat
|
<AIChat
|
||||||
key={keyTrigger}
|
key={keyTrigger}
|
||||||
messages={data?.messages}
|
messages={data?.messages}
|
||||||
|
@@ -30,18 +30,27 @@ export function ListChatHistory(props: ListChatHistoryProps) {
|
|||||||
const { activeChatHistoryId, onChatHistoryClick, onDelete } = props;
|
const { activeChatHistoryId, onChatHistoryClick, onDelete } = props;
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(true);
|
const [isOpen, setIsOpen] = useState(true);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data,
|
data,
|
||||||
fetchNextPage,
|
fetchNextPage,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
isFetchingNextPage,
|
isFetchingNextPage,
|
||||||
isLoading,
|
|
||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
refetch,
|
isLoading: isLoadingInfiniteQuery,
|
||||||
} = useInfiniteQuery(listChatHistoryOptions({ query }), queryClient);
|
} = useInfiniteQuery(listChatHistoryOptions({ query }), queryClient);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(false);
|
||||||
|
}, [data?.pages]);
|
||||||
|
|
||||||
const groupedChatHistory = useMemo(() => {
|
const groupedChatHistory = useMemo(() => {
|
||||||
const today = DateTime.now().startOf('day');
|
const today = DateTime.now().startOf('day');
|
||||||
const allHistories = data?.pages?.flatMap((page) => page.data);
|
const allHistories = data?.pages?.flatMap((page) => page.data);
|
||||||
@@ -85,7 +94,7 @@ export function ListChatHistory(props: ListChatHistoryProps) {
|
|||||||
|
|
||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
return (
|
return (
|
||||||
<div className="absolute top-1 left-1 z-20">
|
<div className="absolute top-2 left-2 z-20">
|
||||||
<button
|
<button
|
||||||
className="flex size-8 items-center justify-center rounded-lg p-1 hover:bg-gray-200"
|
className="flex size-8 items-center justify-center rounded-lg p-1 hover:bg-gray-200"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
@@ -133,7 +142,10 @@ export function ListChatHistory(props: ListChatHistoryProps) {
|
|||||||
<span className="text-sm">New Chat</span>
|
<span className="text-sm">New Chat</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<SearchInput onSearch={setQuery} isLoading={isLoading} />
|
<SearchInput
|
||||||
|
onSearch={setQuery}
|
||||||
|
isLoading={isLoadingInfiniteQuery}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="scrollbar-track-transparent scrollbar-thin scrollbar-thumb-gray-300 -mx-2 mt-6 grow space-y-4 overflow-y-scroll px-2">
|
<div className="scrollbar-track-transparent scrollbar-thin scrollbar-thumb-gray-300 -mx-2 mt-6 grow space-y-4 overflow-y-scroll px-2">
|
||||||
|
@@ -87,7 +87,7 @@ export function listChatHistoryOptions(
|
|||||||
return httpGet<ListChatHistoryResponse>('/v1-list-chat-history', {
|
return httpGet<ListChatHistoryResponse>('/v1-list-chat-history', {
|
||||||
...(query?.query ? { query: query.query } : {}),
|
...(query?.query ? { query: query.query } : {}),
|
||||||
...(pageParam ? { currPage: pageParam } : {}),
|
...(pageParam ? { currPage: pageParam } : {}),
|
||||||
perPage: '21',
|
perPage: '2',
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
enabled: !!isLoggedIn(),
|
enabled: !!isLoggedIn(),
|
||||||
|
Reference in New Issue
Block a user