From 9a6ec13a8fdeb54d2967895a430aa0ce3071565d Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Sat, 21 Sep 2024 22:07:02 +0200 Subject: Add basic share link button --- app/page.tsx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/page.tsx b/app/page.tsx index 785ca18..54454cb 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -7,6 +7,7 @@ export default function Cidr() { const [ip, setIp] = useState([10, 88, 135, 144]); const [cidr, setCidr] = useState(28); const [cols] = useState(["bg-purple-400", "bg-red-400", "bg-green-400", "bg-yellow-400", "bg-slate-300"]); + const [isShared, setIsShared] = useState(false); const bits = ip.map(octet => Array.from({ length: 8 }, (_, i) => (octet >> (7 - i)) & 1)); @@ -63,6 +64,18 @@ export default function Cidr() { } } + const handleShare = async () => { + try { + let frag = "#" + ip.join(".") + "/" + cidr; + window.location.hash = frag; + await navigator.clipboard.writeText("foo"); + setIsShared(true); + setTimeout(() => setIsShared(false), 2000); + } catch (err) { + console.error('Failed to share CIDR link: ', err); + } + }; + useEffect(() => { const fragment = window.location.hash.slice(1); console.log(fragment); @@ -144,7 +157,7 @@ export default function Cidr() { /> -
+
{bits.map((octet, i) => {octet.map((bit, j) => {bit})} )} @@ -158,6 +171,16 @@ export default function Cidr() {
) }
+ +
+ +
+ -- cgit v1.3.1