feat(web): add chat UI with WebSocket streaming and conversation persistence
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
41
web/client/src/components/chat/ChatInput.tsx
Normal file
41
web/client/src/components/chat/ChatInput.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
import { useState, useRef } from 'react';
|
||||
import { Send } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
export function ChatInput({ onSend }: { onSend: (content: string) => void }) {
|
||||
const [input, setInput] = useState('');
|
||||
const ref = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
const handleSend = () => {
|
||||
if (!input.trim()) return;
|
||||
onSend(input.trim());
|
||||
setInput('');
|
||||
ref.current?.focus();
|
||||
};
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) {
|
||||
e.preventDefault();
|
||||
handleSend();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="p-4 border-t border-zinc-800">
|
||||
<div className="flex items-end gap-2 bg-zinc-900 rounded-lg border border-zinc-800 px-3 py-2">
|
||||
<textarea
|
||||
ref={ref}
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
rows={1}
|
||||
placeholder="输入指令..."
|
||||
className="flex-1 bg-transparent text-sm resize-none outline-none placeholder:text-zinc-600"
|
||||
/>
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8" onClick={handleSend}>
|
||||
<Send size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user