Alleinzellgaenger commited on
Commit
f9f3f42
·
1 Parent(s): 373601c

Make text window resizeable

Browse files
frontend/src/components/SimpleChat.jsx CHANGED
@@ -9,6 +9,8 @@ const SimpleChat = ({ messages, currentChunkIndex, onSend, isLoading }) => {
9
  const [input, setInput] = useState('');
10
  const containerRef = useRef(null);
11
  const anchorRef = useRef(null); // <- will be a tiny zero-height anchor BEFORE the bubble
 
 
12
  const handleSubmit = (e) => {
13
  e.preventDefault();
14
  if (!input.trim() || isLoading ) return;
@@ -16,6 +18,21 @@ const SimpleChat = ({ messages, currentChunkIndex, onSend, isLoading }) => {
16
  setInput('');
17
  };
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  // Since messages are now filtered to current chunk only, use the last message for anchoring
20
  const { anchorIndex, firstInChunkIndex } = useMemo(() => {
21
  const lastIndex = messages.length > 0 ? messages.length - 1 : -1;
@@ -150,16 +167,19 @@ const SimpleChat = ({ messages, currentChunkIndex, onSend, isLoading }) => {
150
  )}
151
  </div>
152
 
153
- {/* Input (unchanged) */}
154
  <form onSubmit={handleSubmit} className="p-4 border-t">
155
- <div className="flex space-x-2">
156
- <input
157
- type="text"
158
  value={input}
159
  onChange={(e) => setInput(e.target.value)}
160
- placeholder={'Type your message...'}
161
- disabled={isLoading }
162
- className="flex-1 px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 disabled:text-gray-500"
 
 
 
163
  />
164
  <button
165
  type="submit"
 
9
  const [input, setInput] = useState('');
10
  const containerRef = useRef(null);
11
  const anchorRef = useRef(null); // <- will be a tiny zero-height anchor BEFORE the bubble
12
+ const textareaRef = useRef(null);
13
+
14
  const handleSubmit = (e) => {
15
  e.preventDefault();
16
  if (!input.trim() || isLoading ) return;
 
18
  setInput('');
19
  };
20
 
21
+ const handleKeyDown = (e) => {
22
+ if (e.key === 'Enter' && !e.shiftKey) {
23
+ e.preventDefault();
24
+ handleSubmit(e);
25
+ }
26
+ };
27
+
28
+ // Auto-resize textarea
29
+ useEffect(() => {
30
+ if (textareaRef.current) {
31
+ textareaRef.current.style.height = 'auto';
32
+ textareaRef.current.style.height = Math.min(textareaRef.current.scrollHeight, 120) + 'px';
33
+ }
34
+ }, [input]);
35
+
36
  // Since messages are now filtered to current chunk only, use the last message for anchoring
37
  const { anchorIndex, firstInChunkIndex } = useMemo(() => {
38
  const lastIndex = messages.length > 0 ? messages.length - 1 : -1;
 
167
  )}
168
  </div>
169
 
170
+ {/* Input with auto-resize textarea */}
171
  <form onSubmit={handleSubmit} className="p-4 border-t">
172
+ <div className="flex space-x-2 items-end">
173
+ <textarea
174
+ ref={textareaRef}
175
  value={input}
176
  onChange={(e) => setInput(e.target.value)}
177
+ onKeyDown={handleKeyDown}
178
+ placeholder="Type your message... (Enter to send, Shift+Enter for new line)"
179
+ disabled={isLoading}
180
+ rows={1}
181
+ className="flex-1 px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 disabled:bg-gray-100 disabled:text-gray-500 resize-none overflow-hidden"
182
+ style={{ minHeight: '42px' }}
183
  />
184
  <button
185
  type="submit"