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 (

- URL Shortener + Reduce

- Shorten + Reduce
{shortUrl && ( -

- Short URL:{" "} - - {shortUrl} - -

+
+
+ + {shortUrl} + + +
+
)}
diff --git a/frontend/package.json b/frontend/package.json index 2eaeb2b..fc14057 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -13,7 +13,8 @@ "dotenv": "^16.4.5", "next": "14.2.5", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "react-icons": "^5.2.1" }, "devDependencies": { "postcss": "^8",