Browse Source

Review fixes

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

28
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: {
case: "lora",
value: {
...config.lora, ...config.lora,
...channelSet.loraConfig, ...channelSet.loraConfig,
}, };
},
});
if (deepCompareConfig(config.lora, payload, true)) { if (!deepCompareConfig(config.lora, payload, true)) {
return; setWorkingConfig(
create(Protobuf.Config.ConfigSchema, {
payloadVariant: {
case: "lora",
value: payload,
},
}),
);
} }
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"}

7
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(() => {
if (effectiveByteCount !== lastEffectiveRef.current) {
lastEffectiveRef.current = effectiveByteCount;
setBytes(effectiveByteCount); setBytes(effectiveByteCount);
trigger("settings.psk"); trigger("settings.psk");
}
}, [effectiveByteCount, trigger]); }, [effectiveByteCount, trigger]);
const onSubmit = (data: ChannelValidation) => { const onSubmit = (data: ChannelValidation) => {

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

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

Loading…
Cancel
Save