minor fixes
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import * as React from "react";
|
||||
import { useEffect, useState, ReactNode } from "react";
|
||||
|
||||
import type { ToastActionElement, ToastProps } from "@components/UI/Toast.js";
|
||||
|
||||
@@ -7,8 +7,8 @@ const TOAST_REMOVE_DELAY = 1000000;
|
||||
|
||||
type ToasterToast = ToastProps & {
|
||||
id: string;
|
||||
title?: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
title?: ReactNode;
|
||||
description?: ReactNode;
|
||||
action?: ToastActionElement;
|
||||
};
|
||||
|
||||
@@ -109,7 +109,7 @@ export const reducer = (state: State, action: Action): State => {
|
||||
),
|
||||
};
|
||||
}
|
||||
case "REMOVE_TOAST":
|
||||
case "REMOVE_TOAST": {
|
||||
if (action.toastId === undefined) {
|
||||
return {
|
||||
...state,
|
||||
@@ -120,6 +120,7 @@ export const reducer = (state: State, action: Action): State => {
|
||||
...state,
|
||||
toasts: state.toasts.filter((t) => t.id !== action.toastId),
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -166,9 +167,9 @@ function toast({ ...props }: Toast) {
|
||||
}
|
||||
|
||||
function useToast() {
|
||||
const [state, setState] = React.useState<State>(memoryState);
|
||||
const [state, setState] = useState<State>(memoryState);
|
||||
|
||||
React.useEffect(() => {
|
||||
useEffect(() => {
|
||||
listeners.push(setState);
|
||||
return () => {
|
||||
const index = listeners.indexOf(setState);
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface RasterSource {
|
||||
tileSize: number;
|
||||
}
|
||||
|
||||
export type accentColor =
|
||||
export type AccentColor =
|
||||
| "red"
|
||||
| "orange"
|
||||
| "yellow"
|
||||
@@ -26,7 +26,7 @@ interface AppState {
|
||||
rasterSources: RasterSource[];
|
||||
commandPaletteOpen: boolean;
|
||||
darkMode: boolean;
|
||||
accent: accentColor;
|
||||
accent: AccentColor;
|
||||
connectDialogOpen: boolean;
|
||||
|
||||
setRasterSources: (sources: RasterSource[]) => void;
|
||||
@@ -38,7 +38,7 @@ interface AppState {
|
||||
removeDevice: (deviceId: number) => void;
|
||||
setCommandPaletteOpen: (open: boolean) => void;
|
||||
setDarkMode: (enabled: boolean) => void;
|
||||
setAccent: (color: accentColor) => void;
|
||||
setAccent: (color: AccentColor) => void;
|
||||
setConnectDialogOpen: (open: boolean) => void;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { produce } from "immer";
|
||||
import { create } from "zustand";
|
||||
|
||||
import { Protobuf, Types } from "@meshtastic/meshtasticjs";
|
||||
import { channel } from "diagnostics_channel";
|
||||
|
||||
export type Page = "messages" | "map" | "config" | "channels" | "peers";
|
||||
|
||||
@@ -14,7 +13,7 @@ export interface MessageWithState extends Types.PacketMetadata<string> {
|
||||
|
||||
export type MessageState = "ack" | "waiting" | Protobuf.Routing_Error;
|
||||
|
||||
export interface processPacketParams {
|
||||
export interface ProcessPacketParams {
|
||||
from: number;
|
||||
snr: number;
|
||||
time: number;
|
||||
@@ -84,7 +83,7 @@ export interface Device {
|
||||
state: MessageState,
|
||||
) => void;
|
||||
setDialogOpen: (dialog: DialogVariant, open: boolean) => void;
|
||||
processPacket: (data: processPacketParams) => void;
|
||||
processPacket: (data: ProcessPacketParams) => void;
|
||||
setMessageDraft: (message: string) => void;
|
||||
}
|
||||
|
||||
@@ -152,27 +151,34 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
|
||||
if (device) {
|
||||
switch (config.payloadVariant.case) {
|
||||
case "device":
|
||||
case "device": {
|
||||
device.config.device = config.payloadVariant.value;
|
||||
break;
|
||||
case "position":
|
||||
}
|
||||
case "position": {
|
||||
device.config.position = config.payloadVariant.value;
|
||||
break;
|
||||
case "power":
|
||||
}
|
||||
case "power": {
|
||||
device.config.power = config.payloadVariant.value;
|
||||
break;
|
||||
case "network":
|
||||
}
|
||||
case "network": {
|
||||
device.config.network = config.payloadVariant.value;
|
||||
break;
|
||||
case "display":
|
||||
}
|
||||
case "display": {
|
||||
device.config.display = config.payloadVariant.value;
|
||||
break;
|
||||
case "lora":
|
||||
}
|
||||
case "lora": {
|
||||
device.config.lora = config.payloadVariant.value;
|
||||
break;
|
||||
case "bluetooth":
|
||||
}
|
||||
case "bluetooth": {
|
||||
device.config.bluetooth = config.payloadVariant.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
@@ -185,43 +191,58 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
|
||||
if (device) {
|
||||
switch (config.payloadVariant.case) {
|
||||
case "mqtt":
|
||||
case "mqtt": {
|
||||
device.moduleConfig.mqtt = config.payloadVariant.value;
|
||||
break;
|
||||
case "serial":
|
||||
}
|
||||
case "serial": {
|
||||
device.moduleConfig.serial = config.payloadVariant.value;
|
||||
break;
|
||||
case "externalNotification":
|
||||
}
|
||||
case "externalNotification": {
|
||||
device.moduleConfig.externalNotification =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "storeForward":
|
||||
}
|
||||
case "storeForward": {
|
||||
device.moduleConfig.storeForward =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "rangeTest":
|
||||
}
|
||||
case "rangeTest": {
|
||||
device.moduleConfig.rangeTest =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "telemetry":
|
||||
}
|
||||
case "telemetry": {
|
||||
device.moduleConfig.telemetry =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "cannedMessage":
|
||||
}
|
||||
case "cannedMessage": {
|
||||
device.moduleConfig.cannedMessage =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "audio":
|
||||
}
|
||||
case "audio": {
|
||||
device.moduleConfig.audio = config.payloadVariant.value;
|
||||
break;
|
||||
case "neighborInfo":
|
||||
device.moduleConfig.neighborInfo = config.payloadVariant.value;
|
||||
}
|
||||
case "neighborInfo": {
|
||||
device.moduleConfig.neighborInfo =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "ambientLighting":
|
||||
device.moduleConfig.ambientLighting = config.payloadVariant.value;
|
||||
}
|
||||
case "ambientLighting": {
|
||||
device.moduleConfig.ambientLighting =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
case "detectionSensor":
|
||||
device.moduleConfig.detectionSensor = config.payloadVariant.value;
|
||||
}
|
||||
case "detectionSensor": {
|
||||
device.moduleConfig.detectionSensor =
|
||||
config.payloadVariant.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
@@ -519,7 +540,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
}),
|
||||
);
|
||||
},
|
||||
processPacket(data: processPacketParams) {
|
||||
processPacket(data: ProcessPacketParams) {
|
||||
set(
|
||||
produce<DeviceState>((draft) => {
|
||||
const device = draft.devices.get(id);
|
||||
@@ -527,7 +548,13 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
return;
|
||||
}
|
||||
const node = device.nodes.get(data.from);
|
||||
if (!node) {
|
||||
if (node) {
|
||||
device.nodes.set(data.from, {
|
||||
...node,
|
||||
lastHeard: data.time,
|
||||
snr: data.snr,
|
||||
});
|
||||
} else {
|
||||
device.nodes.set(
|
||||
data.from,
|
||||
new Protobuf.NodeInfo({
|
||||
@@ -536,12 +563,6 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
snr: data.snr,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
device.nodes.set(data.from, {
|
||||
...node,
|
||||
lastHeard: data.time,
|
||||
snr: data.snr,
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -16,20 +16,21 @@ export const subscribeAll = (
|
||||
|
||||
connection.events.onRoutingPacket.subscribe((routingPacket) => {
|
||||
switch (routingPacket.data.variant.case) {
|
||||
case "errorReason":
|
||||
case "errorReason": {
|
||||
if (routingPacket.data.variant.value === Protobuf.Routing_Error.NONE) {
|
||||
return;
|
||||
}
|
||||
console.log(`Routing Error: ${routingPacket.data.variant.value}`);
|
||||
break;
|
||||
case "routeReply":
|
||||
}
|
||||
case "routeReply": {
|
||||
console.log(`Route Reply: ${routingPacket.data.variant.value}`);
|
||||
|
||||
break;
|
||||
case "routeRequest":
|
||||
}
|
||||
case "routeRequest": {
|
||||
console.log(`Route Request: ${routingPacket.data.variant.value}`);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export interface enumLike {
|
||||
export interface EnumLike {
|
||||
[key: number]: string | number;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export const bitwiseEncode = (enumValues: number[]): number => {
|
||||
|
||||
export const bitwiseDecode = (
|
||||
value: number,
|
||||
decodeEnum: enumLike,
|
||||
decodeEnum: EnumLike,
|
||||
): number[] => {
|
||||
const enumValues = Object.keys(decodeEnum).map(Number).filter(Boolean);
|
||||
return enumValues.map((b) => value & b).filter(Boolean);
|
||||
|
||||
Reference in New Issue
Block a user