Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 2243 Rev 2244
Línea 33... Línea 33...
33
    0px -4px 4px -2px rgb(0 0 0 / 12%);
33
    0px -4px 4px -2px rgb(0 0 0 / 12%);
34
`
34
`
Línea 35... Línea 35...
35
 
35
 
36
export default function withExternalShare(Component, url) {
36
export default function withExternalShare(Component, url) {
37
  return function ({ children, setValue, shorterUrl }) {
37
  return function ({ children, setValue, shorterUrl }) {
38
    const [shareOptions, setShareOptions] = useState(false)
38
    const [showOptions, setShowOptions] = useState(false)
39
    const [shareUrl, setShareUrl] = useState('')
39
    const [shareUrl, setShareUrl] = useState('')
Línea 40... Línea 40...
40
    const dispatch = useDispatch()
40
    const dispatch = useDispatch()
41
 
-
 
42
    const toggleShareOptions = () => {
-
 
43
      setShareOptions(!shareOptions)
-
 
44
    }
-
 
45
 
-
 
46
    const getShorterUrl = () =>
-
 
47
      new Promise(() => {
-
 
48
        axios
-
 
49
          .get(url)
-
 
50
          .then(({ data }) => {
-
 
51
            if (!data.success) {
-
 
52
              setShareOptions(false)
-
 
53
              throw new Error(data.data)
-
 
54
            }
-
 
55
 
-
 
56
            setShareUrl(data.data)
-
 
57
          })
-
 
58
          .catch((err) =>
-
 
59
            dispatch(addNotification({ style: 'danger', msg: err.message }))
-
 
Línea 60... Línea 41...
60
          )
41
 
61
      })
42
    const toggleShareOptions = () => setShowOptions(!showOptions)
62
 
43
 
63
    const incrementCount = async () => {
44
    const incrementCount = async () => {
64
      await axios
45
      await axios
65
        .post(shorterUrl)
46
        .post(shorterUrl)
66
        .then(({ data }) => {
-
 
67
          if (!data.success) {
-
 
68
            dispatch(addNotification({ style: 'danger', msg: data.data }))
-
 
69
            return
47
        .then((response) => {
70
          }
48
          const { data, success } = response.data
71
 
49
          if (!success) throw new Error(data)
72
          setShareOptions(false)
50
          setShowOptions(false)
-
 
51
          setValue(data)
-
 
52
        })
73
          setValue(data.data)
53
        .catch((err) =>
Línea -... Línea 54...
-
 
54
          dispatch(addNotification({ style: 'danger', msg: err.message }))
-
 
55
        )
-
 
56
    }
-
 
57
 
-
 
58
    useEffect(() => {
-
 
59
      if (!showOptions || shareUrl) return
-
 
60
 
-
 
61
      const getShareUrl = async () => {
-
 
62
        try {
-
 
63
          const response = await axios.get(url)
-
 
64
          const { data, success } = response.data
-
 
65
          if (!success) throw new Error(data)
-
 
66
          setShareUrl(data)
-
 
67
        } catch (error) {
-
 
68
          dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
69
        }
-
 
70
      }
74
        })
71
 
75
        .catch((err) => console.log(err))
72
      getShareUrl()
76
    }
73
    }, [showOptions, shareUrl])
Línea 77... Línea 74...
77
 
74
 
78
    return (
75
    return (
79
      <Component onClick={toggleShareOptions}>
76
      <Component onClick={toggleShareOptions}>
80
        {children}
77
        {children}
81
 
78
 
82
        {shareOptions && (
79
        {showOptions && (
83
          <StyledShareContainer>
80
          <StyledShareContainer>
84
            <FacebookShareButton
81
            <FacebookShareButton
85
              url={shareUrl}
82
              url={shareUrl}
86
              onShareWindowClose={() => incrementCount()}
83
              onShareWindowClose={incrementCount}
87
              beforeOnClick={getShorterUrl}
84
              disabled={!shareUrl}
88
            >
85
            >
-
 
86
              <FacebookIcon size={32} round />
89
              <FacebookIcon size={32} round />
87
            </FacebookShareButton>
90
            </FacebookShareButton>
88
            <TwitterShareButton
91
            <TwitterShareButton
89
              url={shareUrl}
92
              url={shareUrl}
90
              onShareWindowClose={incrementCount}
93
              onShareWindowClose={() => incrementCount()}
91
              disabled={!shareUrl}
94
            >
92
            >
-
 
93
              <TwitterIcon size={32} round />
95
              <TwitterIcon size={32} round />
94
            </TwitterShareButton>
96
            </TwitterShareButton>
95
            <TelegramShareButton
97
            <TelegramShareButton
96
              url={shareUrl}
98
              url={shareUrl}
97
              onShareWindowClose={incrementCount}
99
              onShareWindowClose={() => incrementCount()}
98
              disabled={!shareUrl}
100
            >
99
            >
-
 
100
              <TelegramIcon size={32} round />
101
              <TelegramIcon size={32} round />
101
            </TelegramShareButton>
102
            </TelegramShareButton>
102
            <WhatsappShareButton
103
            <WhatsappShareButton
103
              url={shareUrl}
104
              url={shareUrl}
104
              onShareWindowClose={incrementCount}
105
              onShareWindowClose={() => incrementCount()}
105
              disabled={!shareUrl}
106
            >
106
            >
-
 
107
              <WhatsappIcon size={32} round />
107
              <WhatsappIcon size={32} round />
108
            </WhatsappShareButton>
108
            </WhatsappShareButton>
109
            <RedditShareButton
109
            <RedditShareButton
110
              url={shareUrl}
110
              url={shareUrl}
111
              onShareWindowClose={incrementCount}
111
              onShareWindowClose={() => incrementCount()}
112
              disabled={!shareUrl}
112
            >
113
            >
-
 
114
              <RedditIcon size={32} round />
113
              <RedditIcon size={32} round />
115
            </RedditShareButton>
114
            </RedditShareButton>
116
            <EmailShareButton
115
            <EmailShareButton
117
              url={shareUrl}
116
              url={shareUrl}
118
              onShareWindowClose={incrementCount}
117
              onShareWindowClose={() => incrementCount()}
119
              disabled={!shareUrl}