-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathShareButton.tsx
More file actions
68 lines (64 loc) · 1.87 KB
/
ShareButton.tsx
File metadata and controls
68 lines (64 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use client";
import React, { useEffect, useState } from "react";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "./ui/dialog";
import { Copy } from "lucide-react";
import toast from "react-hot-toast";
import { FaShare } from "react-icons/fa";
import QR from "./qr";
import { Button } from "./ui/button";
import { usePathname } from "next/navigation";
export default function ShareButton() {
const [origin, setOrigin] = useState("");
useEffect(() => {
if (typeof window !== "undefined") {
setOrigin(window.location.origin);
}
}, []);
const pathname = usePathname();
const paperPath = origin + pathname;
return (
<Dialog>
<DialogTrigger>
<Button className="aspect-square h-10 w-10 p-0">
<FaShare />
</Button>
</DialogTrigger>
<DialogContent className="max-w-96">
<DialogHeader>
<DialogTitle>Share Papers with your friends!</DialogTitle>
<DialogDescription>
Either scan the QR or copy the link and share
</DialogDescription>
</DialogHeader>
<div className="flex flex-col items-center justify-center gap-5">
<QR url={paperPath}></QR>
<Button
type="submit"
size="sm"
className="flex w-fit items-center justify-between gap-5 px-3"
onClick={async () => {
await toast.promise(
navigator.clipboard.writeText(paperPath), // This is a promise
{
success: "Link copied successfully",
loading: "Copying link...",
error: "Error copying link",
},
);
}}
>
<p>Copy Link To Clipboard</p>
<Copy />
</Button>
</div>
</DialogContent>
</Dialog>
);
}