Browse Source

add ability to enable/disable HTTPS connections

pull/250/head
Hunter Thornsberry 2 years ago
parent
commit
c4565d97b0
  1. 20
      src/components/PageComponents/Connect/HTTP.tsx

20
src/components/PageComponents/Connect/HTTP.tsx

@ -24,17 +24,13 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
) )
? "meshtastic.local" ? "meshtastic.local"
: window.location.hostname, : window.location.hostname,
tls: location.protocol === "https:", tls: false,
}, },
}); });
const tlsEnabled = useWatch({
control,
name: "tls",
defaultValue: location.protocol === "https:",
});
const [connectionInProgress, setConnectionInProgress] = useState(false); const [connectionInProgress, setConnectionInProgress] = useState(false);
const [https, setHTTPS] = useState(false);
const onSubmit = handleSubmit(async (data) => { const onSubmit = handleSubmit(async (data) => {
setConnectionInProgress(true); setConnectionInProgress(true);
@ -46,7 +42,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
await connection.connect({ await connection.connect({
address: data.ip, address: data.ip,
fetchInterval: 2000, fetchInterval: 2000,
tls: data.tls, tls: https,
}); });
setSelectedDevice(id); setSelectedDevice(id);
@ -60,8 +56,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
<div className="flex h-48 flex-col gap-2"> <div className="flex h-48 flex-col gap-2">
<Label>IP Address/Hostname</Label> <Label>IP Address/Hostname</Label>
<Input <Input
// label="IP Address/Hostname" prefix={https ? "https://" : "http://"}
prefix={tlsEnabled ? "https://" : "http://"}
placeholder="000.000.000.000 / meshtastic.local" placeholder="000.000.000.000 / meshtastic.local"
disabled={connectionInProgress} disabled={connectionInProgress}
{...register("ip")} {...register("ip")}
@ -71,12 +66,9 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
control={control} control={control}
render={({ field: { value, ...rest } }) => ( render={({ field: { value, ...rest } }) => (
<> <>
<Label>Use TLS</Label> <Label>Use HTTPS</Label>
<Switch <Switch
// label="Use TLS" onCheckedChange={(checked) => {checked ? setHTTPS(true) : setHTTPS(false) }}
// description="Description"
disabled={location.protocol === "https:" || connectionInProgress}
checked={value}
{...rest} {...rest}
/> />
</> </>

Loading…
Cancel
Save