import { Button, Group, Textarea } from "@mantine/core"; import { IconSend } from "@tabler/icons-react"; import { usePubSub } from "create-pubsub/react"; import { chatGenerationStatePubSub, chatInputPubSub, followUpQuestionPubSub, isRestoringFromHistoryPubSub, suppressNextFollowUpPubSub, } from "../../modules/pubSub"; interface ChatInputAreaProps { onKeyDown: (event: React.KeyboardEvent) => void; handleSend: (textToSend?: string) => void; } function ChatInputArea({ onKeyDown, handleSend }: ChatInputAreaProps) { const [input, setInput] = usePubSub(chatInputPubSub); const [generationState] = usePubSub(chatGenerationStatePubSub); const [followUpQuestion] = usePubSub(followUpQuestionPubSub); const [isRestoringFromHistory] = usePubSub(isRestoringFromHistoryPubSub); const [suppressNextFollowUp] = usePubSub(suppressNextFollowUpPubSub); const isGenerating = generationState.isGeneratingResponse && !generationState.isGeneratingFollowUpQuestion; const defaultPlaceholder = "Anything else you would like to know?"; const placeholder = isRestoringFromHistory || suppressNextFollowUp ? defaultPlaceholder : followUpQuestion || defaultPlaceholder; const onChange = (event: React.ChangeEvent) => { setInput(event.target.value); }; const handleKeyDownWithPlaceholder = ( event: React.KeyboardEvent, ) => { if ( input.trim() === "" && followUpQuestion && !isRestoringFromHistory && !suppressNextFollowUp ) { if (event.key === "Enter" && !event.shiftKey) { event.preventDefault(); handleSend(followUpQuestion); return; } } onKeyDown(event); }; const handleSendWithPlaceholder = () => { if ( input.trim() === "" && followUpQuestion && !isRestoringFromHistory && !suppressNextFollowUp ) { handleSend(followUpQuestion); } else { handleSend(); } }; return (