mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Added a member check for toggling on and off likes
- This should stop people who are not logged in from liking comments refs https://github.com/TryGhost/Team/issues/1693
This commit is contained in:
parent
dce15950cd
commit
28b566f95a
@ -3,23 +3,30 @@ import {ReactComponent as LikeIcon} from '../images/icons/like.svg';
|
||||
import AppContext from '../AppContext';
|
||||
|
||||
function Like(props) {
|
||||
const {onAction} = useContext(AppContext);
|
||||
const {onAction, member} = useContext(AppContext);
|
||||
const [animationClass, setAnimation] = useState('');
|
||||
|
||||
let likeCursor = 'cursor-pointer';
|
||||
if (!member) {
|
||||
likeCursor = 'cursor-text';
|
||||
}
|
||||
|
||||
const toggleLike = () => {
|
||||
if (!props.comment.liked) {
|
||||
onAction('likeComment', props.comment);
|
||||
setAnimation('animate-heartbeat');
|
||||
setTimeout(() => {
|
||||
setAnimation('');
|
||||
}, 400);
|
||||
} else {
|
||||
onAction('unlikeComment', props.comment);
|
||||
if (member) {
|
||||
if (!props.comment.liked) {
|
||||
onAction('likeComment', props.comment);
|
||||
setAnimation('animate-heartbeat');
|
||||
setTimeout(() => {
|
||||
setAnimation('');
|
||||
}, 400);
|
||||
} else {
|
||||
onAction('unlikeComment', props.comment);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<button className={`flex font-sans items-center text-sm ${props.comment.liked ? 'text-neutral-900 dark:text-[rgba(255,255,255,0.9)]' : 'text-neutral-400 dark:text-[rgba(255,255,255,0.5)]'}`} onClick={toggleLike}>
|
||||
<button className={`flex font-sans items-center text-sm ${props.comment.liked ? 'text-neutral-900 dark:text-[rgba(255,255,255,0.9)]' : 'text-neutral-400 dark:text-[rgba(255,255,255,0.5)]'} ${likeCursor}`} onClick={toggleLike}>
|
||||
<LikeIcon className={animationClass + ` mr-[6px] ${props.comment.liked ? 'fill-neutral-900 stroke-neutral-900 dark:fill-white dark:stroke-white' : 'stroke-neutral-400 dark:stroke-[rgba(255,255,255,0.5)]'}`} />
|
||||
{props.comment.likes_count}
|
||||
</button>
|
||||
|
Loading…
Reference in New Issue
Block a user