From 2c621efdd4dac26ca8dc9ad00bbafa9f979986b9 Mon Sep 17 00:00:00 2001 From: Hunter Thornsberry Date: Thu, 27 Jun 2024 20:37:24 -0400 Subject: [PATCH] basic utc +/- --- biome.json | 2 +- src/components/Form/DynamicFormField.tsx | 5 ++ src/components/Form/FormSelect.tsx | 51 ++++++++++++++++++- .../PageComponents/Config/Device.tsx | 18 ++++++- src/core/utils/tz.ts | 29 +++++++++++ src/validation/config/device.ts | 8 ++- src/validation/config/display.ts | 5 +- src/validation/moduleConfig/paxcounter.ts | 6 +++ 8 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 src/core/utils/tz.ts diff --git a/biome.json b/biome.json index 6d2c7f6c..f21ce5d7 100644 --- a/biome.json +++ b/biome.json @@ -5,7 +5,7 @@ }, "files": { "ignoreUnknown": true, - "ignore": ["vercel.json"] + "ignore": ["vercel.json", "tz.ts"] }, "vcs": { "enabled": true, diff --git a/src/components/Form/DynamicFormField.tsx b/src/components/Form/DynamicFormField.tsx index fc2f7575..42a74b49 100644 --- a/src/components/Form/DynamicFormField.tsx +++ b/src/components/Form/DynamicFormField.tsx @@ -5,6 +5,7 @@ import { import { type SelectFieldProps, SelectInput, + SelectStringInput, } from "@components/Form/FormSelect.js"; import { type ToggleFieldProps, @@ -44,6 +45,10 @@ export function DynamicFormField({ return ( ); + case "stringSelect": + return ( + + ); case "multiSelect": return
tmp
; } diff --git a/src/components/Form/FormSelect.tsx b/src/components/Form/FormSelect.tsx index b0c922d5..fa01ef48 100644 --- a/src/components/Form/FormSelect.tsx +++ b/src/components/Form/FormSelect.tsx @@ -12,7 +12,7 @@ import { import { Controller, type FieldValues } from "react-hook-form"; export interface SelectFieldProps extends BaseFormBuilderProps { - type: "select" | "multiSelect"; + type: "select" | "multiSelect" | "stringSelect"; properties: BaseFormBuilderProps["properties"] & { enumValue: { [s: string]: string | number; @@ -69,3 +69,52 @@ export function SelectInput({ /> ); } + +export function SelectStringInput({ + control, + disabled, + field, +}: GenericFormElementProps>) { + return ( + { + const { enumValue, formatEnumName, ...remainingProperties } = + field.properties; + const optionsEnumValues = enumValue + ? Object.entries(enumValue).filter( + (value) => typeof value[1] === "string", + ) + : []; + return ( + + ); + }} + /> + ); +} diff --git a/src/components/PageComponents/Config/Device.tsx b/src/components/PageComponents/Config/Device.tsx index c0f3bfc4..899152ee 100644 --- a/src/components/PageComponents/Config/Device.tsx +++ b/src/components/PageComponents/Config/Device.tsx @@ -1,12 +1,14 @@ +import { tzInfo } from "@app/core/utils/tz"; import type { DeviceValidation } from "@app/validation/config/device.js"; import { DynamicForm } from "@components/Form/DynamicForm.js"; import { useDevice } from "@core/stores/deviceStore.js"; import { Protobuf } from "@meshtastic/js"; export const Device = (): JSX.Element => { - const { config, setWorkingConfig } = useDevice(); + const { config, setWorkingConfig, setTzDropdown } = useDevice(); const onSubmit = (data: DeviceValidation) => { + const tzInt = Number.parseInt(data.tzdef); setWorkingConfig( new Protobuf.Config.Config({ payloadVariant: { @@ -20,7 +22,10 @@ export const Device = (): JSX.Element => { return ( onSubmit={onSubmit} - defaultValues={config.device} + defaultValues={{ + //tzdef: toTzDropdown(config.device?.tzdef ?? ""), + ...config.device, + }} fieldGroups={[ { label: "Device Settings", @@ -36,6 +41,15 @@ export const Device = (): JSX.Element => { formatEnumName: true, }, }, + { + type: "stringSelect", + name: "tzdef", + label: "Timezone", + description: "What timezone is the device in", + properties: { + enumValue: tzInfo, + }, + }, { type: "toggle", name: "serialEnabled", diff --git a/src/core/utils/tz.ts b/src/core/utils/tz.ts new file mode 100644 index 00000000..e3a70870 --- /dev/null +++ b/src/core/utils/tz.ts @@ -0,0 +1,29 @@ +export enum tzInfo { + "UTC +12" = "<-12>12", + "UTC +11" = "<-11>11", + "UTC +10" = "<-10>10", + "UTC +9" = "<-09>9", + "UTC +8" = "<-08>8", + "UTC +7" = "<-07>7", + "UTC +6" = "<-06>6", + "UTC +5" = "<-05>5", + "UTC +4" = "<-04>4", + "UTC +3" = "<-03>3", + "UTC +2" = "<-02>2", + "UTC +1" = "<-01>1", + "UTC" = "GMT0", + "UTC -1" = "<+01>-1", + "UTC -2" = "<+02>-2", + "UTC -3" = "<+03>-3", + "UTC -4" = "<+04>-4", + "UTC -5" = "<+05>-5", + "UTC -6" = "<+06>-6", + "UTC -7" = "<+07>-7", + "UTC -8" = "<+08>-8", + "UTC -9" = "<+09>-9", + "UTC -10" = "<+10>-10", + "UTC -11" = "<+11>-11", + "UTC -12" = "<+12>-12", + "UTC -13" = "<+13>-13", + "UTC -14" = "<+14>-14", +} \ No newline at end of file diff --git a/src/validation/config/device.ts b/src/validation/config/device.ts index 728625bf..8b25c1dc 100644 --- a/src/validation/config/device.ts +++ b/src/validation/config/device.ts @@ -1,6 +1,6 @@ import type { Message } from "@bufbuild/protobuf"; import { Protobuf } from "@meshtastic/js"; -import { IsBoolean, IsEnum, IsInt } from "class-validator"; +import { IsBoolean, IsEnum, IsInt, IsString } from "class-validator"; export class DeviceValidation implements Omit @@ -8,6 +8,9 @@ export class DeviceValidation @IsEnum(Protobuf.Config.Config_DeviceConfig_Role) role: Protobuf.Config.Config_DeviceConfig_Role; + @IsString() + tzdef: string; + @IsBoolean() serialEnabled: boolean; @@ -34,4 +37,7 @@ export class DeviceValidation @IsBoolean() disableTripleClick: boolean; + + @IsBoolean() + ledHeartbeatDisabled: boolean; } diff --git a/src/validation/config/display.ts b/src/validation/config/display.ts index 68d0a306..f020312e 100644 --- a/src/validation/config/display.ts +++ b/src/validation/config/display.ts @@ -1,6 +1,6 @@ import type { Message } from "@bufbuild/protobuf"; import { Protobuf } from "@meshtastic/js"; -import { IsBoolean, IsEnum, IsInt } from "class-validator"; +import { IsBoolean, IsEnum, IsInt, IsNumber } from "class-validator"; export class DisplayValidation implements Omit @@ -34,4 +34,7 @@ export class DisplayValidation @IsBoolean() wakeOnTapOrMotion: boolean; + + @IsInt() + compassOrientation: number; } diff --git a/src/validation/moduleConfig/paxcounter.ts b/src/validation/moduleConfig/paxcounter.ts index 67317c96..8872856f 100644 --- a/src/validation/moduleConfig/paxcounter.ts +++ b/src/validation/moduleConfig/paxcounter.ts @@ -11,4 +11,10 @@ export class PaxcounterValidation @IsInt() paxcounterUpdateInterval: number; + + @IsInt() + wifiThreshold: number; + + @IsInt() + bleThreshold: number; }