1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-19 10:55:53 +01:00
upscayl/renderer/components/settings-tab/OverwriteToggle.tsx

48 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-08-11 11:45:27 +02:00
import React, { useEffect } from "react";
2023-08-10 12:17:35 +02:00
2023-09-18 20:30:43 +02:00
type OverwriteToggleProps = {
2023-08-10 12:17:35 +02:00
overwrite: boolean;
setOverwrite: (arg: any) => void;
};
2023-09-18 20:30:43 +02:00
const OverwriteToggle = ({ overwrite, setOverwrite }: OverwriteToggleProps) => {
2023-08-11 11:45:27 +02:00
useEffect(() => {
if (!localStorage.getItem("overwrite")) {
localStorage.setItem("overwrite", JSON.stringify(overwrite));
} else {
2023-08-30 06:54:16 +02:00
const currentlySavedOverwrite = localStorage.getItem("overwrite");
if (currentlySavedOverwrite) {
2023-09-10 19:59:35 +02:00
setOverwrite(currentlySavedOverwrite === "true");
2023-08-30 06:54:16 +02:00
}
2023-08-11 11:45:27 +02:00
}
}, []);
2023-08-30 06:54:16 +02:00
2023-08-10 12:17:35 +02:00
return (
<div className="flex flex-col gap-2">
<p className="text-sm font-medium">OVERWRITE PREVIOUS UPSCALE</p>
2023-09-09 15:58:21 +02:00
<p className="text-xs text-base-content/80">
If enabled, Upscayl will process the image again instead of loading it
directly.
</p>
2023-08-10 12:17:35 +02:00
<input
type="checkbox"
2023-08-26 09:27:15 +02:00
className="toggle"
2023-08-10 12:17:35 +02:00
checked={overwrite}
onClick={() => {
2023-08-30 06:54:16 +02:00
setOverwrite((oldValue: boolean) => {
if (oldValue) {
2023-08-10 12:17:35 +02:00
localStorage.removeItem("overwrite");
2023-08-30 06:54:16 +02:00
return false;
} else {
return true;
2023-08-10 12:17:35 +02:00
}
});
localStorage.setItem("overwrite", JSON.stringify(!overwrite));
}}
/>
</div>
);
};
2023-09-18 20:30:43 +02:00
export default OverwriteToggle;