Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

import React from 'react'
import { useState } from 'react';
/* import { useDispatch } from 'react-redux'; */
/* import { addNotification } from '../../../../redux/notification/notification.actions'; */

const LikeButton = ({ likeUrl, showCounter = false, onClick }) => {

    const [isLike, setIsLike] = useState(false);
    const [likesState, setLikesState] = useState(0);
    /* const dispatch = useDispatch() */

    const handleClick = (url) => {
        if (!url) {
            setIsLike(!isLike)
            if (onClick) {
                onClick()
            }
        }
        /* else {
            axios.post(url)
                .then((res) => {
                    const { success, data } = res.data;
                    if (!success) {
                        setIsLike(!isLike);
                        dispatch(addNotification({
                            style: "danger",
                            msg: data,
                        }));
                    } else {
                        setLikesState(data.likes)
                        setIsLike(!isLike);
                    }
                });
        } */
    }

    return (
        <button
            type="button"
            className={isLike ? "btn-unlike" : "btn-like"}
            onClick={() => handleClick(likeUrl)}
        >
            <i className={isLike ? "fas fa-heart" : "far fa-heart"}></i>
            {showCounter && likesState}
        </button>
    )
}

export default LikeButton