import React, { useState, ForwardedRef, useEffect } from 'react'; import "../styles/variables.css"; interface InputProps { message: string; onSendClick: (message: string, override: boolean) => void; onMicClick: () => void; inputDisabled: boolean; isRecording: boolean; } const InputFrontend = React.forwardRef( ({ message, onSendClick, onMicClick, inputDisabled, isRecording }, ref: ForwardedRef) => { const [inputValue, setInputValue] = useState(''); // Sync the inputValue state with the message prop useEffect(() => { setInputValue(message); }, [message]); // Handle the input change const handleInputChange = (e: React.ChangeEvent) => { setInputValue(e.target.value); }; // Handle 'Enter' key press const handleKeyDown = (event: React.KeyboardEvent) => { if (!inputDisabled && event.key === 'Enter') { onSendClick(inputValue, false); // Send the message on Enter setInputValue(''); // Clear the input after submission event.preventDefault(); // Prevent the default Enter action } }; // Handle the Send button click const handleSendClick = () => { if (inputValue.trim() !== "") { onSendClick(inputValue, false); // Send message setInputValue(''); // Clear input after sending } }; return (
{/* Input field for typing messages */} {/* Send button */} {/* Microphone button */}
); } ); InputFrontend.displayName = "InputFrontend"; export default InputFrontend;