Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 2244 | Rev 2246 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 2244 Rev 2245
Línea 14... Línea 14...
14
  WhatsappIcon,
14
  WhatsappIcon,
15
  WhatsappShareButton
15
  WhatsappShareButton
16
} from 'react-share'
16
} from 'react-share'
17
import { addNotification } from 'store/notification/notification.actions'
17
import { addNotification } from 'store/notification/notification.actions'
18
import { axios } from '../../../utils'
18
import { axios } from '../../../utils'
-
 
19
import SharePopup from './mobile-share/MobileSharePopUp'
-
 
20
 
19
import styled from 'styled-components'
21
import styled from 'styled-components'
-
 
22
import useMobile from '@app/hooks/useMobile'
Línea 20... Línea 23...
20
 
23
 
21
const StyledShareContainer = styled.div`
24
const StyledShareContainer = styled.div`
22
  display: flex;
25
  display: flex;
23
  position: absolute;
26
  position: absolute;
Línea 34... Línea 37...
34
`
37
`
Línea 35... Línea 38...
35
 
38
 
36
export default function withExternalShare(Component, url) {
39
export default function withExternalShare(Component, url) {
37
  return function ({ children, setValue, shorterUrl }) {
40
  return function ({ children, setValue, shorterUrl }) {
-
 
41
    const [showOptions, setShowOptions] = useState(false)
38
    const [showOptions, setShowOptions] = useState(false)
42
    const [openPopup, setOpenPopup] = useState(false)
-
 
43
    const [shareUrl, setShareUrl] = useState('')
39
    const [shareUrl, setShareUrl] = useState('')
44
    const isMobile = useMobile()
Línea 40... Línea 45...
40
    const dispatch = useDispatch()
45
    const dispatch = useDispatch()
Línea 41... Línea 46...
41
 
46
 
42
    const toggleShareOptions = () => setShowOptions(!showOptions)
47
    const onClick = () => setShowOptions(!showOptions)
43
 
48
 
44
    const incrementCount = async () => {
49
    const incrementCount = async () => {
Línea 53... Línea 58...
53
        .catch((err) =>
58
        .catch((err) =>
54
          dispatch(addNotification({ style: 'danger', msg: err.message }))
59
          dispatch(addNotification({ style: 'danger', msg: err.message }))
55
        )
60
        )
56
    }
61
    }
Línea -... Línea 62...
-
 
62
 
-
 
63
    const mobileOnClick = async () => {
-
 
64
      if (navigator?.share) {
-
 
65
        try {
-
 
66
          await navigator.share({ url: shareUrl })
-
 
67
          incrementCount()
-
 
68
        } catch (error) {
-
 
69
          dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
70
        }
-
 
71
      } else if (window?.AndroidShareHandler) {
-
 
72
        try {
-
 
73
          window.AndroidShareHandler.share(shareUrl)
-
 
74
        } catch (error) {
-
 
75
          dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
76
        }
-
 
77
      } else {
-
 
78
        setOpenPopup(true)
-
 
79
      }
-
 
80
    }
57
 
81
 
58
    useEffect(() => {
82
    useEffect(() => {
Línea 59... Línea 83...
59
      if (!showOptions || shareUrl) return
83
      if (!showOptions || shareUrl) return
60
 
84
 
Línea 71... Línea 95...
71
 
95
 
72
      getShareUrl()
96
      getShareUrl()
Línea 73... Línea 97...
73
    }, [showOptions, shareUrl])
97
    }, [showOptions, shareUrl])
-
 
98
 
74
 
99
    return (
75
    return (
100
      <>
76
      <Component onClick={toggleShareOptions}>
101
        <Component onClick={isMobile ? mobileOnClick : onClick}>
77
        {children}
102
          {children}
78
 
103
 
79
        {showOptions && (
104
          {showOptions && (
80
          <StyledShareContainer>
105
            <StyledShareContainer>
81
            <FacebookShareButton
106
              <FacebookShareButton
82
              url={shareUrl}
107
                url={shareUrl}
83
              onShareWindowClose={incrementCount}
108
                onShareWindowClose={incrementCount}
84
              disabled={!shareUrl}
109
                disabled={!shareUrl}
85
            >
110
              >
86
              <FacebookIcon size={32} round />
111
                <FacebookIcon size={32} round />
87
            </FacebookShareButton>
112
              </FacebookShareButton>
88
            <TwitterShareButton
113
              <TwitterShareButton
89
              url={shareUrl}
114
                url={shareUrl}
90
              onShareWindowClose={incrementCount}
115
                onShareWindowClose={incrementCount}
91
              disabled={!shareUrl}
116
                disabled={!shareUrl}
92
            >
117
              >
93
              <TwitterIcon size={32} round />
118
                <TwitterIcon size={32} round />
94
            </TwitterShareButton>
119
              </TwitterShareButton>
95
            <TelegramShareButton
120
              <TelegramShareButton
96
              url={shareUrl}
121
                url={shareUrl}
97
              onShareWindowClose={incrementCount}
122
                onShareWindowClose={incrementCount}
98
              disabled={!shareUrl}
123
                disabled={!shareUrl}
99
            >
124
              >
100
              <TelegramIcon size={32} round />
125
                <TelegramIcon size={32} round />
101
            </TelegramShareButton>
126
              </TelegramShareButton>
102
            <WhatsappShareButton
127
              <WhatsappShareButton
103
              url={shareUrl}
128
                url={shareUrl}
104
              onShareWindowClose={incrementCount}
129
                onShareWindowClose={incrementCount}
105
              disabled={!shareUrl}
130
                disabled={!shareUrl}
106
            >
131
              >
107
              <WhatsappIcon size={32} round />
132
                <WhatsappIcon size={32} round />
108
            </WhatsappShareButton>
133
              </WhatsappShareButton>
109
            <RedditShareButton
134
              <RedditShareButton
110
              url={shareUrl}
135
                url={shareUrl}
111
              onShareWindowClose={incrementCount}
136
                onShareWindowClose={incrementCount}
112
              disabled={!shareUrl}
137
                disabled={!shareUrl}
113
            >
138
              >
114
              <RedditIcon size={32} round />
139
                <RedditIcon size={32} round />
115
            </RedditShareButton>
140
              </RedditShareButton>
116
            <EmailShareButton
141
              <EmailShareButton
117
              url={shareUrl}
142
                url={shareUrl}
118
              onShareWindowClose={incrementCount}
143
                onShareWindowClose={incrementCount}
119
              disabled={!shareUrl}
144
                disabled={!shareUrl}
120
            >
145
              >
121
              <EmailIcon size={32} round />
146
                <EmailIcon size={32} round />
122
            </EmailShareButton>
147
              </EmailShareButton>
123
          </StyledShareContainer>
148
            </StyledShareContainer>
-
 
149
          )}
-
 
150
        </Component>
-
 
151
        <SharePopup
-
 
152
          show={openPopup}
-
 
153
          shareData={{ url: shareUrl }}
-
 
154
          onClose={() => setOpenPopup(false)}
124
        )}
155
        />
125
      </Component>
156
      </>
126
    )
157
    )