1- import React , { useState , useRef , useEffect } from 'react' ;
1+ import React , { useState , useRef , useEffect , useCallback } from 'react' ;
22import { Send } from 'lucide-react' ;
33import { Button } from '@/components/ui/button' ;
44import { useChatStore } from '@/stores/chatStore' ;
@@ -42,44 +42,44 @@ export function MessageInput({ roomId, disabled = false, placeholder = "Type a m
4242
4343 const handleSubmit = ( e : React . FormEvent ) => {
4444 e . preventDefault ( ) ;
45-
45+
4646 if ( ! message . trim ( ) || disabled ) return ;
47-
47+
4848 // Send message
4949 sendMessage ( roomId , message . trim ( ) ) ;
50-
50+
5151 // Clear input
5252 setMessage ( '' ) ;
53-
53+
5454 // Stop typing indicator
5555 if ( isTyping ) {
5656 setTyping ( roomId , false ) ;
5757 setIsTyping ( false ) ;
5858 }
59-
59+
6060 // Reset textarea height
6161 if ( textareaRef . current ) {
6262 textareaRef . current . style . height = 'auto' ;
6363 }
6464 } ;
6565
66- const handleKeyDown = ( e : React . KeyboardEvent ) => {
67- if ( e . key === 'Enter' && ! e . shiftKey ) {
66+ const handleKeyDown = useCallback ( ( e : React . KeyboardEvent ) => {
67+ if ( e . key === 'Enter' ) {
6868 e . preventDefault ( ) ;
6969 handleSubmit ( e ) ;
7070 }
71- } ;
71+ } , [ handleSubmit ] ) ;
7272
7373 const handleInputChange = ( e : React . ChangeEvent < HTMLTextAreaElement > ) => {
7474 const value = e . target . value ;
7575 setMessage ( value ) ;
76-
76+
7777 // Auto-resize textarea
7878 if ( textareaRef . current ) {
7979 textareaRef . current . style . height = 'auto' ;
8080 textareaRef . current . style . height = `${ Math . min ( textareaRef . current . scrollHeight , 120 ) } px` ;
8181 }
82-
82+
8383 // Handle typing indicator with debounce
8484 const now = Date . now ( ) ;
8585
@@ -132,7 +132,7 @@ export function MessageInput({ roomId, disabled = false, placeholder = "Type a m
132132
133133 return (
134134 < div className = "sticky bottom-0 z-10 border-t bg-white p-4 shadow-lg" >
135- < form onSubmit = { handleSubmit } className = "flex items-end gap-2" >
135+ < div className = "flex items-end gap-2" >
136136 < div className = "flex-1 relative" >
137137 < textarea
138138 ref = { textareaRef }
@@ -145,24 +145,25 @@ export function MessageInput({ roomId, disabled = false, placeholder = "Type a m
145145 style = { { minHeight : '40px' , maxHeight : '120px' } }
146146 rows = { 1 }
147147 />
148-
148+
149149 { /* Emoji picker */ }
150150 < div className = "absolute right-2 top-1/2 -translate-y-1/2" >
151151 < EmojiPicker onEmojiSelect = { handleEmojiSelect } disabled = { disabled } />
152152 </ div >
153153 </ div >
154-
154+
155155 < Button
156- type = "submit "
156+ type = "button "
157157 size = "sm"
158158 disabled = { ! message . trim ( ) || disabled }
159159 className = "h-10 px-3"
160+ onClick = { ( e ) => handleSubmit ( e ) }
160161 >
161162 < Send className = "w-4 h-4" />
162163 < span className = "sr-only" > Send message</ span >
163164 </ Button >
164- </ form >
165-
165+ </ div >
166+
166167 { /* Character count (optional) */ }
167168 { message . length > 1800 && (
168169 < div className = "mt-1 text-xs text-gray-500 text-right" >
0 commit comments