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

View File

@@ -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 { StoreForwardValidation } from "@app/validation/moduleConfig/storeForward.js";
import { Form } from "@components/form/Form";
import { useDevice } from "@core/providers/useDevice.js";
@@ -13,51 +9,27 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const StoreForward = (): JSX.Element => {
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
formState: { errors, isDirty },
reset,
control
} = useForm<StoreForwardValidation>({
defaultValues: moduleConfig.storeForward,
resolver: classValidatorResolver(StoreForwardValidation)
});
const { moduleConfig, setWorkingModuleConfig } = useDevice();
const { register, handleSubmit, reset, control } =
useForm<StoreForwardValidation>({
mode: "onChange",
defaultValues: moduleConfig.storeForward,
resolver: classValidatorResolver(StoreForwardValidation)
});
useEffect(() => {
reset(moduleConfig.storeForward);
}, [reset, moduleConfig.storeForward]);
const onSubmit = handleSubmit((data) => {
if (connection) {
void toast.promise(
connection
.setModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "storeForward",
value: data
}
})
)
.then(() =>
setModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "storeForward",
value: data
}
})
)
),
{
loading: "Saving...",
success: "Saved Store & Forward Config, Restarting Node",
error: "No response received"
setWorkingModuleConfig(
new Protobuf.ModuleConfig({
payloadVariant: {
case: "storeForward",
value: data
}
);
}
})
);
});
const moduleEnabled = useWatch({