cleanup dialog state
This commit is contained in:
@@ -77,14 +77,7 @@ export const CommandPalette = (): JSX.Element => {
|
|||||||
} = useAppStore();
|
} = useAppStore();
|
||||||
const { getDevices } = useDeviceStore();
|
const { getDevices } = useDeviceStore();
|
||||||
|
|
||||||
const {
|
const { setDialogOpen, setActivePage, connection } = useDevice();
|
||||||
setQRDialogOpen,
|
|
||||||
setImportDialogOpen,
|
|
||||||
setShutdownDialogOpen,
|
|
||||||
setRebootDialogOpen,
|
|
||||||
setActivePage,
|
|
||||||
connection
|
|
||||||
} = useDevice();
|
|
||||||
|
|
||||||
const groups: Group[] = [
|
const groups: Group[] = [
|
||||||
{
|
{
|
||||||
@@ -182,14 +175,14 @@ export const CommandPalette = (): JSX.Element => {
|
|||||||
name: "Generator",
|
name: "Generator",
|
||||||
icon: <QueueListIcon className="w-4" />,
|
icon: <QueueListIcon className="w-4" />,
|
||||||
action() {
|
action() {
|
||||||
setQRDialogOpen(true);
|
setDialogOpen("QR", true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Import",
|
name: "Import",
|
||||||
icon: <ArrowDownOnSquareStackIcon className="w-4" />,
|
icon: <ArrowDownOnSquareStackIcon className="w-4" />,
|
||||||
action() {
|
action() {
|
||||||
setImportDialogOpen(true);
|
setDialogOpen("import", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -207,14 +200,14 @@ export const CommandPalette = (): JSX.Element => {
|
|||||||
name: "Schedule Shutdown",
|
name: "Schedule Shutdown",
|
||||||
icon: PowerIcon,
|
icon: PowerIcon,
|
||||||
action() {
|
action() {
|
||||||
setShutdownDialogOpen(true);
|
setDialogOpen("shutdown", true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Schedule Reboot",
|
name: "Schedule Reboot",
|
||||||
icon: ArrowPathIcon,
|
icon: ArrowPathIcon,
|
||||||
action() {
|
action() {
|
||||||
setRebootDialogOpen(true);
|
setDialogOpen("reboot", true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,46 +8,35 @@ import { ShutdownDialog } from "./ShutdownDialog.js";
|
|||||||
import { ImportDialog } from "./ImportDialog.js";
|
import { ImportDialog } from "./ImportDialog.js";
|
||||||
|
|
||||||
export const DialogManager = (): JSX.Element => {
|
export const DialogManager = (): JSX.Element => {
|
||||||
const {
|
const { channels, config, dialog, setDialogOpen } = useDevice();
|
||||||
channels,
|
|
||||||
config,
|
|
||||||
importDialogOpen,
|
|
||||||
setImportDialogOpen,
|
|
||||||
QRDialogOpen,
|
|
||||||
setQRDialogOpen,
|
|
||||||
shutdownDialogOpen,
|
|
||||||
setShutdownDialogOpen,
|
|
||||||
rebootDialogOpen,
|
|
||||||
setRebootDialogOpen
|
|
||||||
} = useDevice();
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<QRDialog
|
<QRDialog
|
||||||
isOpen={QRDialogOpen}
|
isOpen={dialog.QR}
|
||||||
close={() => {
|
close={() => {
|
||||||
setQRDialogOpen(false);
|
setDialogOpen("QR", false);
|
||||||
}}
|
}}
|
||||||
channels={channels.map((ch) => ch.config)}
|
channels={channels.map((ch) => ch.config)}
|
||||||
loraConfig={config.lora}
|
loraConfig={config.lora}
|
||||||
/>
|
/>
|
||||||
<ImportDialog
|
<ImportDialog
|
||||||
isOpen={importDialogOpen}
|
isOpen={dialog.import}
|
||||||
close={() => {
|
close={() => {
|
||||||
setImportDialogOpen(false);
|
setDialogOpen("import", false);
|
||||||
}}
|
}}
|
||||||
channels={channels.map((ch) => ch.config)}
|
channels={channels.map((ch) => ch.config)}
|
||||||
loraConfig={config.lora}
|
loraConfig={config.lora}
|
||||||
/>
|
/>
|
||||||
<ShutdownDialog
|
<ShutdownDialog
|
||||||
isOpen={shutdownDialogOpen}
|
isOpen={dialog.shutdown}
|
||||||
close={() => {
|
close={() => {
|
||||||
setShutdownDialogOpen(false);
|
setDialogOpen("shutdown", false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<RebootDialog
|
<RebootDialog
|
||||||
isOpen={rebootDialogOpen}
|
isOpen={dialog.reboot}
|
||||||
close={() => {
|
close={() => {
|
||||||
setRebootDialogOpen(false);
|
setDialogOpen("reboot", false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const RebootDialog = ({
|
|||||||
isOpen,
|
isOpen,
|
||||||
close
|
close
|
||||||
}: RebootDialogProps): JSX.Element => {
|
}: RebootDialogProps): JSX.Element => {
|
||||||
const { connection, setRebootDialogOpen } = useDevice();
|
const { connection, setDialogOpen } = useDevice();
|
||||||
|
|
||||||
const [time, setTime] = useState<number>(5);
|
const [time, setTime] = useState<number>(5);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ export const RebootDialog = ({
|
|||||||
action() {
|
action() {
|
||||||
connection
|
connection
|
||||||
?.reboot(time * 60)
|
?.reboot(time * 60)
|
||||||
.then(() => setRebootDialogOpen(false));
|
.then(() => setDialogOpen("reboot", false));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -46,7 +46,7 @@ export const RebootDialog = ({
|
|||||||
className="w-24"
|
className="w-24"
|
||||||
iconBefore={<ArrowPathIcon className="w-4" />}
|
iconBefore={<ArrowPathIcon className="w-4" />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
connection?.reboot(2).then(() => setRebootDialogOpen(false));
|
connection?.reboot(2).then(() => setDialogOpen("reboot", false));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Now
|
Now
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export const ShutdownDialog = ({
|
|||||||
isOpen,
|
isOpen,
|
||||||
close
|
close
|
||||||
}: ShutdownDialogProps): JSX.Element => {
|
}: ShutdownDialogProps): JSX.Element => {
|
||||||
const { connection, setShutdownDialogOpen } = useDevice();
|
const { connection, setDialogOpen } = useDevice();
|
||||||
|
|
||||||
const [time, setTime] = useState<number>(5);
|
const [time, setTime] = useState<number>(5);
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ export const ShutdownDialog = ({
|
|||||||
action() {
|
action() {
|
||||||
connection
|
connection
|
||||||
?.shutdown(time * 60)
|
?.shutdown(time * 60)
|
||||||
.then(() => setShutdownDialogOpen(false));
|
.then(() => setDialogOpen("shutdown", false));
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -46,7 +46,9 @@ export const ShutdownDialog = ({
|
|||||||
className="w-24"
|
className="w-24"
|
||||||
iconBefore={<PowerIcon className="w-4" />}
|
iconBefore={<PowerIcon className="w-4" />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
connection?.shutdown(2).then(() => setShutdownDialogOpen(false));
|
connection
|
||||||
|
?.shutdown(2)
|
||||||
|
.then(() => setDialogOpen("shutdown", false));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Now
|
Now
|
||||||
|
|||||||
@@ -52,6 +52,18 @@ export interface processPacketParams {
|
|||||||
time: number;
|
time: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type WorkingConfig = [
|
||||||
|
Protobuf.Config_DeviceConfig?,
|
||||||
|
Protobuf.Config_PositionConfig?,
|
||||||
|
Protobuf.Config_PowerConfig?,
|
||||||
|
Protobuf.Config_NetworkConfig?,
|
||||||
|
Protobuf.Config_DisplayConfig?,
|
||||||
|
Protobuf.Config_LoRaConfig?,
|
||||||
|
Protobuf.Config_BluetoothConfig?
|
||||||
|
];
|
||||||
|
|
||||||
|
export type DialogVariant = "import" | "QR" | "shutdown" | "reboot";
|
||||||
|
|
||||||
export interface Device {
|
export interface Device {
|
||||||
id: number;
|
id: number;
|
||||||
ready: boolean;
|
ready: boolean;
|
||||||
@@ -68,12 +80,15 @@ export interface Device {
|
|||||||
waypoints: Protobuf.Waypoint[];
|
waypoints: Protobuf.Waypoint[];
|
||||||
regionUnset: boolean;
|
regionUnset: boolean;
|
||||||
currentMetrics: Protobuf.DeviceMetrics;
|
currentMetrics: Protobuf.DeviceMetrics;
|
||||||
importDialogOpen: boolean;
|
|
||||||
QRDialogOpen: boolean;
|
|
||||||
shutdownDialogOpen: boolean;
|
|
||||||
rebootDialogOpen: boolean;
|
|
||||||
pendingSettingsChanges: boolean;
|
pendingSettingsChanges: boolean;
|
||||||
messageDraft: string;
|
messageDraft: string;
|
||||||
|
workingConfig: WorkingConfig;
|
||||||
|
dialog: {
|
||||||
|
import: boolean;
|
||||||
|
QR: boolean;
|
||||||
|
shutdown: boolean;
|
||||||
|
reboot: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
setReady(ready: boolean): void;
|
setReady(ready: boolean): void;
|
||||||
setStatus: (status: Types.DeviceStatusEnum) => void;
|
setStatus: (status: Types.DeviceStatusEnum) => void;
|
||||||
@@ -101,10 +116,7 @@ export interface Device {
|
|||||||
messageId: number,
|
messageId: number,
|
||||||
state: MessageState
|
state: MessageState
|
||||||
) => void;
|
) => void;
|
||||||
setImportDialogOpen: (open: boolean) => void;
|
setDialogOpen: (dialog: DialogVariant, open: boolean) => void;
|
||||||
setQRDialogOpen: (open: boolean) => void;
|
|
||||||
setShutdownDialogOpen: (open: boolean) => void;
|
|
||||||
setRebootDialogOpen: (open: boolean) => void;
|
|
||||||
processPacket: (data: processPacketParams) => void;
|
processPacket: (data: processPacketParams) => void;
|
||||||
setMessageDraft: (message: string) => void;
|
setMessageDraft: (message: string) => void;
|
||||||
}
|
}
|
||||||
@@ -142,12 +154,15 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
waypoints: [],
|
waypoints: [],
|
||||||
regionUnset: false,
|
regionUnset: false,
|
||||||
currentMetrics: new Protobuf.DeviceMetrics(),
|
currentMetrics: new Protobuf.DeviceMetrics(),
|
||||||
importDialogOpen: false,
|
dialog: {
|
||||||
QRDialogOpen: false,
|
import: false,
|
||||||
shutdownDialogOpen: false,
|
QR: false,
|
||||||
rebootDialogOpen: false,
|
shutdown: false,
|
||||||
|
reboot: false
|
||||||
|
},
|
||||||
pendingSettingsChanges: false,
|
pendingSettingsChanges: false,
|
||||||
messageDraft: "",
|
messageDraft: "",
|
||||||
|
workingConfig: [],
|
||||||
|
|
||||||
setReady: (ready: boolean) => {
|
setReady: (ready: boolean) => {
|
||||||
set(
|
set(
|
||||||
@@ -486,43 +501,14 @@ export const useDeviceStore = create<DeviceState>((set, get) => ({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
setImportDialogOpen: (open: boolean) => {
|
setDialogOpen: (dialog: DialogVariant, open: boolean) => {
|
||||||
set(
|
set(
|
||||||
produce<DeviceState>((draft) => {
|
produce<DeviceState>((draft) => {
|
||||||
const device = draft.devices.get(id);
|
const device = draft.devices.get(id);
|
||||||
if (device) {
|
if (!device) {
|
||||||
device.importDialogOpen = open;
|
return;
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setQRDialogOpen: (open: boolean) => {
|
|
||||||
set(
|
|
||||||
produce<DeviceState>((draft) => {
|
|
||||||
const device = draft.devices.get(id);
|
|
||||||
if (device) {
|
|
||||||
device.QRDialogOpen = open;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setShutdownDialogOpen: (open: boolean) => {
|
|
||||||
set(
|
|
||||||
produce<DeviceState>((draft) => {
|
|
||||||
const device = draft.devices.get(id);
|
|
||||||
if (device) {
|
|
||||||
device.shutdownDialogOpen = open;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
setRebootDialogOpen: (open: boolean) => {
|
|
||||||
set(
|
|
||||||
produce<DeviceState>((draft) => {
|
|
||||||
const device = draft.devices.get(id);
|
|
||||||
if (device) {
|
|
||||||
device.rebootDialogOpen = open;
|
|
||||||
}
|
}
|
||||||
|
device.dialog[dialog] = open;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
import { Protobuf } from "@meshtastic/meshtasticjs";
|
import { Protobuf } from "@meshtastic/meshtasticjs";
|
||||||
|
|
||||||
export const ChannelsPage = (): JSX.Element => {
|
export const ChannelsPage = (): JSX.Element => {
|
||||||
const { channels, setQRDialogOpen, setImportDialogOpen } = useDevice();
|
const { channels, setDialogOpen } = useDevice();
|
||||||
|
|
||||||
const tabs: TabType[] = channels.map((channel) => {
|
const tabs: TabType[] = channels.map((channel) => {
|
||||||
return {
|
return {
|
||||||
@@ -30,11 +30,11 @@ export const ChannelsPage = (): JSX.Element => {
|
|||||||
actions={[
|
actions={[
|
||||||
{
|
{
|
||||||
icon: <ArrowDownOnSquareStackIcon className="w-4" />,
|
icon: <ArrowDownOnSquareStackIcon className="w-4" />,
|
||||||
action: () => setImportDialogOpen(true)
|
action: () => setDialogOpen("import", true)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <QrCodeIcon className="w-4" />,
|
icon: <QrCodeIcon className="w-4" />,
|
||||||
action: () => setQRDialogOpen(true)
|
action: () => setDialogOpen("QR", true)
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user