2022-11-11 21:39:28 +01:00
import React from "react" ;
import Select from "react-select" ;
import ReactTooltip from "react-tooltip" ;
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-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 ,
} : IProps ) {
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
} ;
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" , value : "realesrgan-x4plus" } ,
{ label : "Digital Art" , value : "realesrgan-x4plus-anime" } ,
{ label : "Sharpen Image" , value : "models-DF2K" } ,
] ;
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 >
< / 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 ;