Files
AutoGPT/classic/benchmark/frontend/src/components/index/RunButton.tsx
Swifty ef7cfbb860 refactor: AutoGPT Platform Stealth Launch Repo Re-Org (#8113)
Restructuring the Repo to make it clear the difference between classic autogpt and the autogpt platform:
* Move the "classic" projects `autogpt`, `forge`, `frontend`, and `benchmark` into a `classic` folder
  * Also rename `autogpt` to `original_autogpt` for absolute clarity
* Rename `rnd/` to `autogpt_platform/`
  * `rnd/autogpt_builder` -> `autogpt_platform/frontend`
  * `rnd/autogpt_server` -> `autogpt_platform/backend`
* Adjust any paths accordingly
2024-09-20 16:50:43 +02:00

81 lines
1.7 KiB
TypeScript

import React, { useState, useEffect } from "react";
import tw from "tailwind-styled-components";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faCircleNotch } from "@fortawesome/free-solid-svg-icons";
interface RunButtonProps {
testRun: () => Promise<void>;
isLoading: boolean;
cutoff?: string;
isMock: boolean;
}
const RunButton: React.FC<RunButtonProps> = ({
testRun,
isLoading,
cutoff,
isMock,
}) => {
const intCutoff = cutoff ? parseInt(cutoff) : null;
const [timeElapsed, setTimeElapsed] = useState<number>(0);
useEffect(() => {
let interval: NodeJS.Timeout | null = null;
if (isLoading) {
interval = setInterval(() => {
setTimeElapsed((prevTime) => prevTime + 1);
}, 1000);
} else {
if (interval !== null) {
clearInterval(interval);
}
setTimeElapsed(0); // Reset the timer when not loading
}
return () => {
if (interval !== null) {
clearInterval(interval);
}
};
}, [isLoading]);
const timeUntilCutoff = intCutoff ? intCutoff - timeElapsed : null;
return (
<>
<RunButtonWrapper onClick={testRun}>
{!isLoading ? (
"Run Task"
) : (
<FontAwesomeIcon size="lg" icon={faCircleNotch} spin />
)}
</RunButtonWrapper>
{cutoff && isLoading && (
<>
{isMock ? (
<p>Time elapsed: {timeElapsed} seconds</p>
) : (
<p>Time until cutoff: {timeUntilCutoff} seconds</p>
)}
</>
)}
</>
);
};
export default RunButton;
const RunButtonWrapper = tw.button`
border
mt-4
py-1
px-3
w-28
rounded
flex
items-center
justify-center
`;