import SendButton from "../SendButton"; import { ChangeEvent, useEffect, useState } from "react"; import { useStore } from "@/_models/RootStore"; import { AiModelType } from "@/_models/Product"; import Image from "next/image"; import { observer } from "mobx-react-lite"; import useGetCurrentUser from "@/_hooks/useGetCurrentUser"; import useSignIn from "@/_hooks/useSignIn"; import { useMutation } from "@apollo/client"; import { CreateMessageDocument, CreateMessageMutation, GenerateImageMutation, GenerateImageDocument, } from "@/graphql"; type Props = { prefillPrompt: string; }; export const InputToolbar: React.FC = observer(({ prefillPrompt }) => { const { historyStore } = useStore(); const [text, setText] = useState(prefillPrompt); const { user } = useGetCurrentUser(); const { signInWithKeyCloak } = useSignIn(); const [createMessageMutation] = useMutation( CreateMessageDocument ); const [imageGenerationMutation] = useMutation( GenerateImageDocument ); useEffect(() => { setText(prefillPrompt); }, [prefillPrompt]); const handleMessageChange = (event: any) => { setText(event.target.value); }; const onSubmitClick = () => { if (!user) { signInWithKeyCloak(); return; } if (text.trim().length === 0) return; historyStore.sendMessage( createMessageMutation, imageGenerationMutation, text, user.id, user.displayName, user.avatarUrl ); setText(""); }; const handleKeyDown = (event: any) => { if (event.key === "Enter") { if (!event.shiftKey) { event.preventDefault(); onSubmitClick(); } } }; let shouldDisableSubmitButton = false; if (historyStore.getActiveConversation()?.isWaitingForModelResponse) { shouldDisableSubmitButton = true; } if (text.length === 0) { shouldDisableSubmitButton = true; } const onAdvancedPrompt = () => { historyStore.toggleAdvancedPrompt(); }; const handleResize = (event: ChangeEvent) => { event.target.style.height = "auto"; event.target.style.height = event.target.scrollHeight + "px"; }; const shouldShowAdvancedPrompt = historyStore.getActiveConversation()?.product?.type === AiModelType.ControlNet ?? false; return (