mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Focus on chat input area to enter text after file uploads on web app
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import styles from "./chat.module.css";
|
import styles from "./chat.module.css";
|
||||||
import React, { Suspense, useEffect, useState } from "react";
|
import React, { Suspense, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import SidePanel, { ChatSessionActionMenu } from "../components/sidePanel/chatHistorySidePanel";
|
import SidePanel, { ChatSessionActionMenu } from "../components/sidePanel/chatHistorySidePanel";
|
||||||
import ChatHistory from "../components/chatHistory/chatHistory";
|
import ChatHistory from "../components/chatHistory/chatHistory";
|
||||||
@@ -37,6 +37,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
|||||||
const [images, setImages] = useState<string[]>([]);
|
const [images, setImages] = useState<string[]>([]);
|
||||||
const [processingMessage, setProcessingMessage] = useState(false);
|
const [processingMessage, setProcessingMessage] = useState(false);
|
||||||
const [agentMetadata, setAgentMetadata] = useState<AgentData | null>(null);
|
const [agentMetadata, setAgentMetadata] = useState<AgentData | null>(null);
|
||||||
|
const chatInputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
const setQueryToProcess = props.setQueryToProcess;
|
const setQueryToProcess = props.setQueryToProcess;
|
||||||
const onConversationIdChange = props.onConversationIdChange;
|
const onConversationIdChange = props.onConversationIdChange;
|
||||||
@@ -123,6 +124,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
|||||||
conversationId={conversationId}
|
conversationId={conversationId}
|
||||||
isMobileWidth={props.isMobileWidth}
|
isMobileWidth={props.isMobileWidth}
|
||||||
setUploadedFiles={props.setUploadedFiles}
|
setUploadedFiles={props.setUploadedFiles}
|
||||||
|
ref={chatInputRef}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
|
|||||||
const [progressValue, setProgressValue] = useState(0);
|
const [progressValue, setProgressValue] = useState(0);
|
||||||
const [isDragAndDropping, setIsDragAndDropping] = useState(false);
|
const [isDragAndDropping, setIsDragAndDropping] = useState(false);
|
||||||
|
|
||||||
|
const chatInputRef = ref as React.MutableRefObject<HTMLTextAreaElement>;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!uploading) {
|
if (!uploading) {
|
||||||
setProgressValue(0);
|
setProgressValue(0);
|
||||||
@@ -175,6 +176,8 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
|
|||||||
if (newImagePaths.length > 0) {
|
if (newImagePaths.length > 0) {
|
||||||
setImageUploaded(true);
|
setImageUploaded(true);
|
||||||
setImagePaths((prevPaths) => [...prevPaths, ...newImagePaths]);
|
setImagePaths((prevPaths) => [...prevPaths, ...newImagePaths]);
|
||||||
|
// Set focus to the input for user message after uploading files
|
||||||
|
chatInputRef?.current?.focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +189,9 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
|
|||||||
props.setUploadedFiles,
|
props.setUploadedFiles,
|
||||||
props.conversationId,
|
props.conversationId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set focus to the input for user message after uploading files
|
||||||
|
chatInputRef?.current?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assuming this function is added within the same context as the provided excerpt
|
// Assuming this function is added within the same context as the provided excerpt
|
||||||
@@ -264,7 +270,6 @@ export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((pr
|
|||||||
}
|
}
|
||||||
}, [recording, mediaRecorder]);
|
}, [recording, mediaRecorder]);
|
||||||
|
|
||||||
const chatInputRef = ref as React.MutableRefObject<HTMLTextAreaElement>;
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!chatInputRef?.current) return;
|
if (!chatInputRef?.current) return;
|
||||||
chatInputRef.current.style.height = "auto";
|
chatInputRef.current.style.height = "auto";
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
|||||||
const [images, setImages] = useState<string[]>([]);
|
const [images, setImages] = useState<string[]>([]);
|
||||||
const [processingMessage, setProcessingMessage] = useState(false);
|
const [processingMessage, setProcessingMessage] = useState(false);
|
||||||
const [agentMetadata, setAgentMetadata] = useState<AgentData | null>(null);
|
const [agentMetadata, setAgentMetadata] = useState<AgentData | null>(null);
|
||||||
|
const chatInputRef = useRef<HTMLTextAreaElement>(null);
|
||||||
|
|
||||||
const setQueryToProcess = props.setQueryToProcess;
|
const setQueryToProcess = props.setQueryToProcess;
|
||||||
const streamedMessages = props.streamedMessages;
|
const streamedMessages = props.streamedMessages;
|
||||||
|
|
||||||
@@ -114,6 +116,7 @@ function ChatBodyData(props: ChatBodyDataProps) {
|
|||||||
agentColor={agentMetadata?.color}
|
agentColor={agentMetadata?.color}
|
||||||
isMobileWidth={props.isMobileWidth}
|
isMobileWidth={props.isMobileWidth}
|
||||||
setUploadedFiles={props.setUploadedFiles}
|
setUploadedFiles={props.setUploadedFiles}
|
||||||
|
ref={chatInputRef}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user