From 220ff1df62dd58b1b6e1a9a78121e02767990360 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 21 Oct 2024 00:01:44 -0700 Subject: [PATCH] Set chatInputArea forward ref from parent components for control --- src/interface/web/app/chat/page.tsx | 4 +-- .../chatInputArea/chatInputArea.tsx | 28 +++++-------------- src/interface/web/app/page.tsx | 2 +- src/interface/web/app/share/chat/page.tsx | 2 +- 4 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/interface/web/app/chat/page.tsx b/src/interface/web/app/chat/page.tsx index 7d87fd81..7d003c0e 100644 --- a/src/interface/web/app/chat/page.tsx +++ b/src/interface/web/app/chat/page.tsx @@ -14,11 +14,9 @@ import "katex/dist/katex.min.css"; import { Context, OnlineContext, StreamMessage } from "../components/chatMessage/chatMessage"; 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 { AgentData } from "../agents/page"; -import { DotsThreeVertical } from "@phosphor-icons/react"; -import { Button } from "@/components/ui/button"; interface ChatBodyDataProps { chatOptionsData: ChatOptions | null; diff --git a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx index d85d6a54..6cb88ca0 100644 --- a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx +++ b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx @@ -1,25 +1,9 @@ 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 "katex/dist/katex.min.css"; -import { - ArrowRight, - ArrowUp, - Browser, - ChatsTeardrop, - GlobeSimple, - Gps, - Image, - Microphone, - Notebook, - Paperclip, - X, - Question, - Robot, - Shapes, - Stop, -} from "@phosphor-icons/react"; +import { ArrowUp, Microphone, Paperclip, X, Stop } from "@phosphor-icons/react"; import { Command, @@ -68,7 +52,7 @@ interface ChatInputProps { agentColor?: string; } -export default function ChatInputArea(props: ChatInputProps) { +export const ChatInputArea = forwardRef((props, ref) => { const [message, setMessage] = useState(""); const fileInputRef = useRef(null); @@ -270,7 +254,7 @@ export default function ChatInputArea(props: ChatInputProps) { } }, [recording, mediaRecorder]); - const chatInputRef = useRef(null); + const chatInputRef = ref as React.MutableRefObject; useEffect(() => { if (!chatInputRef.current) return; chatInputRef.current.style.height = "auto"; @@ -514,4 +498,6 @@ export default function ChatInputArea(props: ChatInputProps) { ); -} +}); + +ChatInputArea.displayName = "ChatInputArea"; diff --git a/src/interface/web/app/page.tsx b/src/interface/web/app/page.tsx index 3976a6b6..83081e2f 100644 --- a/src/interface/web/app/page.tsx +++ b/src/interface/web/app/page.tsx @@ -12,7 +12,7 @@ import { Card, CardTitle } from "@/components/ui/card"; import SuggestionCard from "@/app/components/suggestions/suggestionCard"; import SidePanel from "@/app/components/sidePanel/chatHistorySidePanel"; 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 LoginPrompt from "@/app/components/loginPrompt/loginPrompt"; diff --git a/src/interface/web/app/share/chat/page.tsx b/src/interface/web/app/share/chat/page.tsx index 9bc5f12d..9268eb58 100644 --- a/src/interface/web/app/share/chat/page.tsx +++ b/src/interface/web/app/share/chat/page.tsx @@ -13,7 +13,7 @@ import "katex/dist/katex.min.css"; import { useIPLocationData, useIsMobileWidth, welcomeConsole } from "../../common/utils"; 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 { processMessageChunk } from "@/app/common/chatFunctions"; import { AgentData } from "@/app/agents/page";