2023-10-21 16:14:42 +02:00
|
|
|
import React, { useEffect } from "react";
|
2023-07-22 13:07:53 +02:00
|
|
|
import Spinner from "../../icons/Spinner";
|
2022-11-11 21:39:28 +01:00
|
|
|
|
2023-07-23 11:07:18 +02:00
|
|
|
function ProgressBar({
|
|
|
|
progress,
|
|
|
|
doubleUpscaylCounter,
|
|
|
|
stopHandler,
|
|
|
|
batchMode,
|
2023-10-21 15:43:03 +02:00
|
|
|
}: {
|
|
|
|
progress: string;
|
|
|
|
doubleUpscaylCounter: number;
|
|
|
|
stopHandler: () => void;
|
|
|
|
batchMode: boolean;
|
2023-07-23 11:07:18 +02:00
|
|
|
}) {
|
2023-09-09 14:18:00 +02:00
|
|
|
const [batchProgress, setBatchProgress] = React.useState(0);
|
|
|
|
|
2023-10-21 16:14:42 +02:00
|
|
|
useEffect(() => {
|
2023-10-21 15:43:03 +02:00
|
|
|
const progressString = progress.trim().replace(/\n/g, "");
|
|
|
|
// Remove trailing and leading spaces
|
2023-10-21 16:14:42 +02:00
|
|
|
if (progressString.includes("Successful")) {
|
2023-09-09 14:18:00 +02:00
|
|
|
setBatchProgress((prev) => prev + 1);
|
|
|
|
}
|
|
|
|
}, [progress]);
|
|
|
|
|
2022-11-11 21:39:28 +01:00
|
|
|
return (
|
2024-02-15 09:17:11 +01:00
|
|
|
<div className="absolute z-50 flex h-full w-full flex-col items-center justify-center bg-base-300/50 backdrop-blur-lg">
|
2024-04-21 19:14:39 +02:00
|
|
|
<div className="flex flex-col items-center rounded-btn bg-base-100/50 p-4 backdrop-blur-lg">
|
2024-01-15 11:25:28 +01:00
|
|
|
<img
|
|
|
|
src="icon.png"
|
|
|
|
alt="Upscayl Icon"
|
2024-02-15 09:17:11 +01:00
|
|
|
className="spinner mb-4 h-12 w-12"
|
2024-01-15 11:25:28 +01:00
|
|
|
/>
|
2024-02-15 09:17:11 +01:00
|
|
|
<p className="rounded-full px-2 pb-2 font-bold">
|
2023-09-09 14:18:00 +02:00
|
|
|
{batchMode && "Batch Upscale In Progress: " + batchProgress}
|
2024-01-15 11:25:28 +01:00
|
|
|
|
2023-07-23 11:07:18 +02:00
|
|
|
{!batchMode &&
|
|
|
|
(doubleUpscaylCounter > 0
|
|
|
|
? `${progress}\nPass ${doubleUpscaylCounter}`
|
|
|
|
: `${progress}`)}
|
2022-11-11 21:39:28 +01:00
|
|
|
</p>
|
2024-01-15 11:25:28 +01:00
|
|
|
|
2024-02-15 09:17:11 +01:00
|
|
|
<p className="animate-pulse rounded-full px-2 pb-3 text-sm font-medium">
|
2023-03-12 08:59:07 +01:00
|
|
|
Doing the Upscayl magic...
|
|
|
|
</p>
|
2024-02-15 09:17:11 +01:00
|
|
|
<button onClick={stopHandler} className="btn btn-outline">
|
2023-04-29 19:12:40 +02:00
|
|
|
STOP
|
|
|
|
</button>
|
2022-11-11 21:39:28 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ProgressBar;
|