diff --git a/frontend/app/page.js b/frontend/app/page.js index a30cf6f..46def5e 100644 --- a/frontend/app/page.js +++ b/frontend/app/page.js @@ -3,12 +3,14 @@ import { useState } from "react"; import axios from "axios"; import dotenv from "dotenv"; +import { MdContentCopy } from "react-icons/md"; dotenv.config({ path: "./.env.local" }); export default function Home() { const [longUrl, setLongUrl] = useState(""); const [shortUrl, setShortUrl] = useState(""); + const [copied, setCopied] = useState(false); const handleSubmit = async (e) => { e.preventDefault(); @@ -31,11 +33,23 @@ export default function Home() { } }; + const handleCopy = () => { + navigator.clipboard + .writeText(shortUrl) + .then(() => { + setCopied(true); + setTimeout(() => setCopied(false), 2000); // Reset copy state after 2 seconds + }) + .catch((error) => { + console.error("Failed to copy URL:", error); + }); + }; + return (
- Short URL:{" "} - - {shortUrl} - -
+