Skip to content

Commit a10230b

Browse files
authored
Merge pull request meshtastic#442 from justinforlenza/tls-switch-fix
fix: tls switch for http connections
2 parents c9416a3 + ec10b63 commit a10230b

File tree

1 file changed

+6
-8
lines changed
  • src/components/PageComponents/Connect

1 file changed

+6
-8
lines changed

src/components/PageComponents/Connect/HTTP.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { subscribeAll } from "@core/subscriptions.ts";
99
import { randId } from "@core/utils/randId.ts";
1010
import { HttpConnection } from "@meshtastic/js";
1111
import { useState } from "react";
12-
import { Controller, useForm, useWatch } from "react-hook-form";
12+
import { Controller, useForm } from "react-hook-form";
1313

1414
export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
1515
const { addDevice } = useDeviceStore();
1616
const { setSelectedDevice } = useAppStore();
17-
const { register, handleSubmit, control } = useForm<{
17+
const { register, handleSubmit, control, watch } = useForm<{
1818
ip: string;
1919
tls: boolean;
2020
}>({
@@ -29,7 +29,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
2929
});
3030

3131
const [connectionInProgress, setConnectionInProgress] = useState(false);
32-
const [https, setHTTPS] = useState(false);
32+
const https = watch("tls");
3333

3434
const onSubmit = handleSubmit(async (data) => {
3535
setConnectionInProgress(true);
@@ -41,7 +41,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
4141
await connection.connect({
4242
address: data.ip,
4343
fetchInterval: 2000,
44-
tls: https,
44+
tls: data.tls,
4545
});
4646

4747
setSelectedDevice(id);
@@ -64,13 +64,11 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
6464
<Controller
6565
name="tls"
6666
control={control}
67-
render={({ field: { value, ...rest } }) => (
67+
render={({ field: { value, onChange, ...rest } }) => (
6868
<>
6969
<Label>Use HTTPS</Label>
7070
<Switch
71-
onCheckedChange={(checked) => {
72-
checked ? setHTTPS(true) : setHTTPS(false);
73-
}}
71+
onCheckedChange={onChange}
7472
// label="Use TLS"
7573
// description="Description"
7674
disabled={

0 commit comments

Comments
 (0)