1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-30 16:17:41 +01:00

Make admin page even better

This commit is contained in:
Cooper Ransom 2024-03-08 20:04:47 -05:00
parent 8c29042cb8
commit 42b68e972e

View file

@ -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}
> >