()
| 10 | import type { ActionState } from "@/lib/actions"; |
| 11 | |
| 12 | export function URLScraper() { |
| 13 | const [url, setUrl] = useState(""); |
| 14 | const [metadata, setMetadata] = useState<ActionState | null>(null); |
| 15 | |
| 16 | const handleSubmit = async (e: React.FormEvent) => { |
| 17 | e.preventDefault(); |
| 18 | |
| 19 | if (!url) { |
| 20 | toast.error("Please enter a URL"); |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | try { |
| 25 | const formData = new FormData(); |
| 26 | formData.append("url", url); |
| 27 | |
| 28 | //@ts-ignore SOS CAMERON |
| 29 | const response = await scrapeUrl(null, formData); |
| 30 | if (response?.data) { |
| 31 | setMetadata(response); |
| 32 | toast.success("Successfully fetched metadata"); |
| 33 | } else if (response?.error) { |
| 34 | toast.error(response.error); |
| 35 | } else { |
| 36 | toast.error("Failed to fetch metadata"); |
| 37 | } |
| 38 | } catch (error) { |
| 39 | console.error("Error scraping URL:", error); |
| 40 | toast.error("Failed to scrape URL"); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | return ( |
| 45 | <div className="space-y-4"> |
| 46 | <div> |
| 47 | <h2 className="text-2xl font-bold">URL Scraper</h2> |
| 48 | <p className="text-muted-foreground"> |
| 49 | Enter a URL to scrape its content and metadata. |
| 50 | </p> |
| 51 | </div> |
| 52 | |
| 53 | <form onSubmit={handleSubmit} className="space-y-6"> |
| 54 | <div className="space-y-2"> |
| 55 | <Label htmlFor="url">URL to scrape</Label> |
| 56 | <Input |
| 57 | type="url" |
| 58 | name="url" |
| 59 | id="url" |
| 60 | required |
| 61 | placeholder="https://example.com" |
| 62 | value={url} |
| 63 | onChange={(e) => setUrl(e.target.value)} |
| 64 | /> |
| 65 | </div> |
| 66 | |
| 67 | <Button type="submit" className="w-full"> |
| 68 | Scrape URL |
| 69 | </Button> |
nothing calls this directly
no outgoing calls
no test coverage detected