Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4806 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 4806 Rev 6018
Línea 1... Línea 1...
1
/* eslint-disable react/display-name */
1
/* eslint-disable react/display-name */
2
import React, { useEffect, useState } from "react"
2
import React, { useEffect, useState } from 'react'
3
import { useDispatch } from "react-redux"
3
import { useDispatch } from 'react-redux'
4
import { EmailIcon, EmailShareButton, FacebookIcon, FacebookShareButton, RedditIcon, RedditShareButton, TelegramIcon, TelegramShareButton, TwitterIcon, TwitterShareButton, WhatsappIcon, WhatsappShareButton } from "react-share"
-
 
-
 
4
import {
-
 
5
  EmailIcon,
-
 
6
  EmailShareButton,
-
 
7
  FacebookIcon,
-
 
8
  FacebookShareButton,
-
 
9
  RedditIcon,
-
 
10
  RedditShareButton,
-
 
11
  TelegramIcon,
-
 
12
  TelegramShareButton,
-
 
13
  TwitterIcon,
-
 
14
  TwitterShareButton,
-
 
15
  WhatsappIcon,
-
 
16
  WhatsappShareButton,
-
 
17
} from 'react-share'
5
import { addNotification } from "../../../../redux/notification/notification.actions"
18
import { addNotification } from '../../../../redux/notification/notification.actions'
6
import { axios } from "../../../../utils"
19
import { axios } from '../../../../utils'
Línea 7... Línea 20...
7
 
20
 
8
export default function withExternalShare(Component, url, params) {
21
export default function withExternalShare(Component, url, params) {
9
    return function () {
22
  return function () {
10
        const dispatch = useDispatch()
23
    const dispatch = useDispatch()
11
        const [shareOptions, setShareOptions] = useState(false)
24
    const [shareOptions, setShareOptions] = useState(false)
12
        const [shareUrl, setShareUrl] = useState('');
25
    const [shareUrl, setShareUrl] = useState('')
13
 
26
 
14
        const handleDisplayReactionList = () => setShareOptions(!shareOptions)
27
    const handleDisplayReactionList = () => setShareOptions(!shareOptions)
15
 
28
 
16
        const getShareUrl = async () => {
29
    const getShareUrl = async () => {
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
                    }
-
 
24
 
-
 
25
                    setShareUrl(data.data)
30
      await axios
26
                })
-
 
27
                .catch((err) => console.log(err))
-
 
28
        }
-
 
29
 
-
 
30
        const incrementCount = async () => {
-
 
31
            await axios.post(params.shareUrl)
31
        .get(url)
32
                .then(({ data }) => {
32
        .then(({ data }) => {
33
                    if (!data.success) {
33
          if (!data.success) {
34
                        dispatch(addNotification({ style: 'danger', msg: data.data }))
-
 
35
                        return
-
 
36
                    }
-
 
37
 
34
            dispatch(addNotification({ style: 'danger', msg: data.data }))
38
                    setShareOptions(false)
-
 
39
                    params.setValue(data.data)
35
            setShareOptions(false)
40
                })
-
 
41
                .catch((err) => console.log(err))
36
            return
42
        }
37
          }
43
 
-
 
44
        useEffect(() => {
-
 
45
            if (shareOptions && !shareUrl) getShareUrl()
38
 
46
        }, [shareOptions])
-
 
47
 
39
          setShareUrl(data.data)
48
        return (
-
 
49
            <div className="position-relative d-inline-flex" onClick={handleDisplayReactionList} style={{ flexGrow: 1 }}>
-
 
50
                <Component {...params} />
-
 
51
                {shareOptions &&
-
 
52
                    <div className="external__share" >
-
 
53
                        <FacebookShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
54
                            <FacebookIcon size={32} round />
-
 
55
                        </FacebookShareButton>
-
 
56
                        <TwitterShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
57
                            <TwitterIcon size={32} round />
-
 
58
                        </TwitterShareButton>
-
 
59
                        <TelegramShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
60
                            <TelegramIcon size={32} round />
-
 
61
                        </TelegramShareButton>
-
 
62
                        <WhatsappShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
63
                            <WhatsappIcon size={32} round />
-
 
64
                        </WhatsappShareButton>
-
 
65
                        <RedditShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
66
                            <RedditIcon size={32} round />
-
 
67
                        </RedditShareButton>
-
 
68
                        <EmailShareButton url={shareUrl} onShareWindowClose={() => incrementCount()}>
-
 
69
                            <EmailIcon size={32} round />
40
        })
70
                        </EmailShareButton>
-
 
71
                    </div>
-
 
72
                }
-
 
73
            </div>
-
 
74
        )
41
        .catch((err) => console.log(err))
75
    }
-
 
76
}
42
    }
-
 
43
 
-
 
44
    const incrementCount = async () => {
-
 
45
      await axios
-
 
46
        .post(params.shareUrl)
-
 
47
        .then(({ data }) => {
-
 
48
          if (!data.success) {
-
 
49
            dispatch(addNotification({ style: 'danger', msg: data.data }))
-
 
50
            return
-
 
51
          }
-
 
52
 
-
 
53
          setShareOptions(false)
-
 
54
          params.setValue(data.data)
-
 
55
        })
-
 
56
        .catch((err) => console.log(err))
-
 
57
    }
-
 
58
 
-
 
59
    useEffect(() => {
-
 
60
      if (shareOptions && !shareUrl) getShareUrl()
-
 
61
    }, [shareOptions])
-
 
62
 
-
 
63
    return (
-
 
64
      <div
-
 
65
        className="position-relative d-inline-flex"
-
 
66
        onClick={handleDisplayReactionList}
-
 
67
        style={{ flexGrow: 1 }}
-
 
68
      >
-
 
69
        <Component {...params} />
-
 
70
        {shareOptions && (
-
 
71
          <div className="external__share">
-
 
72
            <FacebookShareButton
-
 
73
              url={shareUrl}
-
 
74
              onShareWindowClose={() => incrementCount()}
-
 
75
            >
-
 
76
              <FacebookIcon size={32} round />
-
 
77
            </FacebookShareButton>
-
 
78
            <TwitterShareButton
-
 
79
              url={shareUrl}
-
 
80
              onShareWindowClose={() => incrementCount()}
-
 
81
            >
-
 
82
              <TwitterIcon size={32} round />
-
 
83
            </TwitterShareButton>
-
 
84
            <TelegramShareButton
-
 
85
              url={shareUrl}
-
 
86
              onShareWindowClose={() => incrementCount()}
-
 
87
            >
-
 
88
              <TelegramIcon size={32} round />
-
 
89
            </TelegramShareButton>
-
 
90
            <WhatsappShareButton
-
 
91
              url={shareUrl}
-
 
92
              onShareWindowClose={() => incrementCount()}
-
 
93
            >
-
 
94
              <WhatsappIcon size={32} round />
-
 
95
            </WhatsappShareButton>
-
 
96
            <RedditShareButton
-
 
97
              url={shareUrl}
-
 
98
              onShareWindowClose={() => incrementCount()}
-
 
99
            >
-
 
100
              <RedditIcon size={32} round />
-
 
101
            </RedditShareButton>
-
 
102
            <EmailShareButton
-
 
103
              url={shareUrl}
-
 
104
              onShareWindowClose={() => incrementCount()}
-
 
105
            >
-
 
106
              <EmailIcon size={32} round />
-
 
107
            </EmailShareButton>
-
 
108
          </div>
-
 
109
        )}
-
 
110
      </div>
-
 
111
    )
-
 
112
  }
-
 
113
}