Soham Waghmare commited on
Commit
08ee506
·
1 Parent(s): 8c8c2f9

fix: focus

Browse files
frontend/src/components/ChatInterface.tsx CHANGED
@@ -2,7 +2,7 @@
2
  import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
3
  import { disconnectSocket, getSocket, initializeSocket } from "@/lib/socket";
4
  import { ChatData, ChatState, Conversation, Message, ResearchOptions, ResearchResults, StatusUpdate } from "@/lib/types";
5
- import { useEffect, useState } from "react";
6
  import { v4 as uuidv4 } from "uuid";
7
  import ChatHistory from "./ChatHistory";
8
  import MessageInput from "./MessageInput";
@@ -249,10 +249,12 @@ const ChatInterface = () => {
249
  active: conv.id === id,
250
  }))
251
  );
 
252
  };
253
 
254
  const sidebar = <ConversationList conversations={conversations} onNewConversation={handleNewConversation} onSelectConversation={handleSelectConversation} />;
255
 
 
256
  const mainContent = (
257
  <div className="flex flex-col w-full h-full relative" tabIndex={-1}>
258
  <ChatHistory messages={chatState.messages} isLoading={chatState.isLoading} />
@@ -264,7 +266,7 @@ const ChatInterface = () => {
264
  </Alert>
265
  )}
266
 
267
- <MessageInput onSendMessage={handleSendMessage} isLoading={chatState.isLoading} />
268
  </div>
269
  );
270
 
 
2
  import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
3
  import { disconnectSocket, getSocket, initializeSocket } from "@/lib/socket";
4
  import { ChatData, ChatState, Conversation, Message, ResearchOptions, ResearchResults, StatusUpdate } from "@/lib/types";
5
+ import { useEffect, useRef, useState } from "react";
6
  import { v4 as uuidv4 } from "uuid";
7
  import ChatHistory from "./ChatHistory";
8
  import MessageInput from "./MessageInput";
 
249
  active: conv.id === id,
250
  }))
251
  );
252
+ userInputRef.current?.focus();
253
  };
254
 
255
  const sidebar = <ConversationList conversations={conversations} onNewConversation={handleNewConversation} onSelectConversation={handleSelectConversation} />;
256
 
257
+ const userInputRef = useRef<HTMLTextAreaElement>();
258
  const mainContent = (
259
  <div className="flex flex-col w-full h-full relative" tabIndex={-1}>
260
  <ChatHistory messages={chatState.messages} isLoading={chatState.isLoading} />
 
266
  </Alert>
267
  )}
268
 
269
+ <MessageInput onSendMessage={handleSendMessage} isLoading={chatState.isLoading} userInputRef={userInputRef} />
270
  </div>
271
  );
272
 
frontend/src/components/MessageInput.tsx CHANGED
@@ -8,9 +8,10 @@ import React, { useState } from "react";
8
  interface MessageInputProps {
9
  onSendMessage: (content: string) => void;
10
  isLoading: boolean;
 
11
  }
12
 
13
- const MessageInput: React.FC<MessageInputProps> = ({ onSendMessage, isLoading }) => {
14
  const [message, setMessage] = useState("");
15
 
16
  const handleMessageChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
@@ -36,7 +37,7 @@ const MessageInput: React.FC<MessageInputProps> = ({ onSendMessage, isLoading })
36
  <div className="p-4 absolute bottom-0 left-0 right-0 bg-transparent mb-4">
37
  <form onSubmit={handleSubmit} className="max-w-4xl mx-auto">
38
  <div className="relative flex items-center bg-background shadow-lg rounded-[2rem] border overflow-hidden h-full">
39
- <AutosizeTextarea placeholder="Ask a research question..." maxHeight={500} minHeight={52} className="pr-36 pl-6 py-4 font-medium border-none h-auto resize-none" value={message} onChange={handleMessageChange} onKeyDown={handleKeyDown} disabled={isLoading} rows={1} autoFocus />
40
 
41
  <div className="absolute right-3 flex items-center gap-2 h-full">
42
  <TooltipProvider>
 
8
  interface MessageInputProps {
9
  onSendMessage: (content: string) => void;
10
  isLoading: boolean;
11
+ userInputRef: React.LegacyRef<any>;
12
  }
13
 
14
+ const MessageInput: React.FC<MessageInputProps> = ({ onSendMessage, isLoading, userInputRef }) => {
15
  const [message, setMessage] = useState("");
16
 
17
  const handleMessageChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
 
37
  <div className="p-4 absolute bottom-0 left-0 right-0 bg-transparent mb-4">
38
  <form onSubmit={handleSubmit} className="max-w-4xl mx-auto">
39
  <div className="relative flex items-center bg-background shadow-lg rounded-[2rem] border overflow-hidden h-full">
40
+ <AutosizeTextarea placeholder="Ask a research question..." maxHeight={500} minHeight={52} className="pr-36 pl-6 py-4 font-medium border-none h-auto resize-none" value={message} onChange={handleMessageChange} onKeyDown={handleKeyDown} disabled={isLoading} rows={1} autoFocus ref={userInputRef}/>
41
 
42
  <div className="absolute right-3 flex items-center gap-2 h-full">
43
  <TooltipProvider>