Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Limit uploads to 5 images
Abi Rajabf308365d8d1
diff --git a/frontend/src/components/UpdateImageUpload.tsx b/frontend/src/components/UpdateImageUpload.tsxindex 2a8e05f2..d7c8f320 100644--- a/frontend/src/components/UpdateImageUpload.tsx+++ b/frontend/src/components/UpdateImageUpload.tsx@@ -3,6 +3,8 @@ import { toast } from "react-hot-toast";import { Cross2Icon, ImageIcon } from "@radix-ui/react-icons";import { Button } from "./ui/button";+const MAX_UPDATE_IMAGES = 5;+// Helper function to convert file to data URLfunction fileToDataURL(file: File): Promise<string> {return new Promise((resolve, reject) => {@@ -26,8 +28,15 @@ export function UpdateImagePreview({ updateImages, setUpdateImages }: Props) {if (updateImages.length === 0) return null;+ const remaining = Math.max(0, MAX_UPDATE_IMAGES - updateImages.length);+ const isAtLimit = remaining === 0;+return (<div className="mb-2">+ <div className="flex items-center justify-between text-xs text-gray-500 dark:text-gray-400 mb-1">+ <span>{`Reference images: ${updateImages.length}/${MAX_UPDATE_IMAGES}`}</span>+ <span>{isAtLimit ? "Limit reached" : `${remaining} remaining`}</span>+ </div><div className="flex gap-2 overflow-x-auto py-2">{updateImages.map((image, index) => (<div key={index} className="relative flex-shrink-0 group">@@ -51,9 +60,17 @@ export function UpdateImagePreview({ updateImages, setUpdateImages }: Props) {function UpdateImageUpload({ updateImages, setUpdateImages }: Props) {const fileInputRef = useRef<HTMLInputElement>(null);+ const remaining = Math.max(0, MAX_UPDATE_IMAGES - updateImages.length);+ const isAtLimit = remaining === 0;const handleButtonClick = () => {+ if (isAtLimit) {+ toast.error(+ `You’ve reached the limit of ${MAX_UPDATE_IMAGES} reference images. Remove one to add another.`+ );+ return;+ }fileInputRef.current?.click();};@@ -61,9 +78,28 @@ function UpdateImageUpload({ updateImages, setUpdateImages }: Props) {const files = e.target.files;if (files) {try {- const newImagePromises = Array.from(files).map(file => fileToDataURL(file));+ if (updateImages.length >= MAX_UPDATE_IMAGES) {+ toast.error(+ `You’ve reached the limit of ${MAX_UPDATE_IMAGES} reference images. Remove one to add another.`+ );+ return;+ }++ const remainingSlots = MAX_UPDATE_IMAGES - updateImages.length;+ let filesToAdd = Array.from(files);+ if (filesToAdd.length > remainingSlots) {+ toast.error(+ `Only ${remainingSlots} more image${+ remainingSlots === 1 ? "" : "s"+ } will be added to stay within the ${MAX_UPDATE_IMAGES}-image limit.`+ );+ filesToAdd = filesToAdd.slice(0, remainingSlots);+ }++ const newImagePromises = filesToAdd.map((file) => fileToDataURL(file));const newImages = await Promise.all(newImagePromises);setUpdateImages([...updateImages, ...newImages]);+ e.target.value = "";} catch (error) {toast.error("Error reading image files");console.error("Error reading files:", error);@@ -88,13 +124,20 @@ function UpdateImageUpload({ updateImages, setUpdateImages }: Props) {variant="outline"size="default"onClick={handleButtonClick}- className={`dark:text-white dark:bg-gray-700 h-10 px-3 ${updateImages.length > 0 ? 'border-blue-500' : ''} relative`}- title={updateImages.length > 0 ? "Add more images" : "Add reference images"}+ className={`dark:text-white dark:bg-gray-700 h-10 px-3 ${+ updateImages.length > 0 ? "border-blue-500" : ""+ } relative`}+ disabled={isAtLimit}+ title={+ isAtLimit+ ? `Limit reached (${MAX_UPDATE_IMAGES})`+ : updateImages.length > 0+ ? `Add up to ${remaining} more`+ : `Add up to ${MAX_UPDATE_IMAGES}`+ }><ImageIcon className="h-4 w-4" />- {updateImages.length > 0 && (- <span className="ml-2 text-sm">{updateImages.length}</span>- )}+ <span className="ml-2 text-sm">{`${updateImages.length}/${MAX_UPDATE_IMAGES}`}</span></Button></div>diff --git a/frontend/src/components/unified-input/tabs/UploadTab.tsx b/frontend/src/components/unified-input/tabs/UploadTab.tsxindex 38c2272e..7a88171a 100644--- a/frontend/src/components/unified-input/tabs/UploadTab.tsx+++ b/frontend/src/components/unified-input/tabs/UploadTab.tsx@@ -30,7 +30,7 @@ type FileWithPreview = {preview: string;} & File;-const MAX_FILES = 10;+const MAX_FILES = 5;const isVideoFile = (file: File) =>file.type.startsWith("video/") ||@@ -61,6 +61,8 @@ function UploadTab({ doCreate }: Props) {useState<ScreenRecorderState>(ScreenRecorderState.INITIAL);const hasUploadedFile = uploadedDataUrls.length > 0;+ const remainingSlots = Math.max(0, MAX_FILES - files.length);+ const isAtLimit = remainingSlots === 0;const handleGenerate = useCallback(() => {if (uploadedDataUrls.length > 0) {@@ -108,7 +110,9 @@ function UploadTab({ doCreate }: Props) {const hasExistingImages = files.length > 0 && uploadedInputMode === "image";if (incomingHasVideo && (acceptedFiles.length > 1 || hasExistingImages)) {- toast.error("Please upload a single video or multiple images.");+ toast.error(+ `Upload either one video or up to ${MAX_FILES} screenshots (not both).`+ );return;}@@ -118,7 +122,9 @@ function UploadTab({ doCreate }: Props) {}if (!incomingHasVideo && files.length >= MAX_FILES) {- toast.error(`You can upload up to ${MAX_FILES} images.`);+ toast.error(+ `You’ve reached the limit of ${MAX_FILES} screenshots. Remove one to add another.`+ );return;}@@ -126,9 +132,9 @@ function UploadTab({ doCreate }: Props) {if (!incomingHasVideo && files.length + acceptedFiles.length > MAX_FILES) {const remainingSlots = MAX_FILES - files.length;toast.error(- `You can add up to ${remainingSlots} more image${+ `Only ${remainingSlots} more screenshot${remainingSlots === 1 ? "" : "s"- }.`+ } will be added to stay within the ${MAX_FILES}-screenshot limit.`);filesToAdd = acceptedFiles.slice(0, remainingSlots);}@@ -161,7 +167,7 @@ function UploadTab({ doCreate }: Props) {setTimeout(() => textInputRef.current?.focus(), 100);} catch (error) {newFiles.forEach((file) => URL.revokeObjectURL(file.preview));- toast.error("Error reading files" + error);+ toast.error("Error reading files.");console.error("Error reading files:", error);}},@@ -190,7 +196,28 @@ function UploadTab({ doCreate }: Props) {},onDrop: handleAddFiles,onDropRejected: (rejectedFiles) => {- toast.error(rejectedFiles[0].errors[0].message);+ const firstError = rejectedFiles[0]?.errors?.[0];+ if (!firstError) {+ toast.error("Some files were rejected.");+ return;+ }++ if (firstError.code === "file-too-large") {+ toast.error("One or more files exceed the 20MB limit.");+ return;+ }++ if (firstError.code === "file-invalid-type") {+ toast.error("Unsupported file type. Use PNG, JPG, MP4, MOV, or WebM.");+ return;+ }++ if (firstError.code === "too-many-files") {+ toast.error(`You can upload up to ${MAX_FILES} screenshots.`);+ return;+ }++ toast.error(firstError.message);},});@@ -292,7 +319,7 @@ function UploadTab({ doCreate }: Props) {</div><div className="text-center"><p className="text-gray-700 font-medium">- Drop screenshots or a video here+ Drop up to {MAX_FILES} screenshots or a single video</p></div><p className="text-xs text-gray-400 mt-2">@@ -337,7 +364,7 @@ function UploadTab({ doCreate }: Props) {><input {...getInputProps()} /><div className="flex items-center justify-between text-xs uppercase tracking-wide text-gray-400">- <span>Uploaded Screenshots ({files.length})</span>+ <span>{`Uploaded Screenshots (${files.length}/${MAX_FILES})`}</span><buttontype="button"onClick={handleClear}@@ -346,6 +373,11 @@ function UploadTab({ doCreate }: Props) {Clear all</button></div>+ <div className="mt-1 text-[11px] text-gray-400">+ {isAtLimit+ ? "Limit reached"+ : `${remainingSlots} remaining`}+ </div><div className="mt-3 rounded-md border border-gray-100 bg-gray-50 p-2">{files[selectedIndex] && (<img@@ -386,8 +418,21 @@ function UploadTab({ doCreate }: Props) {))}<buttontype="button"- onClick={open}- className="h-14 w-14 rounded-md border border-dashed border-gray-300 text-gray-500 hover:text-gray-700 hover:border-gray-400 flex items-center justify-center flex-shrink-0"+ onClick={() => {+ if (isAtLimit) {+ toast.error(+ `You’ve reached the limit of ${MAX_FILES} screenshots. Remove one to add another.`+ );+ return;+ }+ open();+ }}+ disabled={isAtLimit}+ className={`h-14 w-14 rounded-md border border-dashed flex items-center justify-center flex-shrink-0 ${+ isAtLimit+ ? "border-gray-200 text-gray-300 cursor-not-allowed"+ : "border-gray-300 text-gray-500 hover:text-gray-700 hover:border-gray-400"+ }`}aria-label="Add more screenshots"><ImageIcon className="h-5 w-5" />