Config saving behaviour change

This commit is contained in:
Sacha Weatherstone
2022-12-31 17:14:11 +11:00
parent f7fe27d621
commit ec25ec60ee
18 changed files with 227 additions and 103 deletions

View File

@@ -24,7 +24,7 @@ export interface SettingsPanelProps {
}
export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
const { connection } = useDevice();
const { connection, addChannel } = useDevice();
const [keySize, setKeySize] = useState<128 | 256>(256);
const [pskHidden, setPskHidden] = useState(true);
@@ -81,7 +81,20 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
addChannel({
config: {
index: channel.index,
role: channel.role,
settings: {
...data,
psk: toByteArray(data.psk ?? "")
}
},
lastInterraction: new Date(),
messages: []
})
),
{
loading: "Saving...",
success: "Saved Channel",

View File

@@ -15,7 +15,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const Bluetooth = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
@@ -44,7 +44,14 @@ export const Bluetooth = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "bluetooth",
bluetooth: data
}
})
),
{
loading: "Saving...",
success: "Saved Bluetooth Config, Restarting Node",

View File

@@ -15,7 +15,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const Device = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
handleSubmit,
@@ -43,7 +43,14 @@ export const Device = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "device",
device: data
}
})
),
{
loading: "Saving...",
success: "Saved Device Config, Restarting Node",

View File

@@ -15,7 +15,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const Display = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
handleSubmit,
@@ -43,7 +43,14 @@ export const Display = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "display",
display: data
}
})
),
{
loading: "Saving...",
success: "Saved Display Config, Restarting Node",

View File

@@ -16,7 +16,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const LoRa = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
@@ -51,7 +51,14 @@ export const LoRa = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "lora",
lora: data
}
})
),
{
loading: "Saving...",
success: "Saved LoRa Config, Restarting Node",

View File

@@ -17,7 +17,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const Network = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
handleSubmit,
@@ -65,7 +65,14 @@ export const Network = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "network",
network: data
}
})
),
{
loading: "Saving...",
success: "Saved Network Config, Restarting Node",

View File

@@ -15,7 +15,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const Position = (): JSX.Element => {
const { config, connection, nodes, hardware } = useDevice();
const { config, connection, nodes, hardware, setConfig } = useDevice();
const myNode = nodes.find((n) => n.data.num === hardware.myNodeNum);
@@ -86,7 +86,14 @@ export const Position = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "position",
position: data
}
})
),
{
loading: "Saving...",
success: "Saved Position Config, Restarting Node",

View File

@@ -13,7 +13,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const Power = (): JSX.Element => {
const { config, connection } = useDevice();
const { config, connection, setConfig } = useDevice();
const {
register,
handleSubmit,
@@ -41,7 +41,14 @@ export const Power = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setConfig({
payloadVariant: {
oneofKind: "power",
power: data
}
})
),
{
loading: "Saving...",
success: "Saved Power Config, Restarting Node",

View File

@@ -15,7 +15,7 @@ import { classValidatorResolver } from "@hookform/resolvers/class-validator";
import { Protobuf } from "@meshtastic/meshtasticjs";
export const CannedMessage = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -49,7 +49,14 @@ export const CannedMessage = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "cannedMessage",
cannedMessage: data
}
})
),
{
loading: "Saving...",
success: "Saved Canned Message Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const ExternalNotification = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -39,7 +39,14 @@ export const ExternalNotification = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "externalNotification",
externalNotification: data
}
})
),
{
loading: "Saving...",
success: "Saved External Notification Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const MQTT = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -46,7 +46,14 @@ export const MQTT = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "mqtt",
mqtt: data
}
})
),
{
loading: "Saving...",
success: "Saved MQTT Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const RangeTest = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -40,7 +40,14 @@ export const RangeTest = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "rangeTest",
rangeTest: data
}
})
),
{
loading: "Saving...",
success: "Saved Range Test Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const Serial = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -40,7 +40,14 @@ export const Serial = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "serial",
serial: data
}
})
),
{
loading: "Saving...",
success: "Saved Serial Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const StoreForward = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -40,7 +40,14 @@ export const StoreForward = (): JSX.Element => {
}
}
})
.then(() => reset({ ...data })),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "storeForward",
storeForward: data
}
})
),
{
loading: "Saving...",
success: "Saved Store & Forward Config, Restarting Node",

View File

@@ -12,7 +12,7 @@ import { useDevice } from "@core/providers/useDevice.js";
import { classValidatorResolver } from "@hookform/resolvers/class-validator";
export const Telemetry = (): JSX.Element => {
const { moduleConfig, connection } = useDevice();
const { moduleConfig, connection, setModuleConfig } = useDevice();
const {
register,
handleSubmit,
@@ -40,10 +40,14 @@ export const Telemetry = (): JSX.Element => {
}
}
})
.then(async () => {
reset({ ...data });
await Promise.resolve();
}),
.then(() =>
setModuleConfig({
payloadVariant: {
oneofKind: "telemetry",
telemetry: data
}
})
),
{
loading: "Saving...",
success: "Saved Telemetry Config, Restarting Node",