Skip to content

Commit

Permalink
Removed WebUI check
Browse files Browse the repository at this point in the history
  • Loading branch information
breiler committed May 5, 2024
1 parent 768d477 commit 1aea8d1
Showing 1 changed file with 8 additions and 48 deletions.
56 changes: 8 additions & 48 deletions src/components/cards/wificard/WiFiCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React from "react";
import Card from "../card";
import Button from "../../button";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand All @@ -12,28 +12,15 @@ type WiFiCardProps = {
onClick: () => void;
};

async function fetchWithTimeout(
resource,
options: RequestInit = {},
timeout = 8000
) {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);

const response = await fetch(resource, {
...options,
signal: controller.signal
});
clearTimeout(id);

return response;
}

const WebUiLink = ({ stats }: { stats: Stats }) => {
return (
<>
<br />
<a href={"http://" + stats.ip + "/"} target="_blank" rel="noreferrer">
<a
href={"http://" + stats.ip + "/"}
target="_blank"
rel="noreferrer"
>
http://{stats.ip}/
</a>
</>
Expand All @@ -45,33 +32,6 @@ export const WiFiCard = ({
disabled = false,
stats
}: WiFiCardProps) => {
const [accessWebUI, setAccessWebUI] = useState(false);

useEffect(() => {
if (!stats) {
return;
}

const timer = setInterval(() => {
const url = "http://" + stats.ip + "/";
fetchWithTimeout(
url,
{
mode: "no-cors"
},
2000
)
.then(() => setAccessWebUI(true))
.catch(() => setAccessWebUI(false));
}, 5000);

return () => {
if (!timer) return;

clearInterval(timer);
};
}, [stats]);

return (
<Card
className="select-card"
Expand All @@ -98,7 +58,7 @@ export const WiFiCard = ({
<span className="text-nowrap">
{stats?.apSSID} {stats.signal}
</span>
{accessWebUI && <WebUiLink stats={stats} />}
<WebUiLink stats={stats} />
</>
)}
</>
Expand All @@ -109,7 +69,7 @@ export const WiFiCard = ({
<span className="text-nowrap">
{stats?.connectedTo} ({stats?.signal})
</span>
{accessWebUI && <WebUiLink stats={stats} />}
<WebUiLink stats={stats} />
</>
)}
</>
Expand Down

0 comments on commit 1aea8d1

Please sign in to comment.