11"use client" ;
22import React , { useEffect , useState } from "react" ;
3- import { Dialog , DialogContent , DialogDescription , DialogHeader , DialogTitle , DialogTrigger } from "./ui/dialog" ;
3+ import {
4+ Dialog ,
5+ DialogContent ,
6+ DialogDescription ,
7+ DialogHeader ,
8+ DialogTitle ,
9+ DialogTrigger ,
10+ } from "./ui/dialog" ;
411import { Copy } from "lucide-react" ;
512import toast from "react-hot-toast" ;
613import { FaShare } from "react-icons/fa" ;
@@ -9,50 +16,53 @@ import { Button } from "./ui/button";
916import { usePathname } from "next/navigation" ;
1017
1118export default function ShareButton ( ) {
12- const [ origin , setOrigin ] = useState ( "" ) ;
19+ const [ origin , setOrigin ] = useState ( "" ) ;
1320
14- useEffect ( ( ) => {
15- if ( typeof window !== "undefined" ) {
16- setOrigin ( window . location . origin ) ;
17- }
18- } , [ ] ) ;
19-
20- const pathname = usePathname ( ) ;
21- const paperPath = origin + pathname ;
21+ useEffect ( ( ) => {
22+ if ( typeof window !== "undefined" ) {
23+ setOrigin ( window . location . origin ) ;
24+ }
25+ } , [ ] ) ;
26+
27+ const pathname = usePathname ( ) ;
28+ const paperPath = origin + pathname ;
2229 return (
23- < Dialog >
24- < DialogTrigger >
25- < FaShare > </ FaShare >
26- </ DialogTrigger >
27- < DialogContent className = "max-w-96" >
28- < DialogHeader >
29- < DialogTitle > Share Papers with your friends!</ DialogTitle >
30- < DialogDescription >
31- Either scan the QR or copy the link and share
32- </ DialogDescription >
33- </ DialogHeader >
34- < div className = "flex flex-col items-center justify-center gap-5" >
35- < QR url = { paperPath } > </ QR >
36- < Button
37- type = "submit"
38- size = "sm"
39- className = "flex w-fit items-center justify-between gap-5 px-3"
40- onClick = { async ( ) => {
41- await toast . promise (
42- navigator . clipboard . writeText ( paperPath ) , // This is a promise
43- {
44- success : "Link copied successfully" ,
45- loading : "Copying link..." ,
46- error : "Error copying link" ,
47- } ,
48- ) ;
49- } }
50- >
51- < p > Copy Link To Clipboard</ p >
52- < Copy />
53- </ Button >
54- </ div >
55- </ DialogContent >
56- </ Dialog >
30+ < Dialog >
31+ < DialogTrigger asChild >
32+ < Button >
33+ { " " }
34+ < FaShare />
35+ </ Button >
36+ </ DialogTrigger >
37+ < DialogContent className = "max-w-96" >
38+ < DialogHeader >
39+ < DialogTitle > Share Papers with your friends!</ DialogTitle >
40+ < DialogDescription >
41+ Either scan the QR or copy the link and share
42+ </ DialogDescription >
43+ </ DialogHeader >
44+ < div className = "flex flex-col items-center justify-center gap-5" >
45+ < QR url = { paperPath } > </ QR >
46+ < Button
47+ type = "submit"
48+ size = "sm"
49+ className = "flex w-fit items-center justify-between gap-5 px-3"
50+ onClick = { async ( ) => {
51+ await toast . promise (
52+ navigator . clipboard . writeText ( paperPath ) , // This is a promise
53+ {
54+ success : "Link copied successfully" ,
55+ loading : "Copying link..." ,
56+ error : "Error copying link" ,
57+ } ,
58+ ) ;
59+ } }
60+ >
61+ < p > Copy Link To Clipboard</ p >
62+ < Copy />
63+ </ Button >
64+ </ div >
65+ </ DialogContent >
66+ </ Dialog >
5767 ) ;
5868}
0 commit comments