deepsite-project / src /components /ChatInterface.jsx
tung14's picture
Build a modular AI assistant website using Next.js and Vite. Include chat UI with memory, proxy app launcher, math and Chinese reference modules, secure input, and deploy-ready structure for Vercel.
02398a6 verified
Raw History Blame Contribute Delete
1.5 kB
```javascript
import { useState } from 'react'
import { Send, Loader } from 'react-feather'
export default function ChatInterface({ messages, onSend, isLoading }) {
const [input, setInput] = useState('')
const handleSubmit = (e) => {
e.preventDefault()
if (!input.trim()) return
onSend(input)
setInput('')
}
return (
<div className="flex flex-col h-full">
<div className="flex-1 overflow-y-auto p-4">
{messages.map((msg, i) => (
<div key={i} className={`mb-4 ${msg.role === 'user' ? 'text-right' : 'text-left'}`}>
<div className={`inline-block p-3 rounded-lg ${msg.role === 'user'
? 'bg-blue-500 text-white'
: 'bg-gray-200 text-gray-800'}`}>
{msg.content}
</div>
</div>
))}
</div>
<form onSubmit={handleSubmit} className="p-4 border-t">
<div className="flex">
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
className="flex-1 p-2 border rounded-l-lg focus:outline-none"
placeholder="Type your message..."
/>
<button
type="submit"
disabled={isLoading}
className="bg-blue-500 text-white p-2 rounded-r-lg hover:bg-blue-600 disabled:bg-blue-300">
{isLoading ? <Loader className="animate-spin" /> : <Send />}
</button>
</div>
</form>
</div>
)
}
```