more state changes

This commit is contained in:
Sacha Weatherstone
2023-02-20 21:07:55 +10:00
parent e6d17692da
commit 0894fd76f5
10 changed files with 112 additions and 213 deletions
+5 -11
View File
@@ -30,7 +30,7 @@ export type DialogVariant =
export interface Device {
id: number;
status: Types.DeviceStatusEnum;
channels: Protobuf.Channel[];
channels: Map<Types.ChannelNumber, Protobuf.Channel>;
config: Protobuf.LocalConfig;
moduleConfig: Protobuf.LocalModuleConfig;
workingConfig: Protobuf.Config[];
@@ -108,7 +108,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
draft.devices.set(id, {
id,
status: Types.DeviceStatusEnum.DEVICE_DISCONNECTED,
channels: [],
channels: new Map(),
config: new Protobuf.LocalConfig(),
moduleConfig: new Protobuf.LocalModuleConfig(),
workingConfig: [],
@@ -336,16 +336,10 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
set(
produce<DeviceState>((draft) => {
const device = draft.devices.get(id);
if (device) {
const channelIndex = device.channels.findIndex(
(c) => c.index === channel.index
);
if (channelIndex !== -1) {
device.channels[channelIndex] = channel;
} else {
device.channels.push(channel);
}
if (!device) {
return;
}
device.channels.set(channel.index, channel);
})
);
},