Skip to content

Commit

Permalink
Merge pull request #202 from PixnBits/fix/disable-connection-while-co…
Browse files Browse the repository at this point in the history
…nnecting

fix(Connect): disable connecting multiple times
  • Loading branch information
Hunter275 committed Jun 18, 2024
2 parents c3116c0 + 54d5559 commit 6d6149e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/PageComponents/Connect/HTTP.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { useState } from "react";
import { TabElementProps } from "@app/components/Dialog/NewDeviceDialog";
import { Button } from "@components/UI/Button.js";
import { Input } from "@components/UI/Input.js";
Expand Down Expand Up @@ -33,20 +34,24 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
defaultValue: location.protocol === "https:",
});

const [connectionInProgress, setConnectionInProgress] = useState(false);

const onSubmit = handleSubmit(async (data) => {
setConnectionInProgress(true);

const id = randId();
const device = addDevice(id);
setSelectedDevice(id);
const connection = new HttpConnection(id);
// TODO: Promise never resolves
await connection.connect({
address: data.ip,
fetchInterval: 2000,
tls: data.tls,
});

setSelectedDevice(id);
device.addConnection(connection);
subscribeAll(device, connection);

closeDialog();
});

Expand All @@ -58,6 +63,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
// label="IP Address/Hostname"
prefix={tlsEnabled ? "https://" : "http://"}
placeholder="000.000.000.000 / meshtastic.local"
disabled={connectionInProgress}
{...register("ip")}
/>
<Controller
Expand All @@ -69,16 +75,16 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
<Switch
// label="Use TLS"
// description="Description"
disabled={location.protocol === "https:"}
disabled={location.protocol === "https:" || connectionInProgress}
checked={value}
{...rest}
/>
</>
)}
/>
</div>
<Button type="submit">
<span>Connect</span>
<Button type="submit" disabled={connectionInProgress}>
<span>{connectionInProgress ? 'Connecting...' : 'Connect' }</span>
</Button>
</form>
);
Expand Down

0 comments on commit 6d6149e

Please sign in to comment.