'use client'; import { useState } from "react"; import { shortenLink } from "./utils/shortenLink"; import { Clipboard, Minimize2 } from "lucide-react"; export default function Home() { const [errorMessage, setErrorMessage] = useState(null); const [successMessage, setSuccessMessage] = useState(null); const [shortUrl, setShortUrl] = useState(null); const [manageUrl, setManageUrl] = useState(null); async function handleSubmit(event: React.FormEvent) { event.preventDefault(); try { const formData = new FormData(event.currentTarget); const longUrl = formData.get("longUrl") as string; const res = await shortenLink(longUrl); setSuccessMessage("Shortened URL!"); setErrorMessage(null); setShortUrl(res.shortUrl); setManageUrl(res.manageUrl); } catch (err) { console.error(err); setErrorMessage("Failed to shorten the link. Please try again."); setSuccessMessage(null); } } function copyToClipboard(text: string, title: string) { navigator.clipboard.writeText(text).then( () => { setSuccessMessage(`Copied ${title} to clipboard!`); }, () => { setErrorMessage(`Failed to copy ${title} to clipboard.`); } ); } return (

halflink

Shorten a link with ease.

{errorMessage && (

{errorMessage}

)} {successMessage && (

{successMessage}

)} {shortUrl && manageUrl && (

Shareable short link:

View analytics and manage your short link at:

)}
); }