mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 19:57:52 +01:00
Implement basic version of likes
This commit is contained in:
37
app/javascript/components/LikeButton/LikeButtonP.tsx
Normal file
37
app/javascript/components/LikeButton/LikeButtonP.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import * as React from 'react';
|
||||
|
||||
interface Props {
|
||||
postId: number;
|
||||
likesCount: number;
|
||||
liked: number;
|
||||
handleLikeSubmit(
|
||||
postId: number,
|
||||
isLike: boolean,
|
||||
authenticityToken: string,
|
||||
): void;
|
||||
authenticityToken: string;
|
||||
isLoggedIn: boolean;
|
||||
}
|
||||
|
||||
const LikeButtonP = ({
|
||||
postId,
|
||||
likesCount,
|
||||
liked,
|
||||
handleLikeSubmit,
|
||||
authenticityToken,
|
||||
isLoggedIn,
|
||||
}: Props) => (
|
||||
<div className="likeButtonContainer">
|
||||
<button onClick={() =>
|
||||
isLoggedIn ?
|
||||
handleLikeSubmit(postId, !liked, authenticityToken)
|
||||
:
|
||||
window.location.href = `/users/sign_in`
|
||||
}>
|
||||
{ liked ? 'down' : 'up' }
|
||||
</button>
|
||||
<span className="likesCountLabel">{likesCount}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default LikeButtonP;
|
||||
Reference in New Issue
Block a user