2.0 Overhaul start
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { createContext, useContext } from 'react';
|
||||
|
||||
import type { Device } from "@core/stores/deviceStore.js";
|
||||
import type { Device } from '@core/stores/deviceStore.js';
|
||||
|
||||
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");
|
||||
throw new Error("useDevice must be used within a DeviceProvider");
|
||||
}
|
||||
return context;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import create from "zustand";
|
||||
import create from 'zustand';
|
||||
|
||||
interface AppState {
|
||||
selectedDevice?: number;
|
||||
selectedDevice: number;
|
||||
devices: {
|
||||
id: number;
|
||||
num: number;
|
||||
|
||||
@@ -79,6 +79,7 @@ export interface DeviceState {
|
||||
addDevice: (id: number) => Device;
|
||||
removeDevice: (id: number) => void;
|
||||
getDevices: () => Device[];
|
||||
getDevice: (id: number) => Device | undefined;
|
||||
}
|
||||
|
||||
export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
@@ -470,6 +471,8 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
||||
},
|
||||
|
||||
getDevices: () => Array.from(get().devices.values()),
|
||||
|
||||
getDevice: (id) => get().devices.get(id),
|
||||
}));
|
||||
|
||||
export const DeviceContext = createContext<Device | undefined>(undefined);
|
||||
|
||||
Reference in New Issue
Block a user