import React from 'react'; import { connection } from '@core/connection'; import { ackMessage } from '@core/slices/meshtasticSlice'; import { useAppDispatch } from '@hooks/useAppDispatch'; import { useAppSelector } from '@hooks/useAppSelector'; import { Input } from '@meshtastic/components'; export interface MessageBarProps { channelIndex: number; } export const MessageBar = ({ channelIndex }: MessageBarProps): JSX.Element => { const dispatch = useAppDispatch(); const ready = useAppSelector((state) => state.meshtastic.ready); const [currentMessage, setCurrentMessage] = React.useState(''); const sendMessage = (): void => { if (ready) { void connection.sendText( currentMessage, undefined, true, channelIndex--, (id) => { dispatch(ackMessage({ channel: channelIndex--, messageId: id })); return Promise.resolve(); }, ); setCurrentMessage(''); } }; return (
{ e.preventDefault(); sendMessage(); }} > { setCurrentMessage(e.target.value); }} />
); };