mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-29 16:07:40 +01:00
Make admin page even better
This commit is contained in:
parent
8c29042cb8
commit
42b68e972e
1 changed files with 18 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useEffect, useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useAsyncFn } from "react-use";
|
import { useAsyncFn } from "react-use";
|
||||||
|
|
||||||
import { singularProxiedFetch } from "@/backend/helpers/fetch";
|
import { singularProxiedFetch } from "@/backend/helpers/fetch";
|
||||||
|
@ -54,7 +54,6 @@ export function WorkerTestPart() {
|
||||||
|
|
||||||
const [buttonClicked, setButtonClicked] = useState(false);
|
const [buttonClicked, setButtonClicked] = useState(false);
|
||||||
const [buttonDisabled, setButtonDisabled] = useState(false);
|
const [buttonDisabled, setButtonDisabled] = useState(false);
|
||||||
const [allWorkersPassed, setAllWorkersPassed] = useState(false);
|
|
||||||
|
|
||||||
const [testState, runTests] = useAsyncFn(async () => {
|
const [testState, runTests] = useAsyncFn(async () => {
|
||||||
setButtonDisabled(true);
|
setButtonDisabled(true);
|
||||||
|
@ -90,7 +89,6 @@ export function WorkerTestPart() {
|
||||||
status: "error",
|
status: "error",
|
||||||
error: err as 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);
|
setTimeout(() => setButtonDisabled(false), 5000);
|
||||||
}, [workerList, setWorkerState]);
|
}, [workerList, setWorkerState]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setAllWorkersPassed(
|
|
||||||
workerState.every((worker) => worker.status === "success"),
|
|
||||||
);
|
|
||||||
}, [workerState]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Heading2 className="!mb-0 mt-12">Worker tests</Heading2>
|
<Heading2 className="!mb-0 mt-12">Worker tests</Heading2>
|
||||||
|
@ -128,18 +120,28 @@ export function WorkerTestPart() {
|
||||||
})}
|
})}
|
||||||
<Divider />
|
<Divider />
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
{allWorkersPassed && buttonClicked ? (
|
{buttonClicked ? (
|
||||||
<div>
|
workerState.every((worker) => worker.status === "success") ? (
|
||||||
<p>All workers have passed the test! ٩(ˊᗜˋ*)و ♡</p>
|
<p>
|
||||||
</div>
|
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
|
<Button
|
||||||
theme="purple"
|
theme="purple"
|
||||||
loading={testState.loading}
|
loading={testState.loading}
|
||||||
onClick={(event) => {
|
onClick={async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setButtonClicked(true);
|
setButtonDisabled(true); // Disable button to prevent multiple clicks
|
||||||
if (!buttonDisabled) runTests();
|
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}
|
disabled={buttonDisabled}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in a new issue