Browse Source

Merge pull request #202 from PixnBits/fix/disable-connection-while-connecting

fix(Connect): disable connecting multiple times
pull/253/head v1.0.0
Hunter Thornsberry 2 years ago
committed by GitHub
parent
commit
6d6149e1da
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      src/components/PageComponents/Connect/HTTP.tsx

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

@ -1,3 +1,4 @@
import React, { useState } from "react";
import { TabElementProps } from "@app/components/Dialog/NewDeviceDialog"; import { TabElementProps } from "@app/components/Dialog/NewDeviceDialog";
import { Button } from "@components/UI/Button.js"; import { Button } from "@components/UI/Button.js";
import { Input } from "@components/UI/Input.js"; import { Input } from "@components/UI/Input.js";
@ -33,10 +34,13 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
defaultValue: location.protocol === "https:", defaultValue: location.protocol === "https:",
}); });
const [connectionInProgress, setConnectionInProgress] = useState(false);
const onSubmit = handleSubmit(async (data) => { const onSubmit = handleSubmit(async (data) => {
setConnectionInProgress(true);
const id = randId(); const id = randId();
const device = addDevice(id); const device = addDevice(id);
setSelectedDevice(id);
const connection = new HttpConnection(id); const connection = new HttpConnection(id);
// TODO: Promise never resolves // TODO: Promise never resolves
await connection.connect({ await connection.connect({
@ -44,9 +48,10 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
fetchInterval: 2000, fetchInterval: 2000,
tls: data.tls, tls: data.tls,
}); });
setSelectedDevice(id);
device.addConnection(connection); device.addConnection(connection);
subscribeAll(device, connection); subscribeAll(device, connection);
closeDialog(); closeDialog();
}); });
@ -58,6 +63,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
// label="IP Address/Hostname" // label="IP Address/Hostname"
prefix={tlsEnabled ? "https://" : "http://"} prefix={tlsEnabled ? "https://" : "http://"}
placeholder="000.000.000.000 / meshtastic.local" placeholder="000.000.000.000 / meshtastic.local"
disabled={connectionInProgress}
{...register("ip")} {...register("ip")}
/> />
<Controller <Controller
@ -69,7 +75,7 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
<Switch <Switch
// label="Use TLS" // label="Use TLS"
// description="Description" // description="Description"
disabled={location.protocol === "https:"} disabled={location.protocol === "https:" || connectionInProgress}
checked={value} checked={value}
{...rest} {...rest}
/> />
@ -77,8 +83,8 @@ export const HTTP = ({ closeDialog }: TabElementProps): JSX.Element => {
)} )}
/> />
</div> </div>
<Button type="submit"> <Button type="submit" disabled={connectionInProgress}>
<span>Connect</span> <span>{connectionInProgress ? 'Connecting...' : 'Connect' }</span>
</Button> </Button>
</form> </form>
); );

Loading…
Cancel
Save