diff --git a/samples/apps/autogen-studio/frontend/src/components/header.tsx b/samples/apps/autogen-studio/frontend/src/components/header.tsx
index 9503f8d13..dc9ae916f 100644
--- a/samples/apps/autogen-studio/frontend/src/components/header.tsx
+++ b/samples/apps/autogen-studio/frontend/src/components/header.tsx
@@ -95,7 +95,7 @@ const Header = ({ meta, link }: any) => {
return (
{
const session: IChatSession | null = useConfigStore((state) => state.session);
- const queryInputRef = React.useRef
(null);
+ const textAreaInputRef = React.useRef(null);
const messageBoxInputRef = React.useRef(null);
const { user } = React.useContext(appContext);
@@ -37,6 +37,7 @@ const ChatBox = ({
const deleteMsgUrl = `${serverUrl}/messages/delete`;
const [loading, setLoading] = React.useState(false);
+ const [text, setText] = React.useState("");
const [error, setError] = React.useState({
status: true,
message: "All good",
@@ -51,7 +52,7 @@ const ChatBox = ({
let pageHeight, chatMaxHeight;
if (typeof window !== "undefined") {
pageHeight = window.innerHeight;
- chatMaxHeight = pageHeight - 300 + "px";
+ chatMaxHeight = pageHeight - 350 + "px";
}
const parseMessages = (messages: any) => {
@@ -265,28 +266,26 @@ const ChatBox = ({
}, 200);
}, [messages]);
+ const textAreaDefaultHeight = "50px";
// clear text box if loading has just changed to false and there is no error
React.useEffect(() => {
- if (loading === false && queryInputRef.current) {
- if (queryInputRef.current) {
- // console.log("loading changed", loading, error);
+ if (loading === false && textAreaInputRef.current) {
+ if (textAreaInputRef.current) {
if (error === null || (error && error.status === false)) {
- queryInputRef.current.value = "";
+ textAreaInputRef.current.value = "";
+ textAreaInputRef.current.style.height = textAreaDefaultHeight;
}
}
}
}, [loading]);
- // scroll to queryInputRef on load
React.useEffect(() => {
- // console.log("scrolling to query input");
- // if (queryInputRef.current) {
- // queryInputRef.current.scrollIntoView({
- // behavior: "smooth",
- // block: "center",
- // });
- // }
- }, []);
+ if (textAreaInputRef.current) {
+ textAreaInputRef.current.style.height = textAreaDefaultHeight; // Reset height to shrink if text is deleted
+ const scrollHeight = textAreaInputRef.current.scrollHeight;
+ textAreaInputRef.current.style.height = `${scrollHeight}px`;
+ }
+ }, [text]);
const chatHistory = (messages: IChatMessage[] | null) => {
let history = "";
@@ -378,6 +377,23 @@ const ChatBox = ({
});
};
+ const handleTextChange = (
+ event: React.ChangeEvent
+ ): void => {
+ setText(event.target.value);
+ };
+
+ const handleKeyDown = (
+ event: React.KeyboardEvent
+ ): void => {
+ if (event.key === "Enter" && !event.shiftKey) {
+ if (textAreaInputRef.current && !loading) {
+ event.preventDefault();
+ getCompletion(textAreaInputRef.current.value);
+ }
+ }
+ };
+
return (
{/*
*/}
-
{
- if (queryInputRef.current && !loading) {
- getCompletion(queryInputRef.current?.value);
- }
- }}
- className="bg-accent hover:brightness-75 transition duration-300 rounded pt-2 px-5 "
- >
- {" "}
- {!loading && (
-
- )}
- {loading && (
-
-
-
- )}
-
{" "}