1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00
This commit is contained in:
Cooper Ransom 2024-03-08 22:32:23 -05:00
commit 05e859391a

View file

@ -1,5 +1,5 @@
import classNames from "classnames";
import { useEffect, useMemo, useState } from "react";
import { useMemo, useState } from "react";
import { useAsyncFn } from "react-use";
import { singularProxiedFetch } from "@/backend/helpers/fetch";
@ -54,7 +54,6 @@ export function WorkerTestPart() {
const [buttonClicked, setButtonClicked] = useState(false);
const [buttonDisabled, setButtonDisabled] = useState(false);
const [allWorkersPassed, setAllWorkersPassed] = useState(false);
const [testState, runTests] = useAsyncFn(async () => {
setButtonDisabled(true);
@ -90,7 +89,6 @@ export function WorkerTestPart() {
status: "error",
error: err as Error,
});
setAllWorkersPassed(false); // Set allWorkersPassed to false if a worker fails
}
});
@ -98,12 +96,6 @@ export function WorkerTestPart() {
setTimeout(() => setButtonDisabled(false), 5000);
}, [workerList, setWorkerState]);
useEffect(() => {
setAllWorkersPassed(
workerState.every((worker) => worker.status === "success"),
);
}, [workerState]);
return (
<>
<Heading2 className="!mb-0 mt-12">Worker tests</Heading2>
@ -128,18 +120,28 @@ export function WorkerTestPart() {
})}
<Divider />
<div className="flex justify-end">
{allWorkersPassed && buttonClicked ? (
<div>
<p>All workers have passed the test! ٩(ˊˋ*)و </p>
</div>
{buttonClicked ? (
workerState.every((worker) => worker.status === "success") ? (
<p>
All workers have passed the test!{" "}
<span className="font-bold">٩(ˊˋ*)و</span>
</p>
) : (
<p>
Some workers have failed the test...{" "}
<span className="font-bold">( )</span>
</p>
)
) : (
<Button
theme="purple"
loading={testState.loading}
onClick={(event) => {
onClick={async (event) => {
event.preventDefault();
setButtonClicked(true);
if (!buttonDisabled) runTests();
setButtonDisabled(true); // Disable button to prevent multiple clicks
await runTests(); // Wait for tests
setButtonClicked(true); // buttonClicked equals true after tests are done!
setTimeout(() => setButtonDisabled(false), 5000); // Turn the button back on
}}
disabled={buttonDisabled}
>