Skip to content

Commit 5795b93

Browse files
committed
loading when query sent to chat
Signed-off-by: RAWx18 <[email protected]>
1 parent c94289e commit 5795b93

File tree

2 files changed

+58
-33
lines changed

2 files changed

+58
-33
lines changed

src/frontend/components/chat-section.tsx

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,58 @@ import React, { useRef, useEffect } from 'react';
22
import { Message } from '@/lib/types';
33
import ChatRequest from './chat-request';
44
import ChatResponse from './chat-response';
5+
import ThinkingAnimation from './thinking-animation';
56

67
interface ChatSectionProps {
7-
messages: Message[];
8+
messages: Message[];
89
}
910

1011
const ChatSection: React.FC<ChatSectionProps> = ({
11-
messages
12+
messages
1213
}) => {
13-
const chatContainerRef =
14-
useRef<HTMLDivElement>(null);
14+
const chatContainerRef = useRef<HTMLDivElement>(null);
15+
const lastMessageIsUser = messages.length > 0 && messages[messages.length - 1].type === 0;
1516

16-
useEffect(() => {
17-
if (chatContainerRef.current) {
18-
chatContainerRef.current.scrollTop =
19-
chatContainerRef.current.scrollHeight;
20-
}
21-
}, [messages]);
17+
useEffect(() => {
18+
if (chatContainerRef.current) {
19+
chatContainerRef.current.scrollTop = chatContainerRef.current.scrollHeight;
20+
}
21+
}, [messages]);
2222

23-
return (
24-
<div className="relative flex flex-col items-center py-2">
25-
<div
26-
className="flex flex-col max-w-3xl w-full flex-grow space-y-2"
27-
ref={chatContainerRef}
28-
>
29-
{messages.map((message, index) => (
30-
<div key={message.id}>
31-
{message.type === 0 ? (
32-
<ChatRequest
33-
request={message.content}
34-
/>
35-
) : (
36-
<ChatResponse
37-
message={message}
38-
/>
39-
)}
40-
</div>
41-
))}
42-
</div>
43-
</div>
44-
);
23+
return (
24+
<div className="relative flex flex-col items-center py-2 h-full overflow-y-auto">
25+
<div
26+
className="flex flex-col max-w-3xl w-full flex-grow space-y-2"
27+
ref={chatContainerRef}
28+
>
29+
{messages.map((message, index) => (
30+
<div key={message.id}>
31+
{message.type === 0 ? (
32+
<ChatRequest
33+
request={message.content}
34+
/>
35+
) : (
36+
<ChatResponse
37+
message={message}
38+
/>
39+
)}
40+
</div>
41+
))}
42+
43+
{/* Show thinking animation when last message is from user */}
44+
{lastMessageIsUser && (
45+
<div className="flex flex-row space-x-4 p-4">
46+
<div className="h-10 w-10 rounded-full border shrink-0 p-2 bg-background flex items-center justify-center">
47+
<ThinkingAnimation />
48+
</div>
49+
<div className="flex items-center">
50+
<p className="text-muted-foreground">AIFAQ is thinking...</p>
51+
</div>
52+
</div>
53+
)}
54+
</div>
55+
</div>
56+
);
4557
};
4658

47-
export default ChatSection;
59+
export default ChatSection;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
const ThinkingAnimation = () => {
4+
return (
5+
<div className="flex space-x-1 justify-center items-center">
6+
<div className="h-2 w-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: '0ms' }}></div>
7+
<div className="h-2 w-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: '150ms' }}></div>
8+
<div className="h-2 w-2 bg-primary rounded-full animate-bounce" style={{ animationDelay: '300ms' }}></div>
9+
</div>
10+
);
11+
};
12+
13+
export default ThinkingAnimation;

0 commit comments

Comments
 (0)