Start moduleConfig & general import cleanup

This commit is contained in:
Sacha Weatherstone
2023-01-29 17:36:31 +10:00
parent 6340809ab3
commit e36032045f
84 changed files with 286 additions and 780 deletions
@@ -1,11 +1,7 @@
import type React from "react";
import { useEffect } from "react";
import { Controller, useForm, useWatch } from "react-hook-form";
import { toast } from "react-hot-toast";
import { Input } from "@app/components/form/Input.js";
import { Toggle } from "@app/components/form/Toggle.js";
import { Input } from "@components/form/Input.js";
import { Toggle } from "@components/form/Toggle.js";
import { MQTTValidation } from "@app/validation/moduleConfig/mqtt.js";
import { Form } from "@components/form/Form";
import { useDevice } from "@core/providers/useDevice.js";
@@ -13,7 +9,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const MQTT = (): JSX.Element => {
const { moduleConfig, connection, setModuleConfig } = useDevice();
const { moduleConfig, setWorkingModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -21,6 +17,7 @@ export const MQTT = (): JSX.Element => {
reset,
control
} = useForm<MQTTValidation>({
mode: "onChange",
defaultValues: moduleConfig.mqtt,
resolver: classValidatorResolver(MQTTValidation)
});
@@ -36,34 +33,14 @@ export const MQTT = (): JSX.Element => {
}, [reset, moduleConfig.mqtt]);
const onSubmit = handleSubmit((data) => {
if (connection) {
void toast.promise(
connection
.setModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "mqtt",
value: data
}
})
)
.then(() =>
setModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "mqtt",
value: data
}
})
)
),
{
loading: "Saving...",
success: "Saved MQTT Config, Restarting Node",
error: "No response received"
setWorkingModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "mqtt",
value: data
}
);
}
})
);
});
return (
@@ -82,7 +59,7 @@ export const MQTT = (): JSX.Element => {
/>
<Input
label="MQTT Server Address"
//description="Description"
description="Description"
disabled={!moduleEnabled}
{...register("address")}
/>