restructured code

This commit is contained in:
Pete Gerlach
2024-06-11 15:26:49 +02:00
parent 5ef0b504e1
commit f17b253ac6
3 changed files with 9 additions and 7 deletions

View File

@@ -2,7 +2,7 @@ import React from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faCaretUp, faCaretDown } from '@fortawesome/free-solid-svg-icons';
const Post = ({ post, upvotePost, downvotePost }) => {
const Post = ({ post, vote }) => {
return (
<div className="post">
<div className="post-container">
@@ -16,12 +16,15 @@ const Post = ({ post, upvotePost, downvotePost }) => {
<div className="votes">
<button onClick={(e) => {
e.stopPropagation();
upvotePost(post.id);
vote(post.id, post.reaction !== null ? null : true);
}}>
<FontAwesomeIcon icon={faCaretUp} />
</button>
<span>{post.reactions.positive - post.reactions.negative}</span>
<button onClick={(e) => { e.stopPropagation(); downvotePost(post.id); }}>
<button onClick={(e) => {
e.stopPropagation();
vote(post.id, post.reaction !== null ? null : false);
}}>
<FontAwesomeIcon icon={faCaretDown} />
</button>
</div>