@@ -19,9 +19,10 @@ import {
1919 FaReddit ,
2020 FaShareAlt ,
2121} from 'react-icons/fa' ;
22- import { FaHandshake } from 'react-icons/fa' ;
22+ import { FaHandshake , FaCopy , FaTimes } from 'react-icons/fa' ;
2323import { FaXTwitter , FaLocationDot } from 'react-icons/fa6' ;
2424import { SiLeetcode , SiCodeforces , SiHashnode , SiReplit , SiHackerrank } from 'react-icons/si' ;
25+ import './ProfileShareTooltip.css' ;
2526
2627const UnstopIcon = ( ) => (
2728 < svg width = "24" height = "24" viewBox = "0 0 225 225" xmlns = "http://www.w3.org/2000/svg" >
@@ -53,17 +54,17 @@ function Profile({ data }) {
5354function Card ( { data } ) {
5455 const cardRef = React . useRef ( ) ;
5556 const [ showFallback , setShowFallback ] = React . useState ( false ) ;
57+ const [ showTooltip , setShowTooltip ] = React . useState ( false ) ;
58+ const shareBtnRef = React . useRef ( ) ;
5659
5760 const handleWheel = ( event ) => {
5861 event . stopPropagation ( ) ;
5962 event . preventDefault ( ) ;
6063 let container = event . target ;
6164 if ( ! container ) return false ;
62-
6365 while ( ! container . classList . contains ( 'skills-container' ) ) {
6466 container = container . parentNode ;
6567 }
66-
6768 const delta = event . deltaX || event . deltaY ;
6869 container . scrollLeft += delta ;
6970 } ;
@@ -72,6 +73,41 @@ function Card({ data }) {
7273 cardRef . current . addEventListener ( 'wheel' , handleWheel , { passive : false } ) ;
7374 } , [ ] ) ;
7475
76+ React . useEffect ( ( ) => {
77+ if ( ! showTooltip ) return ;
78+ function handleClickOutside ( e ) {
79+ if (
80+ shareBtnRef . current &&
81+ ! shareBtnRef . current . contains ( e . target )
82+ ) {
83+ setShowTooltip ( false ) ;
84+ }
85+ }
86+ document . addEventListener ( 'mousedown' , handleClickOutside ) ;
87+ return ( ) => {
88+ document . removeEventListener ( 'mousedown' , handleClickOutside ) ;
89+ } ;
90+ } , [ showTooltip ] ) ;
91+
92+ const profileFileName = data . fileName . replace ( '.json' , '' ) ;
93+ const shareUrl = `https://www.devdisplay.org/profile/${ profileFileName } ` ;
94+
95+ // Tooltip share actions
96+ const handleShareX = ( ) => {
97+ const caption = encodeURIComponent ( `🚀 Check out my DevDisplay profile! #DevDisplay\n${ shareUrl } ` ) ;
98+ window . open ( `https://x.com/intent/tweet?text=${ caption } ` , '_blank' ) ;
99+ setShowTooltip ( false ) ;
100+ } ;
101+ const handleShareLinkedIn = ( ) => {
102+ const caption = encodeURIComponent ( `Check out my DevDisplay profile!\n${ shareUrl } ` ) ;
103+ window . open ( `https://www.linkedin.com/sharing/share-offsite/?url=${ shareUrl } &summary=${ caption } ` , '_blank' ) ;
104+ setShowTooltip ( false ) ;
105+ } ;
106+ const handleCopy = ( ) => {
107+ navigator . clipboard . writeText ( shareUrl ) ;
108+ setShowTooltip ( false ) ;
109+ alert ( `URL copied to clipboard: ${ shareUrl } ` ) ;
110+ } ;
75111 return (
76112 < div className = "mb-6 h-auto rounded-lg bg-white p-4 shadow dark:bg-textPrimary" >
77113 < div className = "relative flex gap-4" >
@@ -154,28 +190,31 @@ function Card({ data }) {
154190 </ div >
155191 </ div >
156192 < div className = "flex items-center justify-end md:absolute md:right-0 md:top-0" >
157- < FaShareAlt
158- className = "mr-4 cursor-pointer text-xl text-blue-600 duration-300 hover:scale-125"
159- onClick = { ( e ) => {
160- const profileFileName = data . fileName . replace ( '.json' , '' ) ;
161- const shareUrl = `https://www.devdisplay.org/profile/${ profileFileName } ` ;
162- console . log ( 'Share URL:' , shareUrl ) ; // Log the share URL
163-
164- if ( navigator . share ) {
165- navigator
166- . share ( {
167- title : 'Check out this profile!' ,
168- text : 'Check out my DevDisplay profile!' ,
169- url : shareUrl ,
170- } )
171- . then ( ( ) => console . log ( 'Successful share' ) )
172- . catch ( ( error ) => console . log ( 'Error sharing' , error ) ) ;
173- } else {
174- navigator . clipboard . writeText ( shareUrl ) ;
175- alert ( `URL copied to clipboard: ${ shareUrl } ` ) ;
176- }
177- } }
178- />
193+ < div className = "relative" ref = { shareBtnRef } >
194+ < FaShareAlt
195+ className = "mr-4 cursor-pointer text-xl text-blue-600 duration-300 hover:scale-125"
196+ onClick = { ( ) => setShowTooltip ( true ) }
197+ />
198+ { showTooltip && (
199+ < div className = "profile-share-tooltip" >
200+ < button className = "profile-share-close" onClick = { ( ) => setShowTooltip ( false ) } >
201+ < FaTimes />
202+ </ button >
203+ < div className = "profile-share-row" onClick = { handleShareX } >
204+ < FaXTwitter className = "text-xl" />
205+ < span > Share on X</ span >
206+ </ div >
207+ < div className = "profile-share-row" onClick = { handleShareLinkedIn } >
208+ < FaLinkedin className = "text-xl" />
209+ < span > Share on LinkedIn</ span >
210+ </ div >
211+ < div className = "profile-share-row" onClick = { handleCopy } >
212+ < FaCopy className = "text-xl" />
213+ < span > Copy Link</ span >
214+ </ div >
215+ </ div >
216+ ) }
217+ </ div >
179218 < a
180219 href = { data . portfolio }
181220 className = { `flex w-28 items-center gap-2 ${
0 commit comments