Use rome and initial format

This commit is contained in:
Sacha Weatherstone
2023-07-09 13:59:31 +10:00
parent a65bc37be5
commit 20ac657b51
90 changed files with 3350 additions and 3092 deletions
+15 -15
View File
@@ -16,7 +16,7 @@ const actionTypes = {
ADD_TOAST: "ADD_TOAST",
UPDATE_TOAST: "UPDATE_TOAST",
DISMISS_TOAST: "DISMISS_TOAST",
REMOVE_TOAST: "REMOVE_TOAST"
REMOVE_TOAST: "REMOVE_TOAST",
} as const;
let count = 0;
@@ -61,7 +61,7 @@ const addToRemoveQueue = (toastId: string) => {
toastTimeouts.delete(toastId);
dispatch({
type: "REMOVE_TOAST",
toastId: toastId
toastId: toastId,
});
}, TOAST_REMOVE_DELAY);
@@ -73,15 +73,15 @@ export const reducer = (state: State, action: Action): State => {
case "ADD_TOAST":
return {
...state,
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
};
case "UPDATE_TOAST":
return {
...state,
toasts: state.toasts.map((t) =>
t.id === action.toast.id ? { ...t, ...action.toast } : t
)
t.id === action.toast.id ? { ...t, ...action.toast } : t,
),
};
case "DISMISS_TOAST":
@@ -103,21 +103,21 @@ export const reducer = (state: State, action: Action): State => {
t.id === toastId || toastId === undefined
? {
...t,
open: false
open: false,
}
: t
)
: t,
),
};
case "REMOVE_TOAST":
if (action.toastId === undefined) {
return {
...state,
toasts: []
toasts: [],
};
}
return {
...state,
toasts: state.toasts.filter((t) => t.id !== action.toastId)
toasts: state.toasts.filter((t) => t.id !== action.toastId),
};
}
};
@@ -141,7 +141,7 @@ function toast({ ...props }: Toast) {
const update = (props: ToasterToast) =>
dispatch({
type: "UPDATE_TOAST",
toast: { ...props, id }
toast: { ...props, id },
});
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
@@ -153,14 +153,14 @@ function toast({ ...props }: Toast) {
open: true,
onOpenChange: (open) => {
if (!open) dismiss();
}
}
},
},
});
return {
id: id,
dismiss,
update
update,
};
}
@@ -180,7 +180,7 @@ function useToast() {
return {
...state,
toast,
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId })
dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }),
};
}
+12 -12
View File
@@ -48,7 +48,7 @@ export const useAppStore = create<AppState>()((set) => ({
currentPage: "messages",
rasterSources: [],
commandPaletteOpen: false,
darkMode: window.matchMedia('(prefers-color-scheme: dark)').matches,
darkMode: window.matchMedia("(prefers-color-scheme: dark)").matches,
accent: "orange",
connectDialogOpen: false,
@@ -56,61 +56,61 @@ export const useAppStore = create<AppState>()((set) => ({
set(
produce<AppState>((draft) => {
draft.rasterSources = sources;
})
}),
);
},
addRasterSource: (source: RasterSource) => {
set(
produce<AppState>((draft) => {
draft.rasterSources.push(source);
})
}),
);
},
removeRasterSource: (index: number) => {
set(
produce<AppState>((draft) => {
draft.rasterSources.splice(index, 1);
})
}),
);
},
setSelectedDevice: (deviceId) =>
set(() => ({
selectedDevice: deviceId
selectedDevice: deviceId,
})),
addDevice: (device) =>
set((state) => ({
devices: [...state.devices, device]
devices: [...state.devices, device],
})),
removeDevice: (deviceId) =>
set((state) => ({
devices: state.devices.filter((device) => device.id !== deviceId)
devices: state.devices.filter((device) => device.id !== deviceId),
})),
setCommandPaletteOpen: (open: boolean) => {
set(
produce<AppState>((draft) => {
draft.commandPaletteOpen = open;
})
}),
);
},
setDarkMode: (enabled: boolean) => {
set(
produce<AppState>((draft) => {
draft.darkMode = enabled;
})
}),
);
},
setAccent(color) {
set(
produce<AppState>((draft) => {
draft.accent = color;
})
}),
);
},
setConnectDialogOpen: (open: boolean) => {
set(
produce<AppState>((draft) => {
draft.connectDialogOpen = open;
})
}),
);
}
},
}));
+36 -36
View File
@@ -81,7 +81,7 @@ export interface Device {
to: number,
from: number,
messageId: number,
state: MessageState
state: MessageState,
) => void;
setDialogOpen: (dialog: DialogVariant, open: boolean) => void;
processPacket: (data: processPacketParams) => void;
@@ -118,7 +118,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
metadata: new Map(),
messages: {
direct: new Map(),
broadcast: new Map()
broadcast: new Map(),
},
connection: undefined,
activePage: "messages",
@@ -130,7 +130,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
QR: false,
shutdown: false,
reboot: false,
deviceName: false
deviceName: false,
},
pendingSettingsChanges: false,
messageDraft: "",
@@ -142,7 +142,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.status = status;
}
})
}),
);
},
setConfig: (config: Protobuf.Config) => {
@@ -175,7 +175,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
break;
}
}
})
}),
);
},
setModuleConfig: (config: Protobuf.ModuleConfig) => {
@@ -215,7 +215,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
device.moduleConfig.audio = config.payloadVariant.value;
}
}
})
}),
);
},
setWorkingConfig: (config: Protobuf.Config) => {
@@ -226,14 +226,14 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
return;
}
const workingConfigIndex = device?.workingConfig.findIndex(
(wc) => wc.payloadVariant.case === config.payloadVariant.case
(wc) => wc.payloadVariant.case === config.payloadVariant.case,
);
if (workingConfigIndex !== -1) {
device.workingConfig[workingConfigIndex] = config;
} else {
device?.workingConfig.push(config);
}
})
}),
);
},
setWorkingModuleConfig: (moduleConfig: Protobuf.ModuleConfig) => {
@@ -247,7 +247,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
device?.workingModuleConfig.findIndex(
(wmc) =>
wmc.payloadVariant.case ===
moduleConfig.payloadVariant.case
moduleConfig.payloadVariant.case,
);
if (workingModuleConfigIndex !== -1) {
device.workingModuleConfig[workingModuleConfigIndex] =
@@ -255,7 +255,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
} else {
device?.workingModuleConfig.push(moduleConfig);
}
})
}),
);
},
setHardware: (hardware: Protobuf.MyNodeInfo) => {
@@ -265,7 +265,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.hardware = hardware;
}
})
}),
);
},
// setMetrics: (metrics: Types.PacketMetadata<Protobuf.Telemetry>) => {
@@ -319,7 +319,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.activePage = page;
}
})
}),
);
},
setPendingSettingsChanges: (state) => {
@@ -329,7 +329,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.pendingSettingsChanges = state;
}
})
}),
);
},
addChannel: (channel: Protobuf.Channel) => {
@@ -340,7 +340,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
return;
}
device.channels.set(channel.index, channel);
})
}),
);
},
addWaypoint: (waypoint: Protobuf.Waypoint) => {
@@ -349,7 +349,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
const device = draft.devices.get(id);
if (device) {
const waypointIndex = device.waypoints.findIndex(
(wp) => wp.id === waypoint.id
(wp) => wp.id === waypoint.id,
);
if (waypointIndex !== -1) {
@@ -358,7 +358,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
device.waypoints.push(waypoint);
}
}
})
}),
);
},
addNodeInfo: (nodeInfo) => {
@@ -369,7 +369,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
return;
}
device.nodes.set(nodeInfo.num, nodeInfo);
})
}),
);
},
setActivePeer: (peer) => {
@@ -379,7 +379,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.activePeer = peer;
}
})
}),
);
},
addUser: (user) => {
@@ -393,7 +393,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
device.nodes.get(user.from) ?? new Protobuf.NodeInfo();
currentNode.user = user.data;
device.nodes.set(user.from, currentNode);
})
}),
);
},
addPosition: (position) => {
@@ -407,7 +407,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
device.nodes.get(position.from) ?? new Protobuf.NodeInfo();
currentNode.position = position.data;
device.nodes.set(position.from, currentNode);
})
}),
);
},
addConnection: (connection) => {
@@ -417,7 +417,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.connection = connection;
}
})
}),
);
},
addMessage: (message) => {
@@ -442,7 +442,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
} else {
messageGroup.set(messageIndex, [message]);
}
})
}),
);
},
addMetadata: (from, metadata) => {
@@ -453,7 +453,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
return;
}
device.metadata.set(from, metadata);
})
}),
);
},
setMessageState: (
@@ -462,7 +462,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
to: number,
from: number,
messageId: number,
state: MessageState
state: MessageState,
) => {
set(
produce<DeviceState>((draft) => {
@@ -494,9 +494,9 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
msg.state = state;
}
return msg;
})
}),
);
})
}),
);
},
setDialogOpen: (dialog: DialogVariant, open: boolean) => {
@@ -507,7 +507,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
return;
}
device.dialog[dialog] = open;
})
}),
);
},
processPacket(data: processPacketParams) {
@@ -524,17 +524,17 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
new Protobuf.NodeInfo({
num: data.from,
lastHeard: data.time,
snr: data.snr
})
snr: data.snr,
}),
);
} else {
device.nodes.set(data.from, {
...node,
lastHeard: data.time,
snr: data.snr
snr: data.snr,
});
}
})
}),
);
},
setMessageDraft: (message: string) => {
@@ -544,11 +544,11 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
if (device) {
device.messageDraft = message;
}
})
}),
);
}
},
});
})
}),
);
const device = get().devices.get(id);
@@ -562,13 +562,13 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
set(
produce<DeviceState>((draft) => {
draft.devices.delete(id);
})
}),
);
},
getDevices: () => Array.from(get().devices.values()),
getDevice: (id) => get().devices.get(id)
getDevice: (id) => get().devices.get(id),
}));
export const DeviceContext = createContext<Device | undefined>(undefined);
+3 -3
View File
@@ -3,7 +3,7 @@ import { Protobuf, Types } from "@meshtastic/meshtasticjs";
export const subscribeAll = (
device: Device,
connection: Types.ConnectionType
connection: Types.ConnectionType,
) => {
let myNodeNum = 0;
@@ -79,7 +79,7 @@ export const subscribeAll = (
connection.events.onMessagePacket.subscribe((messagePacket) => {
device.addMessage({
...messagePacket,
state: messagePacket.from !== myNodeNum ? "ack" : "waiting"
state: messagePacket.from !== myNodeNum ? "ack" : "waiting",
});
});
@@ -91,7 +91,7 @@ export const subscribeAll = (
device.processPacket({
from: meshPacket.from,
snr: meshPacket.rxSnr,
time: meshPacket.rxTime
time: meshPacket.rxTime,
});
});
};
+1 -1
View File
@@ -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);