Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5220 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5214 stevensc 1
/* eslint-disable camelcase */
2
/* eslint-disable react/prop-types */
3
import React, { useEffect, useState } from 'react'
4
import { useDispatch } from 'react-redux'
5
import { addNotification } from '../../../redux/notification/notification.actions'
6
import { axios } from '../../../utils'
7
 
8
const PulseList = ({
9
  options = [],
10
  title = '',
11
  onComplete = () => null
12
}) => {
13
  const [isMounted, setIsMounted] = useState(false)
14
  const dispatch = useDispatch()
15
 
16
  const handleEmojiSave = (url) => {
17
    if (!url) {
18
      return false
19
    }
20
 
21
    axios.post(url)
22
      .then(({ data }) => {
23
        if (!data.success) {
24
          return dispatch(addNotification({
25
            style: 'danger',
26
            msg: typeof data.data === 'string'
27
              ? data.data
28
              : 'Ha ocurrido un error'
29
          }))
30
        }
31
 
32
        return onComplete()
33
      })
34
  }
35
 
36
  useEffect(() => {
37
    setIsMounted(true)
38
  }, [])
39
 
40
  return (
41
        <div className="daily_pulse-quest">
42
            <h4>{title}</h4>
43
            <ul>
44
                {options.map(({ link_save, id, image }, index) =>
45
                    <li key={id}>
5238 stevensc 46
                        <a href={link_save} onClick={(e) => {
47
                          e.preventDefault()
48
                          handleEmojiSave(link_save)
49
                        }}>
5220 stevensc 50
                            <img className={isMounted && 'fadedown'} src={image} style={{ animationDelay: `${index + 10}00ms` }} />
5214 stevensc 51
                        </a>
52
                    </li>
53
                )}
54
            </ul>
55
        </div>
56
  )
57
}
58
 
59
export default PulseList