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

@@ -11,7 +11,7 @@ export const postApi = {
return (await axios.get(`${path}/${id}`)).data;
},
async createNewPost(title, content) {
const location = locationUtils.getCurrentLocation();
const location = await locationUtils.getCurrentLocation();
if(location.lon && location.lat) {
await axios.post(`${path}s`, {
"authorID": 1,

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>

View File

@@ -1,15 +1,14 @@
import React from 'react';
import Post from './Post';
const PostList = ({ posts, upvotePost, downvotePost, onPostClick }) => {
const PostList = ({ posts, vote, onPostClick }) => {
return (
<div className="post-list">
{posts.map(post => (
<div key={post.id} onClick={() => onPostClick(post)}>
<Post
post={post}
upvotePost={upvotePost}
downvotePost={downvotePost}
vote={vote}
/>
</div>
))}