1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-26 06:58:10 +01:00
upscayl/renderer/components/LeftPaneImageSteps.tsx

172 lines
4.9 KiB
TypeScript
Raw Permalink Normal View History

2022-11-12 02:09:28 +05:30
import React from "react";
import Select from "react-select";
import ReactTooltip from "react-tooltip";
2022-11-15 20:24:06 +05:30
interface IProps {
progress: string;
selectImageHandler: () => Promise<void>;
selectFolderHandler: () => Promise<void>;
handleModelChange: (e: any) => void;
handleDrop: (e: any) => void;
outputHandler: () => Promise<void>;
upscaylHandler: () => Promise<void>;
batchMode: boolean;
setBatchMode: (arg: any) => void;
imagePath: string;
outputPath: string;
doubleUpscayl: boolean;
setDoubleUpscayl: (arg: boolean) => void;
model: string;
isVideo: boolean;
setIsVideo: (arg: boolean) => void;
}
2022-11-23 23:54:30 +05:30
function LeftPaneImageSteps({
2022-11-15 20:24:06 +05:30
progress,
selectImageHandler,
selectFolderHandler,
handleModelChange,
handleDrop,
outputHandler,
upscaylHandler,
batchMode,
setBatchMode,
imagePath,
outputPath,
doubleUpscayl,
setDoubleUpscayl,
model,
isVideo,
setIsVideo,
}: IProps) {
2022-11-12 02:09:28 +05:30
const handleBatchMode = () => {
2022-11-15 20:24:06 +05:30
setBatchMode((oldValue) => !oldValue);
2022-11-12 02:09:28 +05:30
};
const customStyles = {
option: (provided, state) => ({
...provided,
borderBottom: "1px dotted pink",
color: state.isSelected ? "red" : "blue",
padding: 20,
}),
control: () => ({
// none of react-select's styles are passed to <Control />
width: 200,
}),
singleValue: (provided, state) => {
const opacity = state.isDisabled ? 0.5 : 1;
const transition = "opacity 300ms";
return { ...provided, opacity, transition };
},
};
const modelOptions = [
2022-12-02 19:51:42 +05:30
{ label: "General Photo (Remacri)", value: "remacri" },
{ label: "General Photo (Ultramix Balanced)", value: "ultramix_balanced" },
{ label: "General Photo (Real-ESRGAN)", value: "realesrgan-x4plus" },
{ label: "General Photo (Ultrasharp)", value: "ultrasharp" },
2022-11-12 02:09:28 +05:30
{ label: "Digital Art", value: "realesrgan-x4plus-anime" },
{ label: "Sharpen Image", value: "models-DF2K" },
];
return (
2022-11-15 20:12:20 +05:30
<div className="animate-step-in animate flex h-screen flex-col gap-7 overflow-y-auto p-5 overflow-x-hidden">
2022-11-12 02:09:28 +05:30
{/* BATCH OPTION */}
2022-11-12 03:02:24 +05:30
<div className="flex flex-row items-center gap-2">
<input
type="checkbox"
2022-11-15 20:12:20 +05:30
className="toggle"
2022-11-23 23:54:30 +05:30
onClick={handleBatchMode}></input>
<p
className="mr-1 inline-block cursor-help text-sm"
data-tip="This will let you upscale all files in a folder at once">
Batch Upscale
</p>
2022-11-12 02:09:28 +05:30
</div>
{/* STEP 1 */}
2022-11-15 20:24:06 +05:30
<div data-tip={imagePath}>
2022-11-12 02:09:28 +05:30
<p className="step-heading">Step 1</p>
<button
2022-11-12 03:02:24 +05:30
className="btn-primary btn"
2022-11-23 23:54:30 +05:30
onClick={!batchMode ? selectImageHandler : selectFolderHandler}>
2022-11-15 20:24:06 +05:30
Select {batchMode ? "Folder" : "Image"}
2022-11-12 02:09:28 +05:30
</button>
</div>
{/* STEP 2 */}
<div className="animate-step-in">
<p className="step-heading">Step 2</p>
2022-11-12 03:02:24 +05:30
<p className="mb-2 text-sm">Select Upscaling Type</p>
2022-11-12 02:09:28 +05:30
<Select
options={modelOptions}
components={{
IndicatorSeparator: () => null,
DropdownIndicator: () => null,
}}
2022-11-15 20:24:06 +05:30
onChange={handleModelChange}
2022-11-14 21:37:39 +05:30
className="react-select-container"
2022-11-12 02:09:28 +05:30
classNamePrefix="react-select"
defaultValue={modelOptions[0]}
/>
2022-11-15 20:24:06 +05:30
{model !== "models-DF2K" && !batchMode && (
2022-11-23 23:54:30 +05:30
<div className="mt-4 flex items-center gap-1">
2022-11-12 02:09:28 +05:30
<input
type="checkbox"
2022-11-12 03:02:24 +05:30
className="checkbox"
2022-11-15 20:24:06 +05:30
checked={doubleUpscayl}
2022-11-12 02:09:28 +05:30
onChange={(e) => {
if (e.target.checked) {
2022-11-15 20:24:06 +05:30
setDoubleUpscayl(true);
2022-11-12 02:09:28 +05:30
} else {
2022-11-15 20:24:06 +05:30
setDoubleUpscayl(false);
2022-11-12 02:09:28 +05:30
}
}}
/>
<p
2022-11-12 03:02:24 +05:30
className="cursor-pointer text-sm"
2022-11-12 02:09:28 +05:30
onClick={(e) => {
2022-11-15 20:24:06 +05:30
setDoubleUpscayl(!doubleUpscayl);
2022-11-23 23:54:30 +05:30
}}>
2022-11-12 02:09:28 +05:30
Double Upscayl
</p>
2022-11-23 23:54:30 +05:30
<button
className="badge-info badge cursor-help"
data-tip="Enable this option to get an 8x upscayl. Note that this may not always work properly with all images, for example, images with really large resolutions.">
i
</button>
2022-11-12 02:09:28 +05:30
</div>
)}
</div>
{/* STEP 3 */}
2022-11-15 20:24:06 +05:30
<div className="animate-step-in" data-tip={outputPath}>
2022-11-12 02:09:28 +05:30
<p className="step-heading">Step 3</p>
2022-11-12 03:02:24 +05:30
<p className="mb-2 text-sm">Defaults to Image's path</p>
2022-11-15 20:24:06 +05:30
<button className="btn-primary btn" onClick={outputHandler}>
2022-11-12 02:09:28 +05:30
Set Output Folder
</button>
</div>
{/* STEP 4 */}
<div className="animate-step-in">
<p className="step-heading">Step 4</p>
<button
2022-11-12 03:02:24 +05:30
className="btn-accent btn"
2022-11-15 20:24:06 +05:30
onClick={upscaylHandler}
2022-11-23 23:54:30 +05:30
disabled={progress.length > 0}>
2022-11-15 20:24:06 +05:30
{progress.length > 0 ? "Upscayling⏳" : "Upscayl"}
2022-11-12 02:09:28 +05:30
</button>
</div>
2022-11-23 23:54:30 +05:30
<ReactTooltip class="max-w-sm" />
2022-11-12 02:09:28 +05:30
</div>
);
}
2022-11-23 23:54:30 +05:30
export default LeftPaneImageSteps;