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