minor fixes

This commit is contained in:
Sacha Weatherstone
2023-12-17 12:58:14 +10:00
parent e3aee4cebd
commit f7ba8ad967
14 changed files with 112 additions and 89 deletions
@@ -17,16 +17,16 @@ export const BLE = (): JSX.Element => {
}, []);
useEffect(() => {
void updateBleDeviceList();
updateBleDeviceList();
}, [updateBleDeviceList]);
const onConnect = async (BLEDevice: BluetoothDevice) => {
const onConnect = async (bleDevice: BluetoothDevice) => {
const id = randId();
const device = addDevice(id);
setSelectedDevice(id);
const connection = new IBLEConnection(id);
await connection.connect({
device: BLEDevice,
device: bleDevice,
});
device.addConnection(connection);
subscribeAll(device, connection);
@@ -39,7 +39,7 @@ export const BLE = (): JSX.Element => {
<Button
key={device.id}
onClick={() => {
void onConnect(device);
onConnect(device);
}}
>
{device.name}
@@ -50,8 +50,8 @@ export const BLE = (): JSX.Element => {
)}
</div>
<Button
onClick={() => {
void navigator.bluetooth
onClick={async () => {
await navigator.bluetooth
.requestDevice({
filters: [{ services: [Constants.ServiceUuid] }],
})
@@ -1,7 +1,6 @@
import { Button } from "@components/UI/Button.js";
import { Input } from "@components/UI/Input.js";
import { Label } from "@components/UI/Label.js";
import { SelectLabel } from "@components/UI/Select.js";
import { Switch } from "@components/UI/Switch.js";
import { useAppStore } from "@core/stores/appStore.js";
import { useDeviceStore } from "@core/stores/deviceStore.js";
@@ -27,19 +26,19 @@ export const HTTP = (): JSX.Element => {
},
});
const TLSEnabled = useWatch({
const tlsEnabled = useWatch({
control,
name: "tls",
defaultValue: location.protocol === "https:",
});
const onSubmit = handleSubmit((data) => {
const onSubmit = handleSubmit(async (data) => {
const id = randId();
const device = addDevice(id);
setSelectedDevice(id);
const connection = new IHTTPConnection(id);
// TODO: Promise never resolves
void connection.connect({
await connection.connect({
address: data.ip,
fetchInterval: 2000,
tls: data.tls,
@@ -49,13 +48,12 @@ export const HTTP = (): JSX.Element => {
});
return (
// eslint-disable-next-line @typescript-eslint/no-misused-promises
<form className="flex w-full flex-col gap-2 p-4" onSubmit={onSubmit}>
<div className="flex h-48 flex-col gap-2">
<Label>IP Address/Hostname</Label>
<Input
// label="IP Address/Hostname"
prefix={TLSEnabled ? "https://" : "http://"}
prefix={tlsEnabled ? "https://" : "http://"}
placeholder="000.000.000.000 / meshtastic.local"
{...register("ip")}
/>
@@ -17,13 +17,13 @@ export const Serial = (): JSX.Element => {
}, []);
navigator.serial.addEventListener("connect", () => {
void updateSerialPortList();
updateSerialPortList();
});
navigator.serial.addEventListener("disconnect", () => {
void updateSerialPortList();
updateSerialPortList();
});
useEffect(() => {
void updateSerialPortList();
updateSerialPortList();
}, [updateSerialPortList]);
const onConnect = async (port: SerialPort) => {
@@ -49,8 +49,8 @@ export const Serial = (): JSX.Element => {
<Button
key={index}
disabled={port.readable !== null}
onClick={() => {
void onConnect(port);
onClick={async () => {
await onConnect(port);
}}
>
{`# ${index} - ${port.getInfo().usbVendorId ?? "UNK"} - ${
@@ -63,8 +63,8 @@ export const Serial = (): JSX.Element => {
)}
</div>
<Button
onClick={() => {
void navigator.serial.requestPort().then((port) => {
onClick={async () => {
await navigator.serial.requestPort().then((port) => {
setSerialPorts(serialPorts.concat(port));
});
}}
@@ -61,7 +61,7 @@ export const MessageInput = ({
<div className="flex flex-grow gap-2">
<span className="w-full">
<Input
autoFocus
autoFocus={true}
minLength={2}
placeholder="Enter Message"
value={messageDraft}