2023-05-01 09:44:12 +02:00
import { useAtom , useAtomValue } from "jotai" ;
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" ;
2023-04-09 07:16:15 +02:00
import { modelsListAtom } from "../atoms/modelsListAtom" ;
2023-05-01 09:21:47 +02:00
import useLog from "./hooks/useLog" ;
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 ;
outputHandler : ( ) = > Promise < void > ;
upscaylHandler : ( ) = > Promise < void > ;
batchMode : boolean ;
2023-03-12 08:41:43 +01:00
setBatchMode : React.Dispatch < React.SetStateAction < boolean > > ;
2022-11-15 15:54:06 +01:00
imagePath : string ;
outputPath : string ;
doubleUpscayl : boolean ;
2023-03-12 08:41:43 +01:00
setDoubleUpscayl : React.Dispatch < React.SetStateAction < boolean > > ;
2022-12-24 08:17:54 +01:00
dimensions : {
width : number | null ;
height : number | null ;
} ;
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 ,
outputHandler ,
upscaylHandler ,
batchMode ,
setBatchMode ,
imagePath ,
outputPath ,
doubleUpscayl ,
setDoubleUpscayl ,
2022-12-24 08:17:54 +01:00
dimensions ,
2022-11-15 15:54:06 +01:00
} : IProps ) {
2022-12-24 09:45:15 +01:00
const [ currentModel , setCurrentModel ] = useState < {
label : string ;
value : string ;
} > ( {
label : null ,
value : null ,
} ) ;
2023-05-01 09:44:12 +02:00
const modelOptions = useAtomValue ( modelsListAtom ) ;
2023-03-12 08:41:43 +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"
2023-04-15 07:00:19 +02:00
defaultChecked = { batchMode }
2023-04-28 04:00:59 +02:00
onClick = { ( ) = > setBatchMode ( ( oldValue ) = > ! oldValue ) } > < / input >
2022-11-23 19:24:30 +01:00
< 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-12-27 07:45:16 +01:00
onChange = { ( e ) = > {
handleModelChange ( e ) ;
setCurrentModel ( { label : e.label , value : e.value } ) ;
} }
2022-11-14 17:07:39 +01:00
className = "react-select-container"
2022-11-11 21:39:28 +01:00
classNamePrefix = "react-select"
2022-12-24 09:45:15 +01:00
value = { currentModel }
2022-11-11 21:39:28 +01:00
/ >
2023-03-18 13:33:17 +01:00
{ ! 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"
2023-03-18 12:58:38 +01:00
data - tip = "Enable this option to get a 16x upscayl (we just run upscayl twice). Note that this may not always work properly with all images, for example, images with really large resolutions." >
2022-11-23 19:24:30 +01:00
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-12-24 08:43:38 +01:00
< p className = "mb-2 text-sm" >
Defaults to { ! batchMode ? "Image's" : "Folder'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 >
2022-12-24 08:17:54 +01:00
{ dimensions . width && dimensions . height && (
< p className = "mb-2 text-sm" >
Upscale from { " " }
< span className = "font-bold" >
{ dimensions . width } x { dimensions . height }
< / span > { " " }
to { " " }
< span className = "font-bold" >
2023-03-18 12:58:38 +01:00
{ doubleUpscayl ? dimensions . width * 16 : dimensions.width * 4 } x
{ doubleUpscayl ? dimensions . height * 16 : dimensions.height * 4 }
2022-12-24 08:17:54 +01:00
< / span >
< / p >
) }
2022-11-11 21:39:28 +01:00
< 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 >
< / 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 ;