Add message destination select
This commit is contained in:
@@ -8,15 +8,20 @@ import { useAppDispatch, useAppSelector } from '@app/hooks/redux';
|
|||||||
import { Input } from '@components/generic/form/Input';
|
import { Input } from '@components/generic/form/Input';
|
||||||
import { connection } from '@core/connection';
|
import { connection } from '@core/connection';
|
||||||
|
|
||||||
|
import { EnumSelect } from '../generic/form/EnumSelect.jsx';
|
||||||
import { IconButton } from '../generic/IconButton.jsx';
|
import { IconButton } from '../generic/IconButton.jsx';
|
||||||
|
|
||||||
export const MessageBar = (): JSX.Element => {
|
export const MessageBar = (): JSX.Element => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const ready = useAppSelector((state) => state.meshtastic.ready);
|
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 [currentMessage, setCurrentMessage] = React.useState('');
|
||||||
|
const [destinationNode, setDestinationNode] =
|
||||||
|
React.useState<number>(0xffffffff);
|
||||||
const sendMessage = (): void => {
|
const sendMessage = (): void => {
|
||||||
if (ready) {
|
if (ready) {
|
||||||
void connection.sendText(currentMessage, undefined, true, (id) => {
|
void connection.sendText(currentMessage, destinationNode, true, (id) => {
|
||||||
dispatch(ackMessage(id));
|
dispatch(ackMessage(id));
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -35,6 +40,25 @@ export const MessageBar = (): JSX.Element => {
|
|||||||
sendMessage();
|
sendMessage();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<EnumSelect
|
||||||
|
onChange={(e): void => {
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
minLength={2}
|
minLength={2}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ type DefaultSelectProps = JSX.IntrinsicElements['select'];
|
|||||||
|
|
||||||
interface SelectProps extends DefaultSelectProps {
|
interface SelectProps extends DefaultSelectProps {
|
||||||
options?: {
|
options?: {
|
||||||
name: string;
|
name: string | number;
|
||||||
value: number | string;
|
value: string | number;
|
||||||
}[];
|
}[];
|
||||||
optionsEnum?: { [s: string]: string | number };
|
optionsEnum?: { [s: string]: string | number };
|
||||||
label?: string;
|
label?: string;
|
||||||
@@ -32,8 +32,16 @@ export const EnumSelect = React.forwardRef<HTMLSelectElement, SelectProps>(
|
|||||||
className={`w-full bg-transparent focus:outline-none focus:border-primary ${
|
className={`w-full bg-transparent focus:outline-none focus:border-primary ${
|
||||||
small ? 'py-1 mx-1' : 'h-10 mx-2'
|
small ? 'py-1 mx-1' : 'h-10 mx-2'
|
||||||
}`}
|
}`}
|
||||||
|
disabled={
|
||||||
|
props.disabled
|
||||||
|
? true
|
||||||
|
: !(optionsEnumValues.length || options?.length)
|
||||||
|
}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
|
{!(optionsEnumValues.length || options?.length) && (
|
||||||
|
<option className="dark:bg-gray-700">Loading</option>
|
||||||
|
)}
|
||||||
{optionsEnumValues.length &&
|
{optionsEnumValues.length &&
|
||||||
optionsEnumValues.map(([name, value]) => (
|
optionsEnumValues.map(([name, value]) => (
|
||||||
<option className="dark:bg-gray-700" key={value} value={value}>
|
<option className="dark:bg-gray-700" key={value} value={value}>
|
||||||
|
|||||||
Reference in New Issue
Block a user