import { useAtom, useAtomValue } from "jotai"; import React, { useCallback, useEffect, useMemo, useState } from "react"; import Select from "react-select"; import { Tooltip } from "react-tooltip"; import { themeChange } from "theme-change"; import { modelsListAtom } from "../../../atoms/modelsListAtom"; import useLog from "../../hooks/useLog"; import { noImageProcessingAtom, outputPathAtom, progressAtom, scaleAtom, } from "../../../atoms/userSettingsAtom"; import { featureFlags } from "@common/feature-flags"; interface IProps { selectImageHandler: () => Promise; selectFolderHandler: () => Promise; handleModelChange: (e: any) => void; outputHandler: () => Promise; upscaylHandler: () => Promise; batchMode: boolean; setBatchMode: React.Dispatch>; imagePath: string; doubleUpscayl: boolean; setDoubleUpscayl: React.Dispatch>; dimensions: { width: number | null; height: number | null; }; setSaveImageAs: React.Dispatch>; model: string; setModel: React.Dispatch>; setGpuId: React.Dispatch>; } function LeftPaneImageSteps({ selectImageHandler, selectFolderHandler, handleModelChange, outputHandler, upscaylHandler, batchMode, setBatchMode, imagePath, doubleUpscayl, setDoubleUpscayl, dimensions, setSaveImageAs, model, setModel, setGpuId, }: IProps) { const [currentModel, setCurrentModel] = useState<{ label: string; value: string; }>({ label: null, value: null, }); const modelOptions = useAtomValue(modelsListAtom); const scale = useAtomValue(scaleAtom); const noImageProcessing = useAtomValue(noImageProcessingAtom); const [outputPath, setOutputPath] = useAtom(outputPathAtom); const [progress, setProgress] = useAtom(progressAtom); const { logit } = useLog(); useEffect(() => { themeChange(false); if (!localStorage.getItem("saveImageAs")) { logit("⚙️ Setting saveImageAs to png"); localStorage.setItem("saveImageAs", "png"); } else { const currentlySavedImageFormat = localStorage.getItem("saveImageAs"); logit( "⚙️ Getting saveImageAs from localStorage: ", currentlySavedImageFormat ); setSaveImageAs(currentlySavedImageFormat); } if (!localStorage.getItem("model")) { setCurrentModel(modelOptions[0]); setModel(modelOptions[0].value); localStorage.setItem("model", JSON.stringify(modelOptions[0])); logit("🔀 Setting model to", modelOptions[0].value); } else { const currentlySavedModel = JSON.parse( localStorage.getItem("model") ) as (typeof modelOptions)[0]; setCurrentModel(currentlySavedModel); setModel(currentlySavedModel.value); logit( "⚙️ Getting model from localStorage: ", JSON.stringify(currentlySavedModel) ); } if (!localStorage.getItem("gpuId")) { localStorage.setItem("gpuId", ""); logit("⚙️ Setting gpuId to empty string"); } else { const currentlySavedGpuId = localStorage.getItem("gpuId"); setGpuId(currentlySavedGpuId); logit("⚙️ Getting gpuId from localStorage: ", currentlySavedGpuId); } }, []); useEffect(() => { logit("🔀 Setting model to", currentModel.value); }, [currentModel]); const getUpscaleResolution = useCallback(() => { const newDimensions = { width: dimensions.width, height: dimensions.height, }; let doubleScale = parseInt(scale) * parseInt(scale); let singleScale = parseInt(scale); if (noImageProcessing) { let initialScale = 4; if (model.includes("x1")) { initialScale = 1; } else if (model.includes("x2")) { initialScale = 2; } else if (model.includes("x3")) { initialScale = 3; } else { initialScale = 4; } doubleScale = initialScale * initialScale; singleScale = initialScale; } if (doubleUpscayl) { const newWidth = dimensions.width * doubleScale; const newHeight = dimensions.height * doubleScale; if (newWidth < 32768 || newHeight < 32768) { newDimensions.width = newWidth; newDimensions.height = newHeight; } else { newDimensions.width = 32384; newDimensions.height = 32384; } } else { newDimensions.width = dimensions.width * singleScale; newDimensions.height = dimensions.height * singleScale; } return newDimensions; }, [dimensions.width, dimensions.height, doubleUpscayl, scale]); return (
{/* BATCH OPTION */}
{ setOutputPath(""); setProgress(""); setBatchMode((oldValue) => !oldValue); }}>

Batch Upscayl

{/* STEP 1 */}

Step 1

{/* STEP 2 */}

Step 2

Select Model

{ if (e.target.checked) { setDoubleUpscayl(true); } else { setDoubleUpscayl(false); } }} />

{ setDoubleUpscayl(!doubleUpscayl); }}> Double Upscayl

)}
{/* STEP 3 */}
Step 3 {!outputPath && featureFlags.APP_STORE_BUILD && (
Not selected
)}
{!batchMode && !featureFlags.APP_STORE_BUILD && (

Defaults to {!batchMode ? "Image's" : "Folder's"} path

)}
{/* STEP 4 */}

Step 4

{dimensions.width && dimensions.height && (

Upscayl from{" "} {dimensions.width}x{dimensions.height} {" "} to{" "} {getUpscaleResolution().width}x{getUpscaleResolution().height}

)}
); } export default LeftPaneImageSteps;