Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to enable/disable HTTPS connections #250

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/components/PageComponents/Connect/HTTP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
)
? "meshtastic.local"
: 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 [https, setHTTPS] = useState(false);

const onSubmit = handleSubmit(async (data) => {
setConnectionInProgress(true);
Expand All @@ -46,7 +42,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
await connection.connect({
address: data.ip,
fetchInterval: 2000,
tls: data.tls,
tls: https,
});

setSelectedDevice(id);
Expand All @@ -60,8 +56,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
<div className="flex h-48 flex-col gap-2">
<Label>IP Address/Hostname</Label>
<Input
// label="IP Address/Hostname"
prefix={tlsEnabled ? "https://" : "http://"}
prefix={https ? "https://" : "http://"}
placeholder="000.000.000.000 / meshtastic.local"
disabled={connectionInProgress}
{...register("ip")}
Expand All @@ -71,12 +66,10 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
control={control}
render={({ field: { value, ...rest } }) => (
<>
<Label>Use TLS</Label>
<Label>Use HTTPS</Label>
<Switch
// label="Use TLS"
// description="Description"
disabled={location.protocol === "https:" || connectionInProgress}
checked={value}
onCheckedChange={(checked) => {checked ? setHTTPS(true) : setHTTPS(false) }}
disabled={connectionInProgress}
{...rest}
/>
</>
Expand Down