mirror of
https://github.com/meshtastic/web.git
synced 2026-01-04 13:40:20 -05:00
* Config reset work WIP * Config reset WIP * Fix tests, tsc, linting * Form reset adjustments * Add ManagedModeDialog * Remove debug logging * Add Suspense * Review fixes --------- Co-authored-by: philon- <philon-@users.noreply.github.com>
109 lines
3.1 KiB
TypeScript
109 lines
3.1 KiB
TypeScript
import {
|
|
type AudioValidation,
|
|
AudioValidationSchema,
|
|
} from "@app/validation/moduleConfig/audio.ts";
|
|
import { create } from "@bufbuild/protobuf";
|
|
import {
|
|
DynamicForm,
|
|
type DynamicFormFormInit,
|
|
} from "@components/Form/DynamicForm.tsx";
|
|
import { useDevice } from "@core/stores/deviceStore.ts";
|
|
import { Protobuf } from "@meshtastic/core";
|
|
import { useTranslation } from "react-i18next";
|
|
import { deepCompareConfig } from "@core/utils/deepCompareConfig.ts";
|
|
|
|
interface AudioModuleConfigProps {
|
|
onFormInit: DynamicFormFormInit<AudioValidation>;
|
|
}
|
|
|
|
export const Audio = ({ onFormInit }: AudioModuleConfigProps) => {
|
|
const {
|
|
moduleConfig,
|
|
setWorkingModuleConfig,
|
|
getEffectiveModuleConfig,
|
|
removeWorkingModuleConfig,
|
|
} = useDevice();
|
|
const { t } = useTranslation("moduleConfig");
|
|
|
|
const onSubmit = (data: AudioValidation) => {
|
|
if (deepCompareConfig(moduleConfig.audio, data, true)) {
|
|
removeWorkingModuleConfig("audio");
|
|
return;
|
|
}
|
|
|
|
setWorkingModuleConfig(
|
|
create(Protobuf.ModuleConfig.ModuleConfigSchema, {
|
|
payloadVariant: {
|
|
case: "audio",
|
|
value: data,
|
|
},
|
|
}),
|
|
);
|
|
};
|
|
|
|
return (
|
|
<DynamicForm<AudioValidation>
|
|
onSubmit={onSubmit}
|
|
onFormInit={onFormInit}
|
|
validationSchema={AudioValidationSchema}
|
|
formId="ModuleConfig_AudioConfig"
|
|
defaultValues={moduleConfig.audio}
|
|
values={getEffectiveModuleConfig("audio")}
|
|
fieldGroups={[
|
|
{
|
|
label: t("audio.title"),
|
|
description: t("audio.description"),
|
|
fields: [
|
|
{
|
|
type: "toggle",
|
|
name: "codec2Enabled",
|
|
label: t("audio.codec2Enabled.label"),
|
|
description: t("audio.codec2Enabled.description"),
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "pttPin",
|
|
label: t("audio.pttPin.label"),
|
|
description: t("audio.pttPin.description"),
|
|
},
|
|
{
|
|
type: "select",
|
|
name: "bitrate",
|
|
label: t("audio.bitrate.label"),
|
|
description: t("audio.bitrate.description"),
|
|
properties: {
|
|
enumValue:
|
|
Protobuf.ModuleConfig.ModuleConfig_AudioConfig_Audio_Baud,
|
|
},
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "i2sWs",
|
|
label: t("audio.i2sWs.label"),
|
|
description: t("audio.i2sWs.description"),
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "i2sSd",
|
|
label: t("audio.i2sSd.label"),
|
|
description: t("audio.i2sSd.description"),
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "i2sDin",
|
|
label: t("audio.i2sDin.label"),
|
|
description: t("audio.i2sDin.description"),
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "i2sSck",
|
|
label: t("audio.i2sSck.label"),
|
|
description: t("audio.i2sSck.description"),
|
|
},
|
|
],
|
|
},
|
|
]}
|
|
/>
|
|
);
|
|
};
|