Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

Remove UrlInputSection component

Abi Raja62b2282f7d49
diff --git a/frontend/src/components/UrlInputSection.tsx b/frontend/src/components/UrlInputSection.tsx
deleted file mode 100644
index 2cfb9c79..00000000
--- a/frontend/src/components/UrlInputSection.tsx
+++ /dev/null
@@ -1,87 +0,0 @@
-import { useState } from "react";
-import { HTTP_BACKEND_URL } from "../config";
-import { Button } from "./ui/button";
-import { Input } from "./ui/input";
-import { toast } from "react-hot-toast";
-
-interface Props {
- screenshotOneApiKey: string | null;
- doCreate: (
- urls: string[],
- inputMode: "image" | "video",
- textPrompt?: string
- ) => void;
-}
-
-export function UrlInputSection({ doCreate, screenshotOneApiKey }: Props) {
- const [isLoading, setIsLoading] = useState(false);
- const [referenceUrl, setReferenceUrl] = useState("");
-
- async function takeScreenshot() {
- if (!screenshotOneApiKey) {
- toast.error(
- "Please add a ScreenshotOne API key in the Settings dialog. This is optional - you can also drag/drop and upload images directly.",
- { duration: 8000 }
- );
- return;
- }
-
- if (!referenceUrl) {
- toast.error("Please enter a URL");
- return;
- }
-
- if (referenceUrl) {
- try {
- setIsLoading(true);
- const response = await fetch(`${HTTP_BACKEND_URL}/api/screenshot`, {
- method: "POST",
- body: JSON.stringify({
- url: referenceUrl,
- apiKey: screenshotOneApiKey,
- }),
- headers: {
- "Content-Type": "application/json",
- },
- });
-
- if (!response.ok) {
- throw new Error("Failed to capture screenshot");
- }
-
- const res = await response.json();
- doCreate([res.url], "image");
- } catch (error) {
- console.error(error);
- toast.error(
- "Failed to capture screenshot. Look at the console and your backend logs for more details."
- );
- } finally {
- setIsLoading(false);
- }
- }
- }
-
- return (
- <div className="max-w-[90%] min-w-[40%] gap-y-2 flex flex-col">
- <div className="text-gray-500 text-sm">Or screenshot a URL...</div>
- <Input
- placeholder="Enter URL"
- onChange={(e) => setReferenceUrl(e.target.value)}
- value={referenceUrl}
- onKeyDown={(e) => {
- if (e.key === "Enter" && !isLoading) {
- takeScreenshot();
- }
- }}
- />
- <Button
- onClick={takeScreenshot}
- disabled={isLoading}
- className="bg-slate-400 capture-btn"
- >
- {isLoading ? "Capturing..." : "Capture"}
- </Button>
- </div>
- );
-}
diff --git a/frontend/src/components/unified-input/tabs/UrlTab.tsx b/frontend/src/components/unified-input/tabs/UrlTab.tsx
index fd8397d8..829b0ab7 100644
--- a/frontend/src/components/unified-input/tabs/UrlTab.tsx
+++ b/frontend/src/components/unified-input/tabs/UrlTab.tsx
@@ -11,7 +11,7 @@ interface Props {
doCreate: (
urls: string[],
inputMode: "image" | "video",
- textPrompt?: string
+ textPrompt?: string,
) => void;
stack: Stack;
setStack: (stack: Stack) => void;
@@ -22,25 +22,34 @@ function UrlTab({ doCreate, screenshotOneApiKey, stack, setStack }: Props) {
const [referenceUrl, setReferenceUrl] = useState("");
async function takeScreenshot() {
+ const trimmedReferenceUrl = referenceUrl.trim();
+
if (!screenshotOneApiKey) {
toast.error(
"Please add a ScreenshotOne API key in Settings. You can also upload screenshots directly in the Upload tab.",
- { duration: 6000 }
+ { duration: 6000 },
);
return;
}
- if (!referenceUrl) {
+ if (!trimmedReferenceUrl) {
toast.error("Please enter a URL");
return;
}
+ if (trimmedReferenceUrl.toLowerCase().startsWith("file://")) {
+ toast.error(
+ "file:// URLs can't be screenshot. If you're trying to import a local file, please use the Import tab.",
+ );
+ return;
+ }
+
try {
setIsLoading(true);
const response = await fetch(`${HTTP_BACKEND_URL}/api/screenshot`, {
method: "POST",
body: JSON.stringify({
- url: referenceUrl,
+ url: trimmedReferenceUrl,
apiKey: screenshotOneApiKey,
}),
headers: {
@@ -101,10 +110,7 @@ function UrlTab({ doCreate, screenshotOneApiKey, stack, setStack }: Props) {
className="w-full"
data-testid="url-input"
/>
- <OutputSettingsSection
- stack={stack}
- setStack={setStack}
- />
+ <OutputSettingsSection stack={stack} setStack={setStack} />
<Button
onClick={takeScreenshot}