1- import React , { useRef , useEffect , useState } from 'react' ;
2- import { FiShare2 } from 'react-icons/fi' ;
1+ import React , { useRef , useEffect } from 'react' ;
32
43const DEFAULT_HASHTAGS = [ ] ;
54const DEFAULT_PLATFORMS = [ 'whatsapp' , 'facebook' , 'twitter' , 'linkedin' , 'telegram' , 'reddit' , 'pinterest' ] ;
@@ -16,7 +15,6 @@ const SocialShareButton = ({
1615 buttonText = 'Share' ,
1716 customClass = '' ,
1817 onShare = null ,
19- onCopy = null ,
2018 buttonStyle = 'default' ,
2119 modalPosition = 'center' ,
2220 buttonColor = '' ,
@@ -30,41 +28,35 @@ const SocialShareButton = ({
3028} ) => {
3129 const containerRef = useRef ( null ) ;
3230 const shareButtonRef = useRef ( null ) ;
33- const [ loadError , setLoadError ] = useState ( false ) ;
3431
3532 useEffect ( ( ) => {
36- if ( typeof window !== 'undefined' ) {
37- if ( window . SocialShareButton ) {
38- setLoadError ( false ) ;
39- shareButtonRef . current = new window . SocialShareButton ( {
40- container : containerRef . current ,
41- url : url || 'https://orgexplorer.aossie.org/' ,
42- title : title || document . title ,
43- description,
44- hashtags,
45- via,
46- platforms,
47- theme,
48- buttonText,
49- customClass,
50- onShare,
51- onCopy,
52- buttonStyle,
53- modalPosition,
54- buttonColor,
55- buttonHoverColor,
56- showButton,
57- analytics,
58- onAnalytics,
59- analyticsPlugins,
60- componentId,
61- debug,
62- } ) ;
63- } else {
64- setLoadError ( true ) ;
65- }
33+ if ( typeof window !== 'undefined' && window . SocialShareButton ) {
34+ shareButtonRef . current = new window . SocialShareButton ( {
35+ container : containerRef . current ,
36+ url : url || 'https://orgexplorer.aossie.org/' ,
37+ title : title || document . title ,
38+ description,
39+ hashtags,
40+ via,
41+ platforms,
42+ theme,
43+ buttonText,
44+ customClass,
45+ onShare,
46+ buttonStyle,
47+ modalPosition,
48+ buttonColor,
49+ buttonHoverColor,
50+ showButton,
51+ analytics,
52+ onAnalytics,
53+ analyticsPlugins,
54+ componentId,
55+ debug,
56+ } ) ;
57+ } else {
58+ console . warn ( 'SocialShareButton widget not loaded' ) ;
6659 }
67-
6860 return ( ) => {
6961 if ( shareButtonRef . current ) {
7062 shareButtonRef . current . destroy ( ) ;
@@ -73,43 +65,11 @@ const SocialShareButton = ({
7365 } ;
7466 } , [
7567 url , title , description , hashtags , via , platforms , theme , buttonText ,
76- customClass , onShare , onCopy , buttonStyle , modalPosition , buttonColor ,
68+ customClass , onShare , buttonStyle , modalPosition , buttonColor ,
7769 buttonHoverColor , showButton , analytics , onAnalytics , analyticsPlugins ,
78- componentId , debug
70+ componentId , debug ,
7971 ] ) ;
8072
81- if ( loadError ) {
82- const handleFallbackCopy = async ( ) => {
83- try {
84- if ( onCopy ) {
85- await onCopy ( ) ;
86- } else {
87- const fallbackUrl = url || 'https://orgexplorer.aossie.org/' ;
88- if ( navigator . clipboard && navigator . clipboard . writeText ) {
89- await navigator . clipboard . writeText ( fallbackUrl ) ;
90- } else {
91- throw new Error ( "Clipboard API not available" ) ;
92- }
93- }
94- alert ( "Widget failed to load. Link copied to clipboard!" ) ;
95- } catch ( err ) {
96- console . error ( "Failed to copy link: " , err ) ;
97- alert ( "Widget failed to load. Failed to copy link." ) ;
98- }
99- } ;
100-
101- return (
102- < button
103- type = "button"
104- onClick = { handleFallbackCopy }
105- style = { { display : 'flex' , alignItems : 'center' , gap : 6 , fontSize : 12 , border : '1px solid #ef4444' , padding : '6px 12px' , borderRadius : '6px' , background : 'transparent' , color : 'inherit' , cursor : 'pointer' } }
106- title = "Social Share widget failed to load. Click to copy link."
107- >
108- < FiShare2 size = { 13 } /> { buttonText } (Fallback)
109- </ button >
110- ) ;
111- }
112-
11373 return < div ref = { containerRef } > </ div > ;
11474} ;
11575
0 commit comments