Files
astuto/app/javascript/components/LikeButton/LikeButtonP.tsx

45 lines
1.0 KiB
TypeScript
Raw Normal View History

2019-09-27 16:57:23 +02:00
import * as React from 'react';
import { LikeIcon, SolidLikeIcon } from '../common/Icons';
2019-09-27 16:57:23 +02:00
interface Props {
postId: number;
likeCount: number;
showLikeCount?: boolean;
showLikeButton?: boolean;
2019-09-27 16:57:23 +02:00
liked: number;
handleLikeSubmit(
postId: number,
isLike: boolean,
authenticityToken: string,
): void;
authenticityToken: string;
isLoggedIn: boolean;
}
const LikeButtonP = ({
postId,
likeCount,
showLikeCount = true,
showLikeButton = true,
2019-09-27 16:57:23 +02:00
liked,
handleLikeSubmit,
authenticityToken,
isLoggedIn,
}: Props) => (
<div className="likeButtonContainer">
2019-09-27 18:19:13 +02:00
<div onClick={(e) => {
e.stopPropagation();
if (isLoggedIn) handleLikeSubmit(postId, !liked, authenticityToken);
else window.location.href = `/users/sign_in`;
}}
className={`likeButton${liked ? ' liked' : ''}`}
hidden={!showLikeButton}
2019-09-27 18:19:13 +02:00
>
{ liked ? <SolidLikeIcon /> : <LikeIcon />}
2019-09-27 18:19:13 +02:00
</div>
{ showLikeCount && <span className="likeCountLabel">{likeCount}</span> }
2019-09-27 16:57:23 +02:00
</div>
);
export default LikeButtonP;