mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-04-24 06:57:10 -05:00
Implement Share button in HackOptionsMenu
This commit is contained in:
parent
2bb33483ff
commit
8609ab451a
|
|
@ -1,7 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import React from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { FiMoreVertical } from "react-icons/fi";
|
||||
import { Menu, MenuButton, MenuItem, MenuItems, MenuSeparator } from "@headlessui/react";
|
||||
|
||||
|
|
@ -11,8 +10,6 @@ interface HackOptionsMenuProps {
|
|||
}
|
||||
|
||||
export default function HackOptionsMenu({ slug, canEdit }: HackOptionsMenuProps) {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<Menu as="div" className="relative">
|
||||
<MenuButton
|
||||
|
|
@ -29,8 +26,24 @@ export default function HackOptionsMenu({ slug, canEdit }: HackOptionsMenuProps)
|
|||
>
|
||||
<MenuItem
|
||||
as="button"
|
||||
onClick={() => {
|
||||
// TODO: Implement share
|
||||
onClick={async () => {
|
||||
try {
|
||||
const url = window.location.href;
|
||||
const title = document?.title || "Check this out";
|
||||
if (navigator.share) {
|
||||
await navigator.share({ title, url });
|
||||
} else {
|
||||
if (navigator.clipboard?.writeText) {
|
||||
await navigator.clipboard.writeText(url);
|
||||
alert("Link copied to clipboard");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore if user cancels share; otherwise log
|
||||
if (!(e instanceof Error) || e.name !== "AbortError") {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}}
|
||||
className="block w-full px-3 py-2 text-left text-sm data-focus:bg-black/5 dark:data-focus:bg-white/10">
|
||||
Share
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user