add regionUnset, move useDevice out of store
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createContext, useContext } from "react";
|
import { createContext } from "react";
|
||||||
|
|
||||||
import { produce } from "immer";
|
import { produce } from "immer";
|
||||||
import create from "zustand";
|
import create from "zustand";
|
||||||
@@ -45,6 +45,7 @@ export interface Device {
|
|||||||
peerInfoOpen: boolean;
|
peerInfoOpen: boolean;
|
||||||
activePeer: number;
|
activePeer: number;
|
||||||
waypoints: Protobuf.Location[];
|
waypoints: Protobuf.Location[];
|
||||||
|
regionUnset: boolean;
|
||||||
|
|
||||||
setReady(ready: boolean): void;
|
setReady(ready: boolean): void;
|
||||||
setStatus: (status: Types.DeviceStatusEnum) => void;
|
setStatus: (status: Types.DeviceStatusEnum) => void;
|
||||||
@@ -95,6 +96,7 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
peerInfoOpen: false,
|
peerInfoOpen: false,
|
||||||
activePeer: 0,
|
activePeer: 0,
|
||||||
waypoints: [],
|
waypoints: [],
|
||||||
|
regionUnset: false,
|
||||||
|
|
||||||
setReady: (ready: boolean) => {
|
setReady: (ready: boolean) => {
|
||||||
set(
|
set(
|
||||||
@@ -140,6 +142,9 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
break;
|
break;
|
||||||
case "lora":
|
case "lora":
|
||||||
device.config.lora = config.payloadVariant.lora;
|
device.config.lora = config.payloadVariant.lora;
|
||||||
|
device.regionUnset =
|
||||||
|
config.payloadVariant.lora.region ===
|
||||||
|
Protobuf.Config_LoRaConfig_RegionCode.Unset;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,11 +457,3 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const DeviceContext = createContext<Device | undefined>(undefined);
|
export const DeviceContext = createContext<Device | undefined>(undefined);
|
||||||
|
|
||||||
export const useDevice = (): Device => {
|
|
||||||
const context = useContext(DeviceContext);
|
|
||||||
if (context === undefined) {
|
|
||||||
throw new Error("useDevice must be used within a ConnectionProvider");
|
|
||||||
}
|
|
||||||
return context;
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user