import React from 'react'; import { useTranslation } from 'react-i18next'; import { FiSend } from 'react-icons/fi'; import { connection } from '@core/connection'; import { ackMessage } from '@core/slices/meshtasticSlice'; import { useAppDispatch } from '@hooks/useAppDispatch'; import { useAppSelector } from '@hooks/useAppSelector'; import { IconButton, Input, Select } 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 nodes = useAppSelector((state) => state.meshtastic.nodes); const myNodeNum = useAppSelector( (state) => state.meshtastic.radio.hardware, ).myNodeNum; const [currentMessage, setCurrentMessage] = React.useState(''); const [destinationNode, setDestinationNode] = React.useState(0xffffffff); const sendMessage = (): void => { if (ready) { void connection.sendText( currentMessage, destinationNode, true, channelIndex--, (id) => { dispatch(ackMessage({ channel: channelIndex--, messageId: id })); return Promise.resolve(); }, ); setCurrentMessage(''); } }; const { t } = useTranslation(); return (
{ e.preventDefault(); sendMessage(); }} > { setCurrentMessage(e.target.value); }} /> } type="submit" />
); };