restructured code
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user