"use client"; import { useState } from "react"; import axios from "axios"; import { MdContentCopy } from "react-icons/md"; import Link from "next/link"; import QRCode from "react-qr-code"; export default function Home() { const [longUrl, setLongUrl] = useState(""); const [shortUrl, setShortUrl] = useState(""); const [copied, setCopied] = useState(false); const [prevLongUrl, setPrevLongUrl] = useState(""); const handleSubmit = async (e) => { e.preventDefault(); if (longUrl === prevLongUrl && shortUrl) { return; } const baseURL = window.location.origin; try { const response = await axios.post( `${process.env.NEXT_PUBLIC_BACKEND_URL}/reduce/shorten`, { long_url: longUrl, base_url: baseURL, }, ); setShortUrl(response.data.short_url); setPrevLongUrl(longUrl); } catch (error) { console.error("Error shortening URL:", error); } }; const handleCopy = () => { navigator.clipboard.writeText(shortUrl); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return ( <>

Reduce

setLongUrl(e.target.value)} className="border border-gray-300 bg-inherit rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" />
{shortUrl && (
{shortUrl}
)}
); }