Set chatInputArea forward ref from parent components for control

This commit is contained in:
Debanjum Singh Solanky 2024-10-21 00:01:44 -07:00
parent 54b92eaf73
commit 220ff1df62
4 changed files with 10 additions and 26 deletions

View file

@ -14,11 +14,9 @@ import "katex/dist/katex.min.css";
import { Context, OnlineContext, StreamMessage } from "../components/chatMessage/chatMessage"; import { Context, OnlineContext, StreamMessage } from "../components/chatMessage/chatMessage";
import { useIPLocationData, useIsMobileWidth, welcomeConsole } from "../common/utils"; import { useIPLocationData, useIsMobileWidth, welcomeConsole } from "../common/utils";
import ChatInputArea, { ChatOptions } from "../components/chatInputArea/chatInputArea"; import { ChatInputArea, ChatOptions } from "../components/chatInputArea/chatInputArea";
import { useAuthenticatedData } from "../common/auth"; import { useAuthenticatedData } from "../common/auth";
import { AgentData } from "../agents/page"; import { AgentData } from "../agents/page";
import { DotsThreeVertical } from "@phosphor-icons/react";
import { Button } from "@/components/ui/button";
interface ChatBodyDataProps { interface ChatBodyDataProps {
chatOptionsData: ChatOptions | null; chatOptionsData: ChatOptions | null;

View file

@ -1,25 +1,9 @@
import styles from "./chatInputArea.module.css"; import styles from "./chatInputArea.module.css";
import React, { useEffect, useRef, useState } from "react"; import React, { useEffect, useRef, useState, forwardRef } from "react";
import DOMPurify from "dompurify"; import DOMPurify from "dompurify";
import "katex/dist/katex.min.css"; import "katex/dist/katex.min.css";
import { import { ArrowUp, Microphone, Paperclip, X, Stop } from "@phosphor-icons/react";
ArrowRight,
ArrowUp,
Browser,
ChatsTeardrop,
GlobeSimple,
Gps,
Image,
Microphone,
Notebook,
Paperclip,
X,
Question,
Robot,
Shapes,
Stop,
} from "@phosphor-icons/react";
import { import {
Command, Command,
@ -68,7 +52,7 @@ interface ChatInputProps {
agentColor?: string; agentColor?: string;
} }
export default function ChatInputArea(props: ChatInputProps) { export const ChatInputArea = forwardRef<HTMLTextAreaElement, ChatInputProps>((props, ref) => {
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const fileInputRef = useRef<HTMLInputElement>(null); const fileInputRef = useRef<HTMLInputElement>(null);
@ -270,7 +254,7 @@ export default function ChatInputArea(props: ChatInputProps) {
} }
}, [recording, mediaRecorder]); }, [recording, mediaRecorder]);
const chatInputRef = useRef<HTMLTextAreaElement>(null); 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";
@ -514,4 +498,6 @@ export default function ChatInputArea(props: ChatInputProps) {
</div> </div>
</> </>
); );
} });
ChatInputArea.displayName = "ChatInputArea";

View file

@ -12,7 +12,7 @@ import { Card, CardTitle } from "@/components/ui/card";
import SuggestionCard from "@/app/components/suggestions/suggestionCard"; import SuggestionCard from "@/app/components/suggestions/suggestionCard";
import SidePanel from "@/app/components/sidePanel/chatHistorySidePanel"; import SidePanel from "@/app/components/sidePanel/chatHistorySidePanel";
import Loading from "@/app/components/loading/loading"; import Loading from "@/app/components/loading/loading";
import ChatInputArea, { ChatOptions } from "@/app/components/chatInputArea/chatInputArea"; import { ChatInputArea, ChatOptions } from "@/app/components/chatInputArea/chatInputArea";
import { Suggestion, suggestionsData } from "@/app/components/suggestions/suggestionsData"; import { Suggestion, suggestionsData } from "@/app/components/suggestions/suggestionsData";
import LoginPrompt from "@/app/components/loginPrompt/loginPrompt"; import LoginPrompt from "@/app/components/loginPrompt/loginPrompt";

View file

@ -13,7 +13,7 @@ import "katex/dist/katex.min.css";
import { useIPLocationData, useIsMobileWidth, welcomeConsole } from "../../common/utils"; import { useIPLocationData, useIsMobileWidth, welcomeConsole } from "../../common/utils";
import { useAuthenticatedData } from "@/app/common/auth"; import { useAuthenticatedData } from "@/app/common/auth";
import ChatInputArea, { ChatOptions } from "@/app/components/chatInputArea/chatInputArea"; import { ChatInputArea, ChatOptions } from "@/app/components/chatInputArea/chatInputArea";
import { StreamMessage } from "@/app/components/chatMessage/chatMessage"; import { StreamMessage } from "@/app/components/chatMessage/chatMessage";
import { processMessageChunk } from "@/app/common/chatFunctions"; import { processMessageChunk } from "@/app/common/chatFunctions";
import { AgentData } from "@/app/agents/page"; import { AgentData } from "@/app/agents/page";