| 4309 |
stevensc |
1 |
/* eslint-disable react/display-name */
|
| 4802 |
stevensc |
2 |
import React, { useEffect, useState } from "react"
|
| 4309 |
stevensc |
3 |
import { useDispatch } from "react-redux"
|
|
|
4 |
import { EmailIcon, EmailShareButton, FacebookIcon, FacebookShareButton, RedditIcon, RedditShareButton, TelegramIcon, TelegramShareButton, TwitterIcon, TwitterShareButton, WhatsappIcon, WhatsappShareButton } from "react-share"
|
|
|
5 |
import { addNotification } from "../../../../redux/notification/notification.actions"
|
|
|
6 |
import { axios } from "../../../../utils"
|
|
|
7 |
|
| 4802 |
stevensc |
8 |
export default function withExternalShare(Component, url, params, countUrl, setValue) {
|
| 4309 |
stevensc |
9 |
return function () {
|
|
|
10 |
const dispatch = useDispatch()
|
|
|
11 |
const [shareOptions, setShareOptions] = useState(false)
|
|
|
12 |
const [shareUrl, setShareUrl] = useState('');
|
|
|
13 |
|
|
|
14 |
const handleDisplayReactionList = () => setShareOptions(!shareOptions)
|
|
|
15 |
|
| 4802 |
stevensc |
16 |
const getShareUrl = async () => {
|
| 4798 |
stevensc |
17 |
await axios.get(url)
|
|
|
18 |
.then(({ data }) => {
|
|
|
19 |
if (!data.success) {
|
|
|
20 |
dispatch(addNotification({ style: 'danger', msg: data.data }))
|
|
|
21 |
setShareOptions(false)
|
|
|
22 |
return
|
|
|
23 |
}
|
| 4792 |
stevensc |
24 |
|
| 4798 |
stevensc |
25 |
setShareUrl(data.data)
|
|
|
26 |
})
|
|
|
27 |
.catch((err) => console.log(err))
|
|
|
28 |
}
|
| 4309 |
stevensc |
29 |
|
| 4802 |
stevensc |
30 |
const incrementCount = async () => {
|
|
|
31 |
await axios.post(countUrl)
|
|
|
32 |
.then(({ data }) => {
|
|
|
33 |
if (!data.success) {
|
|
|
34 |
dispatch(addNotification({ style: 'danger', msg: data.data }))
|
|
|
35 |
return
|
|
|
36 |
}
|
| 4801 |
stevensc |
37 |
|
| 4802 |
stevensc |
38 |
setShareOptions(false)
|
|
|
39 |
setValue(data.data)
|
|
|
40 |
})
|
|
|
41 |
.catch((err) => console.log(err))
|
|
|
42 |
}
|
| 4792 |
stevensc |
43 |
|
| 4802 |
stevensc |
44 |
useEffect(() => {
|
|
|
45 |
if (!shareOptions && !shareUrl) getShareUrl()
|
|
|
46 |
}, [setShareOptions])
|
|
|
47 |
|
| 4309 |
stevensc |
48 |
return (
|
| 4626 |
stevensc |
49 |
<div className="position-relative d-inline-flex" onClick={handleDisplayReactionList} style={{ flexGrow: 1 }}>
|
| 4309 |
stevensc |
50 |
<Component {...params} />
|
|
|
51 |
{shareOptions &&
|
|
|
52 |
<div className="external__share" >
|
| 4802 |
stevensc |
53 |
<FacebookShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
54 |
<FacebookIcon size={32} round />
|
|
|
55 |
</FacebookShareButton>
|
| 4802 |
stevensc |
56 |
<TwitterShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
57 |
<TwitterIcon size={32} round />
|
|
|
58 |
</TwitterShareButton>
|
| 4802 |
stevensc |
59 |
<TelegramShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
60 |
<TelegramIcon size={32} round />
|
|
|
61 |
</TelegramShareButton>
|
| 4802 |
stevensc |
62 |
<WhatsappShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
63 |
<WhatsappIcon size={32} round />
|
|
|
64 |
</WhatsappShareButton>
|
| 4802 |
stevensc |
65 |
<RedditShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
66 |
<RedditIcon size={32} round />
|
|
|
67 |
</RedditShareButton>
|
| 4802 |
stevensc |
68 |
<EmailShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
|
| 4309 |
stevensc |
69 |
<EmailIcon size={32} round />
|
|
|
70 |
</EmailShareButton>
|
|
|
71 |
</div>
|
|
|
72 |
}
|
|
|
73 |
</div>
|
|
|
74 |
)
|
|
|
75 |
}
|
|
|
76 |
}
|