Browse Source

Config stuff

pull/110/head
Malte Grimm 3 years ago
parent
commit
487017a837
  1. 16
      src/components/Dashboard.tsx
  2. 21
      src/components/PageComponents/Config/Device.tsx
  3. 10
      src/core/stores/deviceStore.ts
  4. 8
      src/pages/Config/DeviceConfig.tsx

16
src/components/Dashboard.tsx

@ -71,11 +71,12 @@ const DeviceList = ({devices}: {devices: Device[]}) => {
return ( return (
<div className="flex rounded-md border border-dashed border-slate-200 h-1/2 p-3 mb-2 dark:border-slate-700"> <div className="flex rounded-md border border-dashed border-slate-200 h-1/2 p-3 mb-2 dark:border-slate-700">
{devices.length ? ( {devices.length ? (
<div className="flex flex-col justify-between w-full">
<ul role="list" className="grow divide-y divide-gray-200"> <ul role="list" className="grow divide-y divide-gray-200">
{devices.map((device, index) => { {devices.map((device, index) => {
return ( return (
<li key={device.id}> <li key={device.id}>
<div className="px-4 py-4 sm:px-6"> <div className="py-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
<p className="truncate text-sm font-medium text-accent"> <p className="truncate text-sm font-medium text-accent">
{device.nodes.get(device.hardware.myNodeNum)?.user {device.nodes.get(device.hardware.myNodeNum)?.user
@ -103,7 +104,7 @@ const DeviceList = ({devices}: {devices: Device[]}) => {
</div> </div>
</div> </div>
<div className="mt-1 sm:flex sm:justify-between"> <div className="mt-1 sm:flex sm:justify-between">
<div className="flex gap-2 items-center text-sm text-gray-500"> <div className="flex gap-2 w-full items-center text-sm text-gray-500">
<UsersIcon <UsersIcon
size={20} size={20}
className="text-gray-400" className="text-gray-400"
@ -113,7 +114,7 @@ const DeviceList = ({devices}: {devices: Device[]}) => {
<Button <Button
variant={devicesToFlash[index] ? "default" : "outline"} variant={devicesToFlash[index] ? "default" : "outline"}
size="sm" size="sm"
className="w-full justify-start gap-2" className="w-full gap-2 h-8"
onClick={() => { onClick={() => {
// TODO: HACKY AF, fix. // TODO: HACKY AF, fix.
// Used to make sure page rerenders but this has issues // Used to make sure page rerenders but this has issues
@ -125,7 +126,7 @@ const DeviceList = ({devices}: {devices: Device[]}) => {
// toggleDeviceFlash(device); // toggleDeviceFlash(device);
}} }}
> >
{devicesToFlash[index] ? "Yes" : "No"} {devicesToFlash[index] ? "Enabled" : "Disabled"}
</Button> </Button>
</div> </div>
@ -135,6 +136,13 @@ const DeviceList = ({devices}: {devices: Device[]}) => {
); );
})} })}
</ul> </ul>
<Button
className="gap-2"
onClick={() => setConnectDialogOpen(true)}
>
Flash
</Button>
</div>
) : ( ) : (
<div className="m-auto flex flex-col gap-3 text-center"> <div className="m-auto flex flex-col gap-3 text-center">
<ListPlusIcon size={48} className="mx-auto text-textSecondary" /> <ListPlusIcon size={48} className="mx-auto text-textSecondary" />

21
src/components/PageComponents/Config/Device.tsx

@ -1,20 +1,21 @@
import type { DeviceValidation } from "@app/validation/config/device.js"; import type { DeviceValidation } from "@app/validation/config/device.js";
import { useDevice } from "@core/stores/deviceStore.js"; import { useConfig, useDevice } from "@core/stores/deviceStore.js";
import { Protobuf } from "@meshtastic/meshtasticjs"; import { Protobuf } from "@meshtastic/meshtasticjs";
import { DynamicForm } from "@components/Form/DynamicForm.js"; import { DynamicForm } from "@components/Form/DynamicForm.js";
export const Device = (): JSX.Element => { export const Device = (): JSX.Element => {
const { config, setWorkingConfig } = useDevice(); // const { config, setWorkingConfig } = useDevice();
const config = useConfig();
const onSubmit = (data: DeviceValidation) => { const onSubmit = (data: DeviceValidation) => {
setWorkingConfig( // setWorkingConfig(
new Protobuf.Config({ // new Protobuf.Config({
payloadVariant: { // payloadVariant: {
case: "device", // case: "device",
value: data // value: data
} // }
}) // })
); // );
}; };
return ( return (

10
src/core/stores/deviceStore.ts

@ -5,6 +5,7 @@ import { create } from "zustand";
import { Protobuf, Types } from "@meshtastic/meshtasticjs"; import { Protobuf, Types } from "@meshtastic/meshtasticjs";
import { channel } from "diagnostics_channel"; import { channel } from "diagnostics_channel";
import { useAppStore } from "./appStore";
export type Page = "messages" | "map" | "config" | "channels" | "peers"; export type Page = "messages" | "map" | "config" | "channels" | "peers";
@ -593,3 +594,12 @@ export const useDevice = (): Device => {
} }
return context; return context;
}; };
export const useConfig = (): Protobuf.Config => {
const context = useContext(DeviceContext);
if(context == undefined) {
const {configPresetRoot, configPresetSelected } = useAppStore();
return configPresetRoot.children[configPresetSelected].config;
}
return context.config;
};

8
src/pages/Config/DeviceConfig.tsx

@ -1,4 +1,4 @@
import { Fragment } from "react"; import { Fragment, useContext } from "react";
import { Network } from "@components/PageComponents/Config/Network.js"; import { Network } from "@components/PageComponents/Config/Network.js";
import { Bluetooth } from "@components/PageComponents/Config/Bluetooth.js"; import { Bluetooth } from "@components/PageComponents/Config/Bluetooth.js";
import { Device } from "@components/PageComponents/Config/Device.js"; import { Device } from "@components/PageComponents/Config/Device.js";
@ -6,7 +6,7 @@ import { Display } from "@components/PageComponents/Config/Display.js";
import { LoRa } from "@components/PageComponents/Config/LoRa.js"; import { LoRa } from "@components/PageComponents/Config/LoRa.js";
import { Position } from "@components/PageComponents/Config/Position.js"; import { Position } from "@components/PageComponents/Config/Position.js";
import { Power } from "@components/PageComponents/Config/Power.js"; import { Power } from "@components/PageComponents/Config/Power.js";
import { useDevice } from "@core/stores/deviceStore.js"; import { DeviceContext, useDevice } from "@core/stores/deviceStore.js";
import { import {
Tabs, Tabs,
TabsContent, TabsContent,
@ -15,7 +15,7 @@ import {
} from "@components/UI/Tabs.js"; } from "@components/UI/Tabs.js";
export const DeviceConfig = (): JSX.Element => { export const DeviceConfig = (): JSX.Element => {
const { hardware } = useDevice(); const device = useContext(DeviceContext);
const tabs = [ const tabs = [
{ {
@ -34,7 +34,7 @@ export const DeviceConfig = (): JSX.Element => {
{ {
label: "Network", label: "Network",
element: Network, element: Network,
disabled: !hardware.hasWifi disabled: device && !device.hardware.hasWifi
}, },
{ {
label: "Display", label: "Display",

Loading…
Cancel
Save