1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-12-03 03:27:25 +01:00
upscayl/renderer/components/LeftPaneImageSteps.tsx

288 lines
9.1 KiB
TypeScript
Raw Normal View History

2022-12-11 06:47:00 +01:00
import React, { useEffect, useState } from "react";
2022-11-11 21:39:28 +01:00
import Select from "react-select";
import ReactTooltip from "react-tooltip";
2022-12-08 04:25:26 +01:00
import { themeChange } from "theme-change";
2022-11-11 21:39:28 +01:00
2022-11-15 15:54:06 +01:00
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-12-16 17:20:46 +01:00
saveImageAs: string;
setSaveImageAs: (arg: string) => void;
gpuId: string;
setGpuId: (arg: string) => void;
2022-11-15 15:54:06 +01:00
}
2022-11-23 19:24:30 +01:00
function LeftPaneImageSteps({
2022-11-15 15:54:06 +01:00
progress,
selectImageHandler,
selectFolderHandler,
handleModelChange,
handleDrop,
outputHandler,
upscaylHandler,
batchMode,
setBatchMode,
imagePath,
outputPath,
doubleUpscayl,
setDoubleUpscayl,
model,
isVideo,
setIsVideo,
2022-12-16 17:20:46 +01:00
gpuId,
setGpuId,
saveImageAs,
setSaveImageAs,
2022-11-15 15:54:06 +01:00
}: IProps) {
2022-12-08 04:25:26 +01:00
useEffect(() => {
themeChange(false);
2022-12-11 06:47:00 +01:00
if (!localStorage.getItem("saveImageAs")) {
localStorage.setItem("saveImageAs", "png");
} else {
setSaveImageAs(localStorage.getItem("saveImageAs"));
}
2022-12-08 04:25:26 +01:00
}, []);
2022-12-11 06:47:00 +01:00
const setExportType = (format: string) => {
setSaveImageAs(format);
localStorage.setItem("saveImageAs", format);
};
2022-12-08 04:25:26 +01:00
2022-11-11 21:39:28 +01:00
const handleBatchMode = () => {
2022-11-15 15:54:06 +01:00
setBatchMode((oldValue) => !oldValue);
2022-11-11 21:39:28 +01:00
};
2022-12-11 06:47:00 +01:00
const handleGpuIdChange = (e) => {
setGpuId(e.target.value);
};
2022-11-11 21:39:28 +01:00
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 = [
{ label: "General Photo (Real-ESRGAN)", value: "realesrgan-x4plus" },
2022-12-02 15:21:42 +01:00
{ label: "General Photo (Remacri)", value: "remacri" },
{ label: "General Photo (Ultramix Balanced)", value: "ultramix_balanced" },
{ label: "General Photo (Ultrasharp)", value: "ultrasharp" },
2022-11-11 21:39:28 +01:00
{ label: "Digital Art", value: "realesrgan-x4plus-anime" },
{ label: "Sharpen Image", value: "models-DF2K" },
];
2022-12-11 06:47:00 +01:00
const availableThemes = [
2022-12-16 17:20:46 +01:00
{ label: "light", value: "light" },
{ label: "dark", value: "dark" },
{ label: "cupcake", value: "cupcake" },
{ label: "bumblebee", value: "bumblebee" },
{ label: "emerald", value: "emerald" },
{ label: "corporate", value: "corporate" },
{ label: "synthwave", value: "synthwave" },
{ label: "retro", value: "retro" },
{ label: "cyberpunk", value: "cyberpunk" },
{ label: "valentine", value: "valentine" },
{ label: "halloween", value: "halloween" },
{ label: "garden", value: "garden" },
{ label: "forest", value: "forest" },
{ label: "aqua", value: "aqua" },
{ label: "lofi", value: "lofi" },
{ label: "pastel", value: "pastel" },
{ label: "fantasy", value: "fantasy" },
{ label: "wireframe", value: "wireframe" },
{ label: "black", value: "black" },
{ label: "luxury", value: "luxury" },
{ label: "dracula", value: "dracula" },
{ label: "cmyk", value: "cmyk" },
{ label: "autumn", value: "autumn" },
{ label: "business", value: "business" },
{ label: "acid", value: "acid" },
{ label: "lemonade", value: "lemonade" },
{ label: "night", value: "night" },
{ label: "coffee", value: "coffee" },
{ label: "winter", value: "winter" },
2022-12-11 06:47:00 +01:00
];
2022-11-11 21:39:28 +01:00
return (
2022-11-15 15:42:20 +01:00
<div className="animate-step-in animate flex h-screen flex-col gap-7 overflow-y-auto p-5 overflow-x-hidden">
2022-11-11 21:39:28 +01:00
{/* BATCH OPTION */}
2022-11-11 22:32:24 +01:00
<div className="flex flex-row items-center gap-2">
<input
type="checkbox"
2022-11-15 15:42:20 +01:00
className="toggle"
2022-11-23 19:24:30 +01:00
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-11 21:39:28 +01:00
</div>
{/* STEP 1 */}
2022-11-15 15:54:06 +01:00
<div data-tip={imagePath}>
2022-11-11 21:39:28 +01:00
<p className="step-heading">Step 1</p>
<button
2022-11-11 22:32:24 +01:00
className="btn-primary btn"
2022-11-23 19:24:30 +01:00
onClick={!batchMode ? selectImageHandler : selectFolderHandler}>
2022-11-15 15:54:06 +01:00
Select {batchMode ? "Folder" : "Image"}
2022-11-11 21:39:28 +01:00
</button>
</div>
{/* STEP 2 */}
<div className="animate-step-in">
<p className="step-heading">Step 2</p>
2022-11-11 22:32:24 +01:00
<p className="mb-2 text-sm">Select Upscaling Type</p>
2022-11-11 21:39:28 +01:00
<Select
options={modelOptions}
components={{
IndicatorSeparator: () => null,
DropdownIndicator: () => null,
}}
2022-11-15 15:54:06 +01:00
onChange={handleModelChange}
2022-11-14 17:07:39 +01:00
className="react-select-container"
2022-11-11 21:39:28 +01:00
classNamePrefix="react-select"
defaultValue={modelOptions[0]}
/>
2022-11-15 15:54:06 +01:00
{model !== "models-DF2K" && !batchMode && (
2022-11-23 19:24:30 +01:00
<div className="mt-4 flex items-center gap-1">
2022-11-11 21:39:28 +01:00
<input
type="checkbox"
2022-11-11 22:32:24 +01:00
className="checkbox"
2022-11-15 15:54:06 +01:00
checked={doubleUpscayl}
2022-11-11 21:39:28 +01:00
onChange={(e) => {
if (e.target.checked) {
2022-11-15 15:54:06 +01:00
setDoubleUpscayl(true);
2022-11-11 21:39:28 +01:00
} else {
2022-11-15 15:54:06 +01:00
setDoubleUpscayl(false);
2022-11-11 21:39:28 +01:00
}
}}
/>
<p
2022-11-11 22:32:24 +01:00
className="cursor-pointer text-sm"
2022-11-11 21:39:28 +01:00
onClick={(e) => {
2022-11-15 15:54:06 +01:00
setDoubleUpscayl(!doubleUpscayl);
2022-11-23 19:24:30 +01:00
}}>
2022-11-11 21:39:28 +01:00
Double Upscayl
</p>
2022-11-23 19:24:30 +01:00
<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-11 21:39:28 +01:00
</div>
)}
</div>
{/* STEP 3 */}
2022-11-15 15:54:06 +01:00
<div className="animate-step-in" data-tip={outputPath}>
2022-11-11 21:39:28 +01:00
<p className="step-heading">Step 3</p>
2022-11-11 22:32:24 +01:00
<p className="mb-2 text-sm">Defaults to Image's path</p>
2022-11-15 15:54:06 +01:00
<button className="btn-primary btn" onClick={outputHandler}>
2022-11-11 21:39:28 +01:00
Set Output Folder
</button>
</div>
{/* STEP 4 */}
<div className="animate-step-in">
<p className="step-heading">Step 4</p>
<button
2022-11-11 22:32:24 +01:00
className="btn-accent btn"
2022-11-15 15:54:06 +01:00
onClick={upscaylHandler}
2022-11-23 19:24:30 +01:00
disabled={progress.length > 0}>
2022-11-15 15:54:06 +01:00
{progress.length > 0 ? "Upscayling⏳" : "Upscayl"}
2022-11-11 21:39:28 +01:00
</button>
2022-12-08 04:25:26 +01:00
<div className="rounded-btn collapse mt-5">
<input type="checkbox" className="peer" />
<div className="collapse-title bg-neutral text-neutral-content peer-checked:bg-primary peer-checked:text-primary-content">
Advanced Options
</div>
<div className="collapse-content flex flex-col gap-4 bg-neutral text-neutral-content peer-checked:bg-base-300 peer-checked:py-4 peer-checked:text-base-content">
<div className="flex flex-col gap-2">
<p>Save Image As:</p>
<div className="flex gap-2">
2022-12-11 06:47:00 +01:00
<button
className={`btn-primary btn ${
saveImageAs === "png" && "btn-accent"
}`}
onClick={() => setExportType("png")}>
PNG
</button>
<button
className={`btn-primary btn ${
saveImageAs === "jpg" && "btn-accent"
}`}
onClick={() => setExportType("jpg")}>
JPG
</button>
<button
className={`btn-primary btn ${
saveImageAs === "webp" && "btn-accent"
}`}
onClick={() => setExportType("webp")}>
WEBP
</button>
2022-12-08 04:25:26 +01:00
</div>
</div>
<div className="flex flex-col gap-2">
<p>Upscayl Theme:</p>
<select data-choose-theme className="select-primary select">
<option value="dark">Default</option>
{availableThemes.map((theme) => {
return (
2022-12-16 17:20:46 +01:00
<option value={theme.value} key={theme.value}>
{theme.label.toLocaleUpperCase()}
2022-12-11 06:47:00 +01:00
</option>
2022-12-08 04:25:26 +01:00
);
})}
</select>
</div>
2022-12-11 06:47:00 +01:00
<div className="flex flex-col gap-2">
<p>GPU ID:</p>
<input
2022-12-16 17:20:46 +01:00
type="text"
2022-12-11 06:47:00 +01:00
placeholder="Type here"
className="input w-full max-w-xs"
value={gpuId}
onChange={handleGpuIdChange}
/>
</div>
2022-12-08 04:25:26 +01:00
</div>
</div>
2022-11-11 21:39:28 +01:00
</div>
2022-11-23 19:24:30 +01:00
<ReactTooltip class="max-w-sm" />
2022-11-11 21:39:28 +01:00
</div>
);
}
2022-11-23 19:24:30 +01:00
export default LeftPaneImageSteps;