From eb8cf5011d205146447deafcca3136e6946cfba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aykut=20Karda=C5=9F?= Date: Tue, 5 Mar 2024 16:47:45 +0300 Subject: [PATCH] feat: improve ui & ux and fix loading states --- app/page.tsx | 135 ++++++++++++++++------------- components/compare-image-label.tsx | 8 +- components/model-compare.tsx | 6 ++ components/original-compare.tsx | 6 ++ 4 files changed, 92 insertions(+), 63 deletions(-) diff --git a/app/page.tsx b/app/page.tsx index 76a966b..097992f 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -16,6 +16,7 @@ import { UPSCALE_MODELS, } from "@/components/model-dropdown"; import { Button } from "@/components/ui/button"; +import { LoaderIcon } from "lucide-react"; fal.config({ proxyUrl: "/api/proxy" }); @@ -26,9 +27,7 @@ interface ModelResult { type CompareMode = "original" | "model"; -UPSCALE_MODELS; - -export default function Lightning() { +export default function UpscalerBattleground() { const [mode, setMode] = useState("original"); const [position, setPosition] = useState(50); const [originalImage, setOriginalImage] = useState(null); @@ -104,17 +103,23 @@ export default function Lightning() { setSecondModelLoading(false); }; - const handleCompare = async () => { - if (!imageFile) return; - - setPosition(50); - - const blobUrl = URL.createObjectURL(imageFile); - setOriginalImage(blobUrl); + const handleImageSelect = (e: React.ChangeEvent) => { + const image = e.target?.files?.[0]; setFirstModelOutput(null); setSecondModelOutput(null); + setImageFile(image || null); + setPosition(50); + + if (image) { + const blobUrl = URL.createObjectURL(image); + setOriginalImage(blobUrl); + } + }; + const handleCompare = async () => { + if (!imageFile) return; + upscaleWithFirstModel(imageFile); upscaleWithSecondModel(imageFile); }; @@ -128,67 +133,73 @@ export default function Lightning() { return (
-
-
-
-
- - { - setImageFile(e.target?.files?.[0] || null); - }} - className={cn( - "font-light mx-auto rounded-full h-10 pr-10 truncate", - !imageFile && "border-orange-400" - )} - placeholder="Type something..." - /> -
-
- -
- setMode("original")} - className={cn( - mode === "original" && - "bg-neutral-900 text-white dark:bg-neutral-200 dark:text-black", - "w-1/2 cursor-pointer text-sm rounded-full h-8 px-3 flex items-center" - )} - > - Original - - setMode("model")} +
+
+
+
+
+ +
+ setMode("original")} + className={cn( + mode === "original" && + "bg-neutral-900 text-white dark:bg-neutral-200 dark:text-black", + "w-1/2 cursor-pointer text-sm rounded-full h-8 px-3 flex items-center" + )} + > + Original + + setMode("model")} + className={cn( + mode === "model" && + "bg-neutral-900 text-white dark:bg-neutral-200 dark:text-black", + "w-1/2 cursor-pointer text-sm rounded-full h-8 px-3 flex items-center" + )} + > + Model + +
+
+
+ + - Model - + placeholder="Type something..." + />
+
-
-
+
+
setFirstModel(model)} value={firstModel} />
-
- -
-
+ +
setSecondModel(model)} value={secondModel} @@ -202,8 +213,10 @@ export default function Lightning() { setPosition={setPosition} firstModel={firstModel} firstModelOutput={firstModelOutput} + firstModelLoading={firstModelLoading} secondModel={secondModel} secondModelOutput={secondModelOutput} + secondModelLoading={secondModelLoading} /> )} {mode === "original" && ( @@ -213,8 +226,10 @@ export default function Lightning() { setPosition={setPosition} firstModel={firstModel} firstModelOutput={firstModelOutput} + firstModelLoading={firstModelLoading} secondModel={secondModel} secondModelOutput={secondModelOutput} + secondModelLoading={secondModelLoading} /> )}
diff --git a/components/compare-image-label.tsx b/components/compare-image-label.tsx index 488badc..9de637a 100644 --- a/components/compare-image-label.tsx +++ b/components/compare-image-label.tsx @@ -4,12 +4,14 @@ import { LoaderIcon } from "lucide-react"; interface CompareImageLabelProps { modelData: any; name: string; + loading: boolean; position?: "left" | "right"; } const CompareImageLabel = ({ modelData, name, + loading, position = "left", }: CompareImageLabelProps) => (
{name} - {modelData ? ( + {loading ? ( + + ) : ( {modelData ? formatTime(modelData.inferenceTime * 1000) : `n/a`} - ) : ( - )}
); diff --git a/components/model-compare.tsx b/components/model-compare.tsx index 22a4fd2..3bf3cad 100644 --- a/components/model-compare.tsx +++ b/components/model-compare.tsx @@ -12,8 +12,10 @@ interface ModelCompareProps { setPosition: (position: number) => void; firstModel: any; firstModelOutput: any; + firstModelLoading: boolean; secondModel: any; secondModelOutput: any; + secondModelLoading: boolean; } const ModelCompare = ({ @@ -22,8 +24,10 @@ const ModelCompare = ({ setPosition, firstModel, firstModelOutput, + firstModelLoading, secondModel, secondModelOutput, + secondModelLoading, }: ModelCompareProps) => { return (
@@ -45,6 +49,7 @@ const ModelCompare = ({ alt="Image one" /> @@ -61,6 +66,7 @@ const ModelCompare = ({ alt="Image two" /> void; firstModel: any; firstModelOutput: any; + firstModelLoading: boolean; secondModel: any; secondModelOutput: any; + secondModelLoading: boolean; } const OriginalCompare = ({ @@ -22,8 +24,10 @@ const OriginalCompare = ({ setPosition, firstModel, firstModelOutput, + firstModelLoading, secondModel, secondModelOutput, + secondModelLoading, }: OriginalCompareProps) => { return (
@@ -57,6 +61,7 @@ const OriginalCompare = ({ alt="Image one" />