Proyectos de Subversion LeadersLinked - Backend

Rev

Ir a la última revisión | | Ultima modificación | Ver Log |

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