Skip to content

Commit 7f25cee

Browse files
committed
loader
1 parent 6e086f5 commit 7f25cee

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

components/chatbot/ChatBot.tsx

+22-7
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Card, CardHeader, CardContent, CardFooter } from "@/components/ui/card"
44
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
55
import { Input } from "@/components/ui/input";
66
import { wait } from "@/utils/utils";
7-
import { useChat } from "ai/react";
7+
88
import { v4 as uuidv4 } from "uuid";
99
import { useFlags, useLDClient } from "launchdarkly-react-client-sdk";
10+
import { BeatLoader } from "react-spinners";
1011

1112
//https://sdk.vercel.ai/providers/legacy-providers/aws-bedrock
1213
export default function Chatbot() {
@@ -19,21 +20,24 @@ export default function Chatbot() {
1920
const handleInputChange2 = (e: any) => {
2021
setInput2(e.target.value);
2122
};
22-
// const { messages, input, handleInputChange, handleSubmit } = useChat({
23-
// api: "/api/bedrock",
24-
// initialInput: "Where is a good vacation place for under $1000? Limit to 100 characters.",
25-
// });
2623

2724
async function submitQuery() {
2825
const userInput = input2;
2926
setInput2("");
27+
setIsLoading(true);
3028
const userMessage = {
3129
role: "user",
3230
content: userInput,
3331
id: uuidv4().slice(0, 4),
3432
};
3533

36-
setMessages2([...messages2, userMessage]);
34+
const loadingMessage = {
35+
role: "loader",
36+
content: "loading",
37+
id: uuidv4().slice(0, 4),
38+
};
39+
40+
setMessages2([...messages2, userMessage, loadingMessage]);
3741

3842
const response = await fetch("/api/chat", {
3943
method: "POST",
@@ -58,7 +62,7 @@ export default function Chatbot() {
5862
};
5963
setMessages2([...messages2, userMessage, assistantMessage]);
6064

61-
return data;
65+
setIsLoading(false);
6266
}
6367

6468
useEffect(() => {
@@ -152,6 +156,17 @@ export default function Chatbot() {
152156
);
153157
}
154158

159+
if (m?.role === "loader" && isLoading) {
160+
return (
161+
<div
162+
key={m?.id}
163+
className="flex w-max max-w-[75%] flex-col gap-2 rounded-lg px-3 py-2 text-sm bg-gray-100 dark:bg-gray-800"
164+
>
165+
<BeatLoader className="" />
166+
</div>
167+
);
168+
}
169+
155170
return (
156171
<div
157172
key={m?.id}

0 commit comments

Comments
 (0)