import { ChangeEvent, KeyboardEvent, useState } from 'react'; import { useWaku } from './WakuContext'; import { TextInput, TextComposer, Row, Fill, Fit, SendButton, } from '@livechat/ui-kit'; interface Props { sendMessage: ((msg: string) => Promise) | undefined; } export default function MessageInput(props: Props) { const [inputText, setInputText] = useState(''); const { waku } = useWaku(); const sendMessage = async () => { if (props.sendMessage) { await props.sendMessage(inputText); setInputText(''); } }; const messageHandler = (event: ChangeEvent) => { setInputText(event.target.value); }; const keyPressHandler = async (event: KeyboardEvent) => { if ( event.key === 'Enter' && !event.altKey && !event.ctrlKey && !event.shiftKey ) { await sendMessage(); } }; // Enable the button if there are relay peers available or the user is sending a command const activeButton = (waku && waku.relay.getPeers().size !== 0) || inputText.startsWith('/'); return ( ); }