@@ -4,9 +4,10 @@ import { Card, CardHeader, CardContent, CardFooter } from "@/components/ui/card"
4
4
import { Avatar , AvatarImage , AvatarFallback } from "@/components/ui/avatar" ;
5
5
import { Input } from "@/components/ui/input" ;
6
6
import { wait } from "@/utils/utils" ;
7
- import { useChat } from "ai/react" ;
7
+
8
8
import { v4 as uuidv4 } from "uuid" ;
9
9
import { useFlags , useLDClient } from "launchdarkly-react-client-sdk" ;
10
+ import { BeatLoader } from "react-spinners" ;
10
11
11
12
//https://sdk.vercel.ai/providers/legacy-providers/aws-bedrock
12
13
export default function Chatbot ( ) {
@@ -19,21 +20,24 @@ export default function Chatbot() {
19
20
const handleInputChange2 = ( e : any ) => {
20
21
setInput2 ( e . target . value ) ;
21
22
} ;
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
- // });
26
23
27
24
async function submitQuery ( ) {
28
25
const userInput = input2 ;
29
26
setInput2 ( "" ) ;
27
+ setIsLoading ( true ) ;
30
28
const userMessage = {
31
29
role : "user" ,
32
30
content : userInput ,
33
31
id : uuidv4 ( ) . slice ( 0 , 4 ) ,
34
32
} ;
35
33
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 ] ) ;
37
41
38
42
const response = await fetch ( "/api/chat" , {
39
43
method : "POST" ,
@@ -58,7 +62,7 @@ export default function Chatbot() {
58
62
} ;
59
63
setMessages2 ( [ ...messages2 , userMessage , assistantMessage ] ) ;
60
64
61
- return data ;
65
+ setIsLoading ( false ) ;
62
66
}
63
67
64
68
useEffect ( ( ) => {
@@ -152,6 +156,17 @@ export default function Chatbot() {
152
156
) ;
153
157
}
154
158
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
+
155
170
return (
156
171
< div
157
172
key = { m ?. id }
0 commit comments