no input while generating/empty

This commit is contained in:
YasinOnm08 2024-09-24 13:50:46 +02:00
parent 37177a7856
commit 615a58ce28
2 changed files with 17 additions and 14 deletions

View file

@ -4,21 +4,25 @@ interface InputProps {
message: string;
onSendClick: (message: string) => void;
onMicClick: () => void;
inputDisabled:boolean
}
const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
({ message, onSendClick, onMicClick }, ref: ForwardedRef<HTMLDivElement>) => {
({ message, onSendClick, onMicClick, inputDisabled }, ref: ForwardedRef<HTMLDivElement>) => {
const [inputValue, setInputValue] = useState('');
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setInputValue(e.target.value);
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter') {
onSendClick(inputValue); // Call the function passed via props
setInputValue(''); // Optionally clear input after submission
event.preventDefault(); // Prevent default action (e.g., form submission)
if (!inputDisabled) {
if (event.key === 'Enter') {
onSendClick(inputValue); // Call the function passed via props
setInputValue(''); // Optionally clear input after submission
event.preventDefault(); // Prevent default action (e.g., form submission)
}
}
};
@ -32,7 +36,7 @@ const InputFrontend = React.forwardRef<HTMLDivElement, InputProps>(
onChange={handleInputChange}
onKeyDown={handleKeyDown}
/>
<button type="button" onClick={() => onSendClick(inputValue)}>
<button type="button" onClick={() => onSendClick(inputValue)} disabled={inputDisabled?true:false}>
<img src="/img/send.svg" alt="send" />
</button>
<button type="button" onClick={onMicClick}>