Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
15761 stevensc 1
import React, { useState } from 'react'
2
 
11350 nelberth 3
/* import { useDispatch } from 'react-redux'; */
4
/* import { addNotification } from '../../../../redux/notification/notification.actions'; */
5
 
6
const LikeButton = ({ likeUrl, showCounter = false, onClick }) => {
15761 stevensc 7
  const [isLike, setIsLike] = useState(false)
8
  const [likesState, setLikesState] = useState(0)
9
  /* const dispatch = useDispatch() */
11350 nelberth 10
 
15761 stevensc 11
  const handleClick = (url) => {
12
    if (!url) {
13
      setIsLike(!isLike)
14
      if (onClick) {
15
        onClick()
16
      }
17
    }
18
    /* else {
11350 nelberth 19
            axios.post(url)
20
                .then((res) => {
21
                    const { success, data } = res.data;
22
                    if (!success) {
23
                        setIsLike(!isLike);
24
                        dispatch(addNotification({
25
                            style: "danger",
26
                            msg: data,
27
                        }));
28
                    } else {
29
                        setLikesState(data.likes)
30
                        setIsLike(!isLike);
31
                    }
32
                });
33
        } */
15761 stevensc 34
  }
11350 nelberth 35
 
15761 stevensc 36
  return (
11350 nelberth 37
        <button
38
            type="button"
15761 stevensc 39
            className={isLike ? 'btn-unlike' : 'btn-like'}
11350 nelberth 40
            onClick={() => handleClick(likeUrl)}
41
        >
15761 stevensc 42
            <i className={isLike ? 'fas fa-heart' : 'far fa-heart'}></i>
11350 nelberth 43
            {showCounter && likesState}
44
        </button>
15761 stevensc 45
  )
11350 nelberth 46
}
47
 
15761 stevensc 48
export default LikeButton