From ff868c6350553389b2ca3769dc0a3c189759935c Mon Sep 17 00:00:00 2001 From: Sacha Weatherstone Date: Mon, 8 Nov 2021 12:49:11 +1100 Subject: [PATCH] Add message destination select --- src/components/chat/MessageBar.tsx | 26 +++++++++++++++++++++- src/components/generic/form/EnumSelect.tsx | 12 ++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/components/chat/MessageBar.tsx b/src/components/chat/MessageBar.tsx index 6d4e515f..129c1dd6 100644 --- a/src/components/chat/MessageBar.tsx +++ b/src/components/chat/MessageBar.tsx @@ -8,15 +8,20 @@ import { useAppDispatch, useAppSelector } from '@app/hooks/redux'; import { Input } from '@components/generic/form/Input'; import { connection } from '@core/connection'; +import { EnumSelect } from '../generic/form/EnumSelect.jsx'; import { IconButton } from '../generic/IconButton.jsx'; export const MessageBar = (): JSX.Element => { const dispatch = useAppDispatch(); const ready = useAppSelector((state) => state.meshtastic.ready); + const nodes = useAppSelector((state) => state.meshtastic.nodes); + const myNodeInfo = useAppSelector((state) => state.meshtastic.myNodeInfo); const [currentMessage, setCurrentMessage] = React.useState(''); + const [destinationNode, setDestinationNode] = + React.useState(0xffffffff); const sendMessage = (): void => { if (ready) { - void connection.sendText(currentMessage, undefined, true, (id) => { + void connection.sendText(currentMessage, destinationNode, true, (id) => { dispatch(ackMessage(id)); return Promise.resolve(); @@ -35,6 +40,25 @@ export const MessageBar = (): JSX.Element => { sendMessage(); }} > + { + setDestinationNode(parseInt(e.target.value)); + }} + options={[ + { + name: 'All', + value: 0xffffffff, + }, + ...nodes + .filter((node) => node.num !== myNodeInfo.myNodeNum) + .map((node) => { + return { + name: node.user?.shortName ?? node.num, + value: node.num, + }; + }), + ]} + /> ( className={`w-full bg-transparent focus:outline-none focus:border-primary ${ small ? 'py-1 mx-1' : 'h-10 mx-2' }`} + disabled={ + props.disabled + ? true + : !(optionsEnumValues.length || options?.length) + } {...props} > + {!(optionsEnumValues.length || options?.length) && ( + + )} {optionsEnumValues.length && optionsEnumValues.map(([name, value]) => (