Skip to content

Commit 0d948aa

Browse files
authored
fix: move loading messages (#2879)
1 parent 65db8bb commit 0d948aa

File tree

2 files changed

+12
-11
lines changed
  • apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab

2 files changed

+12
-11
lines changed

apps/web/client/src/app/project/[id]/_components/right-panel/chat-tab/chat-tab-content/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type ChatMessage } from '@onlook/models';
2+
import { Icons } from '@onlook/ui/icons';
23
import { useChat } from '../../../../_hooks/use-chat';
34
import { ChatInput } from '../chat-input';
45
import { ChatMessages } from '../chat-messages';
@@ -8,12 +9,14 @@ interface ChatTabContentProps {
89
conversationId: string;
910
projectId: string;
1011
initialMessages: ChatMessage[];
12+
isLoadingMessages: boolean;
1113
}
1214

1315
export const ChatTabContent = ({
1416
conversationId,
1517
projectId,
1618
initialMessages,
19+
isLoadingMessages,
1720
}: ChatTabContentProps) => {
1821
const { isStreaming, sendMessage, editMessage, messages, error, stop, suggestions } = useChat({
1922
conversationId,
@@ -24,12 +27,17 @@ export const ChatTabContent = ({
2427
return (
2528
<div className="flex flex-col h-full justify-end gap-2 pt-2">
2629
<div className="h-full flex-1 overflow-y-auto">
27-
<ChatMessages
30+
{isLoadingMessages ? (
31+
<div className="flex-1 flex items-center justify-center w-full h-full text-foreground-secondary">
32+
<Icons.LoadingSpinner className="animate-spin mr-2" />
33+
<p>Loading messages...</p>
34+
</div>
35+
) : (<ChatMessages
2836
messages={messages}
2937
isStreaming={isStreaming}
3038
error={error}
3139
onEditMessage={editMessage}
32-
/>
40+
/>)}
3341
</div>
3442
<ErrorSection isStreaming={isStreaming} onSendMessage={sendMessage} />
3543
<ChatInput
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { api } from '@/trpc/react';
2-
import { Icons } from '@onlook/ui/icons';
32
import { ChatTabContent } from './chat-tab-content';
43

54
interface ChatTabProps {
@@ -8,25 +7,19 @@ interface ChatTabProps {
87
}
98

109
export const ChatTab = ({ conversationId, projectId }: ChatTabProps) => {
11-
const { data: initialMessages, isLoading } = api.chat.message.getAll.useQuery(
10+
const { data: initialMessages = [], isLoading } = api.chat.message.getAll.useQuery(
1211
{ conversationId: conversationId },
1312
{ enabled: !!conversationId },
1413
);
1514

16-
if (!initialMessages || isLoading) {
17-
return <div className="flex-1 flex items-center justify-center w-full h-full text-foreground-secondary">
18-
<Icons.LoadingSpinner className="animate-spin mr-2" />
19-
<p>Loading messages...</p>
20-
</div>
21-
}
22-
2315
return (
2416
<ChatTabContent
2517
// Used to force re-render the use-chat hook when the conversationId changes
2618
key={conversationId}
2719
conversationId={conversationId}
2820
projectId={projectId}
2921
initialMessages={initialMessages}
22+
isLoadingMessages={isLoading}
3023
/>
3124
);
3225
};

0 commit comments

Comments
 (0)