4285 |
stevensc |
1 |
/* eslint-disable react/prop-types */
|
|
|
2 |
/* eslint-disable react/display-name */
|
|
|
3 |
import React, { useState } from "react"
|
|
|
4 |
import { useDispatch } from "react-redux"
|
|
|
5 |
import { EmailIcon, EmailShareButton, FacebookIcon, FacebookShareButton, RedditIcon, RedditShareButton, TelegramIcon, TelegramShareButton, TwitterIcon, TwitterShareButton, WhatsappIcon, WhatsappShareButton } from "react-share"
|
|
|
6 |
import { addNotification } from "../../../../redux/notification/notification.actions"
|
|
|
7 |
import { axios } from "../../../../utils"
|
|
|
8 |
|
|
|
9 |
export default function withReactionList(Component, url, props) {
|
|
|
10 |
return function () {
|
|
|
11 |
const dispatch = useDispatch()
|
|
|
12 |
const [shareOptions, setShareOptions] = useState(false)
|
|
|
13 |
const [shareUrl, setShareUrl] = useState('');
|
|
|
14 |
|
|
|
15 |
const handleDisplayReactionList = () => setShareOptions(!shareOptions)
|
|
|
16 |
|
|
|
17 |
const getShareUrl = new Promise((resolve, reject) => {
|
|
|
18 |
if (shareOptions) {
|
|
|
19 |
axios.get(url)
|
|
|
20 |
.then(({ data }) => {
|
|
|
21 |
if (!data.success) {
|
|
|
22 |
dispatch(addNotification({ style: 'danger', msg: data.data }))
|
|
|
23 |
setShareOptions(false)
|
|
|
24 |
return reject(data.data)
|
|
|
25 |
}
|
|
|
26 |
setShareUrl(data.data)
|
|
|
27 |
return resolve(data.data)
|
|
|
28 |
})
|
|
|
29 |
.catch((err) => reject(err))
|
|
|
30 |
}
|
|
|
31 |
});
|
|
|
32 |
|
|
|
33 |
return (
|
|
|
34 |
<div className="position-relative" onClick={handleDisplayReactionList}>
|
|
|
35 |
<Component Icon={props.icon} title={props.title} color={props.color} />
|
|
|
36 |
{shareOptions &&
|
|
|
37 |
<div className="ext_share" >
|
|
|
38 |
<FacebookShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
39 |
<FacebookIcon size={32} round />
|
|
|
40 |
</FacebookShareButton>
|
|
|
41 |
<TwitterShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
42 |
<TwitterIcon size={32} round />
|
|
|
43 |
</TwitterShareButton>
|
|
|
44 |
<TelegramShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
45 |
<TelegramIcon size={32} round />
|
|
|
46 |
</TelegramShareButton>
|
|
|
47 |
<WhatsappShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
48 |
<WhatsappIcon size={32} round />
|
|
|
49 |
</WhatsappShareButton>
|
|
|
50 |
<RedditShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
51 |
<RedditIcon size={32} round />
|
|
|
52 |
</RedditShareButton>
|
|
|
53 |
<EmailShareButton beforeOnClick={() => getShareUrl} url={shareUrl}>
|
|
|
54 |
<EmailIcon size={32} round />
|
|
|
55 |
</EmailShareButton>
|
|
|
56 |
</div>
|
|
|
57 |
}
|
|
|
58 |
</div>
|
|
|
59 |
)
|
|
|
60 |
}
|
|
|
61 |
}
|