WIP config update

This commit is contained in:
Sacha Weatherstone
2023-01-23 13:14:02 +10:00
parent 703eacc269
commit e3f2a4585f
27 changed files with 116 additions and 270 deletions
@@ -7,7 +7,7 @@ import { toast } from "react-hot-toast";
import { Input } from "@app/components/form/Input.js";
import { Select } from "@app/components/form/Select.js";
import { Toggle } from "@app/components/form/Toggle.js";
import { DisplayValidation } from "@app/validation/config/display.js";
import type { DisplayValidation } from "@app/validation/config/display.js";
import { Form } from "@components/form/Form";
import { useDevice } from "@core/providers/useDevice.js";
import { renderOptions } from "@core/utils/selectEnumOptions.js";
@@ -22,54 +22,48 @@ export const Display = (): JSX.Element => {
formState: { errors, isDirty },
reset,
control
} = useForm<Protobuf.Config_DisplayConfig>({
defaultValues: config.display,
resolver: classValidatorResolver(DisplayValidation)
} = useForm<DisplayValidation>({
defaultValues: config.display
// resolver: classValidatorResolver(DisplayValidation)
});
useEffect(() => {
reset(config.display);
}, [reset, config.display]);
// useEffect(() => {
// reset(config.display);
// }, [reset, config.display]);
const onSubmit = handleSubmit((data) => {
if (connection) {
void toast.promise(
connection
.setConfig(
new Protobuf.Config({
payloadVariant: {
case: "display",
value: data
}
})
)
.then(() =>
setConfig(
new Protobuf.Config({
payloadVariant: {
case: "display",
value: data
}
})
)
),
{
loading: "Saving...",
success: "Saved Display Config, Restarting Node",
error: "No response received"
}
);
}
// if (connection) {
// void toast.promise(
// connection
// .setConfig(
// new Protobuf.Config({
// payloadVariant: {
// case: "display",
// value: data
// }
// })
// )
// .then(() =>
// setConfig(
// new Protobuf.Config({
// payloadVariant: {
// case: "display",
// value: data
// }
// })
// )
// ),
// {
// loading: "Saving...",
// success: "Saved Display Config, Restarting Node",
// error: "No response received"
// }
// );
// }
});
return (
<Form
title="Display Config"
breadcrumbs={["Config", "Display"]}
reset={() => reset(config.display)}
dirty={isDirty}
onSubmit={onSubmit}
>
<Form onSubmit={onSubmit}>
<Input
label="Screen Timeout"
description="Turn off the display after this long"