From c0ebd9aab8d77bd9e3d0ba07fd102b29718fead1 Mon Sep 17 00:00:00 2001 From: Cam Johnson Date: Tue, 28 Oct 2025 14:27:05 -0600 Subject: [PATCH 1/3] Refactor message input --- src/components/Chat.tsx | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 3c4830d..adb996c 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -2,7 +2,6 @@ import { useState, useRef, useEffect } from 'react'; import { motion } from 'framer-motion'; import type { Message } from '@/types/message'; import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Card, CardContent } from '@/components/ui/card'; @@ -13,6 +12,7 @@ interface ChatProps { export const Chat = ({ messages, setMessages }: ChatProps) => { const scrollAreaRef = useRef(null); + const textareaRef = useRef(null); const [input, setInput] = useState(''); const [loading, setLoading] = useState(false); @@ -33,6 +33,12 @@ export const Chat = ({ messages, setMessages }: ChatProps) => { const userMessage: Message = { id: crypto.randomUUID(), role: 'user', content: input }; setMessages((prev) => [...prev, userMessage]); setInput(''); + + if (textareaRef.current) { + textareaRef.current.style.height = 'auto'; + textareaRef.current.style.height = '48px'; + } + setLoading(true); try { @@ -116,15 +122,31 @@ export const Chat = ({ messages, setMessages }: ChatProps) => { }} className='flex gap-2 p-4 border-t border-border' > - setInput(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + sendMessage(); + } + }} placeholder='Type your message...' - className='border border-border focus-visible:ring-0 focus-visible:ring-offset-0 !py-3' + className='flex-1 resize-none border border-border focus:outline-none focus:ring-0 focus:ring-offset-0 py-3 px-3 rounded-md min-h-[48px] max-h-32 overflow-y-auto' + rows={1} + style={{ + height: 'auto', + }} + onInput={(e) => { + const target = e.target as HTMLTextAreaElement; + target.style.height = 'auto'; + target.style.height = `${Math.min(target.scrollHeight, 128)}px`; + }} />