import React, { useState } from "react"; import { BOTTOMTEXT } from "../constants/constants"; import { useMessageFetching } from "../context/MessageFetch"; import { send } from "./Icons"; type InputProps = { askQuestion: (msg: string) => void; input: string; setInput: (value: string) => void; inputRef: React.RefObject; socket: any; }; export default function Input({ askQuestion, input, setInput, inputRef, socket, }: InputProps) { const { messageFetching, setDisableinput, disableinput, stopFetching, setMessageFetching, } = useMessageFetching(); function handleInputSubmit() { setDisableinput(true); setMessageFetching(true); if (input == "") return; askQuestion(input); setInput(""); if (inputRef.current) { inputRef.current.innerText = ""; } } const onKeyDown = (e: any) => { // if shift and enter are pressed together then add a new line if enter is pressed then submit the message if (e.key == "Enter" && !e.shiftKey && !messageFetching) { e.preventDefault(); handleInputSubmit(); } }; return ( <>
{ setInput(e.currentTarget.innerText); }} onKeyDownCapture={(e) => { onKeyDown(e); }} /> {disableinput ? (
) : ( <> )}

{BOTTOMTEXT}

{messageFetching && ( )} ); }