Browse Source

Review fixes

pull/807/head
philon- 11 months ago
parent
commit
a681fb53a5
  1. 34
      packages/web/src/components/Dialog/ImportDialog.tsx
  2. 2
      packages/web/src/components/Form/FormPasswordGenerator.tsx
  3. 11
      packages/web/src/components/PageComponents/ChannelConfig/Channel.tsx
  4. 42
      packages/web/src/pages/Config/index.tsx

34
packages/web/src/components/Dialog/ImportDialog.tsx

@ -100,35 +100,33 @@ export const ImportDialog = ({ open, onOpenChange }: ImportDialogProps) => {
}); });
if ( if (
deepCompareConfig( !deepCompareConfig(
channels.get(importIndex[index] ?? 0), channels.get(importIndex[index] ?? 0),
payload, payload,
true, true,
) )
) { ) {
return; setWorkingChannelConfig(payload);
} }
setWorkingChannelConfig(payload);
}, },
); );
if (channelSet?.loraConfig && updateConfig) { if (channelSet?.loraConfig && updateConfig) {
const payload = create(Protobuf.Config.ConfigSchema, { const payload = {
payloadVariant: { ...config.lora,
case: "lora", ...channelSet.loraConfig,
value: { };
...config.lora,
...channelSet.loraConfig, if (!deepCompareConfig(config.lora, payload, true)) {
}, setWorkingConfig(
}, create(Protobuf.Config.ConfigSchema, {
}); payloadVariant: {
case: "lora",
if (deepCompareConfig(config.lora, payload, true)) { value: payload,
return; },
}),
);
} }
setWorkingConfig(payload);
} }
// Reset state after import // Reset state after import
setImportDialogInput(""); setImportDialogInput("");

2
packages/web/src/components/Form/FormPasswordGenerator.tsx

@ -46,8 +46,8 @@ export function PasswordGenerator<T extends FieldValues>({
bits={field.bits} bits={field.bits}
inputChange={(e) => { inputChange={(e) => {
const value = e.target.value; const value = e.target.value;
controllerField.onChange(value); // ensure RHF receives just the value
field.inputChange?.(e); // call any external handler field.inputChange?.(e); // call any external handler
controllerField.onChange(value); // ensure RHF receives just the value
}} }}
selectChange={field.selectChange ?? (() => {})} selectChange={field.selectChange ?? (() => {})}
variant={invalid ? "invalid" : isDirty ? "dirty" : "default"} variant={invalid ? "invalid" : isDirty ? "dirty" : "default"}

11
packages/web/src/components/PageComponents/ChannelConfig/Channel.tsx

@ -14,7 +14,7 @@ import { deepCompareConfig } from "@core/utils/deepCompareConfig.ts";
import { Protobuf } from "@meshtastic/core"; import { Protobuf } from "@meshtastic/core";
import { fromByteArray, toByteArray } from "base64-js"; import { fromByteArray, toByteArray } from "base64-js";
import cryptoRandomString from "crypto-random-string"; import cryptoRandomString from "crypto-random-string";
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useRef, useState } from "react";
import { type DefaultValues, useForm } from "react-hook-form"; import { type DefaultValues, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -96,9 +96,14 @@ export const Channel = ({ onFormInit, channel }: SettingsPanelProps) => {
// Since byteCount is an independent state, we need to use the effective value // Since byteCount is an independent state, we need to use the effective value
// from the channel config to ensure the form updates when the setting changes // from the channel config to ensure the form updates when the setting changes
const effectiveByteCount = effectiveConfig.settings?.psk.length ?? 16; const effectiveByteCount = effectiveConfig.settings?.psk.length ?? 16;
const lastEffectiveRef = useRef<number>(effectiveByteCount);
useEffect(() => { useEffect(() => {
setBytes(effectiveByteCount); if (effectiveByteCount !== lastEffectiveRef.current) {
trigger("settings.psk"); lastEffectiveRef.current = effectiveByteCount;
setBytes(effectiveByteCount);
trigger("settings.psk");
}
}, [effectiveByteCount, trigger]); }, [effectiveByteCount, trigger]);
const onSubmit = (data: ChannelValidation) => { const onSubmit = (data: ChannelValidation) => {

42
packages/web/src/pages/Config/index.tsx

@ -95,29 +95,31 @@ const ConfigPage = () => {
), ),
); );
await connection?.commitEditSettings().then(() => { if (workingConfig.length > 0 || workingModuleConfig.length > 0) {
if (formMethods) { await connection?.commitEditSettings();
formMethods.reset(undefined, { }
keepDirty: false,
keepErrors: false,
keepTouched: false,
keepValues: false,
});
// Force RHF to re-validate and emit state workingChannelConfig.forEach((newChannel) => addChannel(newChannel));
formMethods.trigger(); workingConfig.forEach((newConfig) => setConfig(newConfig));
} workingModuleConfig.forEach((newModuleConfig) =>
setModuleConfig(newModuleConfig),
);
workingChannelConfig.map((newChannel) => addChannel(newChannel)); removeWorkingChannelConfig();
workingConfig.map((newConfig) => setConfig(newConfig)); removeWorkingConfig();
workingModuleConfig.map((newModuleConfig) => removeWorkingModuleConfig();
setModuleConfig(newModuleConfig),
);
removeWorkingChannelConfig(); if (formMethods) {
removeWorkingConfig(); formMethods.reset(formMethods.getValues(), {
removeWorkingModuleConfig(); keepDirty: false,
}); keepErrors: false,
keepTouched: false,
keepValues: false,
});
// Force RHF to re-validate and emit state
formMethods.trigger();
}
} catch (_error) { } catch (_error) {
toast({ toast({
title: t("toast.configSaveError.title"), title: t("toast.configSaveError.title"),

Loading…
Cancel
Save