1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-07 04:01:34 +01:00
upscayl/renderer/components/main-content/progress-bar.tsx

88 lines
2.6 KiB
TypeScript
Raw Normal View History

import React, { useEffect } from "react";
import UpscaylSVGLogo from "@/components/icons/upscayl-logo-svg";
import { useAtomValue } from "jotai";
import { translationAtom } from "@/atoms/translations-atom";
import { ELECTRON_COMMANDS } from "@common/electron-commands";
import useLogger from "../hooks/use-logger";
2022-11-11 21:39:28 +01:00
function ProgressBar({
progress,
doubleUpscaylCounter,
batchMode,
resetImagePaths,
2023-10-21 15:43:03 +02:00
}: {
progress: string;
doubleUpscaylCounter: number;
batchMode: boolean;
resetImagePaths: () => void;
}) {
2023-09-09 14:18:00 +02:00
const [batchProgress, setBatchProgress] = React.useState(0);
const t = useAtomValue(translationAtom);
const logit = useLogger();
2023-09-09 14:18:00 +02:00
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]);
const stopHandler = () => {
window.electron.send(ELECTRON_COMMANDS.STOP);
logit("🛑 Stopping Upscayl");
resetImagePaths();
};
2024-08-31 13:05:53 +02:00
// const progressStyle = useMemo(() => {
// if (progress.includes("%")) {
// return {
// "--value": parseFloat(progress.replace("%", "")),
// };
// } else if (progress.includes("Success")) {
// return {
// "--value": 100,
// };
// }
// return {
// "--value": 0,
// };
// }, [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-08-31 13:05:53 +02:00
<div className="flex flex-col items-center gap-2 rounded-btn bg-base-100/50 p-4 backdrop-blur-lg">
<UpscaylSVGLogo className="spinner h-12 w-12" />
<p className="rounded-full px-2 pb-2 font-bold">
{batchMode &&
`${t("APP.PROGRESS_BAR.BATCH_UPSCAYL_IN_PROGRESS_TITLE")} ${batchProgress}`}
2023-03-12 08:59:07 +01:00
</p>
2024-08-31 13:05:53 +02:00
<div className="flex flex-col items-center gap-1">
{progress !== "Hold on..." ? (
<p className="text-sm font-bold">
{progress}
{!batchMode &&
doubleUpscaylCounter > 0 &&
"\nPass " + doubleUpscaylCounter}
</p>
) : (
<p className="text-sm font-bold">{progress}</p>
)}
2024-08-31 13:05:53 +02:00
<p className="animate-pulse rounded-full px-2 pb-3 text-xs font-medium text-neutral-content/50">
{t("APP.PROGRESS_BAR.IN_PROGRESS_TITLE")}
2024-08-31 13:05:53 +02:00
</p>
</div>
2024-02-15 09:17:11 +01:00
<button onClick={stopHandler} className="btn btn-outline">
{t("APP.PROGRESS_BAR.STOP_BUTTON_TITLE")}
2023-04-29 19:12:40 +02:00
</button>
2022-11-11 21:39:28 +01:00
</div>
</div>
);
}
export default ProgressBar;