|
1 |
| -"use client"; |
| 1 | +'use client'; |
2 | 2 |
|
3 |
| -import { scrollToBottom, initialMessages, getSources } from "@/lib/utils"; |
4 |
| -import { ChatLine } from "./chat-line"; |
5 |
| -import { useChat, Message } from "ai-stream-experimental/react"; |
6 |
| -import { Input } from "@/components/ui/input"; |
7 |
| -import { Button } from "@/components/ui/button"; |
8 |
| -import { Spinner } from "@/components/ui/spinner"; |
9 |
| -import { useEffect, useRef } from "react"; |
| 3 | +import React, { useEffect, useRef } from 'react'; |
| 4 | +import { Message, useChat } from 'ai-stream-experimental/react'; |
| 5 | +import { LuSend } from 'react-icons/lu'; |
| 6 | + |
| 7 | +import { getSources, initialMessages, scrollToBottom } from '@/lib/utils'; |
| 8 | +import { Button } from '@/components/ui/button'; |
| 9 | +import { Input } from '@/components/ui/input'; |
| 10 | +import { Spinner } from '@/components/ui/spinner'; |
| 11 | + |
| 12 | +import { ChatLine } from './chat-line'; |
10 | 13 |
|
11 | 14 | export function Chat() {
|
12 |
| -const containerRef = useRef<HTMLDivElement | null>(null); |
13 |
| -const { messages, input, handleInputChange, handleSubmit, isLoading, data } = |
| 15 | + const containerRef = useRef<HTMLDivElement | null>(null); |
| 16 | + const { messages, input, handleInputChange, handleSubmit, isLoading, data } = |
14 | 17 | useChat({
|
15 |
| - initialMessages: initialMessages.map((message) => ({ |
16 |
| - ...message, |
17 |
| - role: message.role as "function" | "system" | "user" | "assistant", |
18 |
| - })), |
| 18 | + initialMessages: initialMessages.map((message) => ({ |
| 19 | + ...message, |
| 20 | + role: message.role as 'function' | 'system' | 'user' | 'assistant', |
| 21 | + })), |
19 | 22 | });
|
20 | 23 |
|
21 |
| -useEffect(() => { |
| 24 | + useEffect(() => { |
22 | 25 | setTimeout(() => scrollToBottom(containerRef), 100);
|
23 |
| -}, [messages]); |
| 26 | + }, [messages]); |
24 | 27 |
|
25 | 28 | return (
|
26 |
| - <div className="rounded-2xl border h-[75vh] flex flex-col justify-between"> |
27 |
| - <div className="p-6 overflow-auto" ref={containerRef}> |
| 29 | + <div className=" flex h-[100vh] flex-col justify-between bg-gradient-to-l from-green-900 to-green-900 text-white"> |
| 30 | + <div className="flex-grow overflow-auto px-44 py-32" ref={containerRef}> |
28 | 31 | {messages.map(({ id, role, content }: Message, index) => (
|
29 | 32 | <ChatLine
|
30 | 33 | key={id}
|
31 | 34 | role={role}
|
32 | 35 | content={content}
|
33 |
| - // Start from the third message of the assistant |
34 | 36 | sources={data?.length ? getSources(data, role, index) : []}
|
35 | 37 | />
|
36 | 38 | ))}
|
37 | 39 | </div>
|
38 | 40 |
|
39 |
| - <form onSubmit={handleSubmit} className="p-4 flex clear-both"> |
| 41 | + <form |
| 42 | + onSubmit={handleSubmit} |
| 43 | + className="clear-both flex items-center justify-center p-4" |
| 44 | + > |
40 | 45 | <Input
|
41 | 46 | value={input}
|
42 |
| - placeholder={"Type to chat with AI..."} |
| 47 | + placeholder="Type to chat with AI..." |
43 | 48 | onChange={handleInputChange}
|
44 |
| - className="mr-2" |
| 49 | + className="mr-2 w-[70%] rounded-3xl border-gray-500 bg-green-700 py-6 text-white placeholder:text-white focus:border-green-500" |
45 | 50 | />
|
46 |
| - |
47 |
| - <Button type="submit" className="w-24"> |
48 |
| - {isLoading ? <Spinner /> : "Ask"} |
| 51 | + <Button |
| 52 | + type="submit" |
| 53 | + className="rounded-full border border-gray-500 bg-green-700 px-3 py-6 shadow-lg hover:bg-green-500" |
| 54 | + disabled={!input} |
| 55 | + > |
| 56 | + {isLoading ? <Spinner /> : <LuSend size={24} />} |
49 | 57 | </Button>
|
50 | 58 | </form>
|
51 | 59 | </div>
|
|
0 commit comments