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; return (await axios.get(`${path}/${id}`)).data;
}, },
async createNewPost(title, content) { async createNewPost(title, content) {
const location = locationUtils.getCurrentLocation(); const location = await locationUtils.getCurrentLocation();
if(location.lon && location.lat) { if(location.lon && location.lat) {
await axios.post(`${path}s`, { await axios.post(`${path}s`, {
"authorID": 1, "authorID": 1,

View File

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

View File

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