Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1194 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1192 stevensc 1
import React from 'react'
2
import { useState } from 'react';
1193 stevensc 3
/* import { useDispatch } from 'react-redux'; */
4
/* import { addNotification } from '../../../../redux/notification/notification.actions'; */
1192 stevensc 5
 
1198 stevensc 6
const LikeButton = ({ likeUrl, showCounter = false, onClick }) => {
1192 stevensc 7
 
8
    const [isLike, setIsLike] = useState(false);
9
    const [likesState, setLikesState] = useState(0);
1193 stevensc 10
    /* const dispatch = useDispatch() */
1192 stevensc 11
 
12
    const handleClick = (url) => {
1193 stevensc 13
        if (!url) {
14
            setIsLike(!isLike)
1198 stevensc 15
            if (onClick) {
16
                onClick()
17
            }
1193 stevensc 18
        }
19
        /* else {
1192 stevensc 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
                });
1193 stevensc 34
        } */
1192 stevensc 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>
1194 stevensc 44
            {showCounter && likesState}
1192 stevensc 45
        </button>
46
    )
47
}
48
 
49
export default LikeButton