-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fevi
committed
Aug 2, 2020
1 parent
4be52af
commit d7f3432
Showing
22 changed files
with
4,400 additions
and
3,641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
.DS_Store | ||
|
||
|
||
.idea/ | ||
|
||
# Logs | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
import React, {useState} from 'react'; | ||
import React, { useState } from 'react'; | ||
import axios from 'axios'; | ||
|
||
export default ({postId}) => { | ||
const [content, setContent] = useState(''); | ||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
await axios.post(`http://localhost:4001/posts/${postId}/comments`, { | ||
content | ||
}); | ||
setContent(''); | ||
}; | ||
return <div> | ||
<form onSubmit={onSubmit}> | ||
<div className="form-group"> | ||
<label>New Comment</label> | ||
<input | ||
value={content} | ||
onChange={e => setContent(e.target.value)} | ||
className="form-control" | ||
> | ||
</input> | ||
</div> | ||
<button className="btn btn-primary">Submit</button> | ||
</form> | ||
</div>; | ||
}; | ||
export default ({ postId }) => { | ||
const [content, setContent] = useState(''); | ||
|
||
const onSubmit = async event => { | ||
event.preventDefault(); | ||
|
||
await axios.post(`http://localhost:4001/posts/${postId}/comments`, { | ||
content | ||
}); | ||
|
||
setContent(''); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={onSubmit}> | ||
<div className="form-group"> | ||
<label>New Comment</label> | ||
<input | ||
value={content} | ||
onChange={e => setContent(e.target.value)} | ||
className="form-control" | ||
/> | ||
</div> | ||
<button className="btn btn-primary">Submit</button> | ||
</form> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
|
||
export default ({postId}) => { | ||
const [comments, setComments] = useState([]); | ||
const fetchData = async () => { | ||
const res = await axios.get(`http://localhost:4001/posts/${postId}/comments`); | ||
setComments(res.data); | ||
}; | ||
useEffect( | ||
() => { | ||
fetchData(); | ||
}, | ||
[] | ||
export default ({ postId }) => { | ||
const [comments, setComments] = useState([]); | ||
|
||
const fetchData = async () => { | ||
const res = await axios.get( | ||
`http://localhost:4001/posts/${postId}/comments` | ||
); | ||
const renderedComments = comments.map(comment => { | ||
console.log(comment); | ||
return <li key={comment.id}>{comment.content}</li>; | ||
}); | ||
return <ul> | ||
{renderedComments} | ||
</ul> | ||
}; | ||
|
||
setComments(res.data); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
const renderedComments = comments.map(comment => { | ||
return <li key={comment.id}>{comment.content}</li>; | ||
}); | ||
|
||
return <ul>{renderedComments}</ul>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
import React, {useState} from 'react'; | ||
import React, { useState } from 'react'; | ||
import axios from 'axios'; | ||
|
||
export default () => { | ||
const [title, setTitle] = useState(''); | ||
const onSubmit = async (event) => { | ||
event.preventDefault(); | ||
await axios.post('http://localhost:4000/posts', { | ||
title | ||
}); | ||
setTitle(''); | ||
}; | ||
return <div> | ||
<form onSubmit={onSubmit}> | ||
<div className="form-group"> | ||
<label>Title</label> | ||
<input value={title} onChange={e => setTitle(e.target.value)} className="form-control"/> | ||
</div> | ||
<button className="btn btn-primary">Submit</button> | ||
</form> | ||
</div>; | ||
}; | ||
const [title, setTitle] = useState(''); | ||
|
||
const onSubmit = async event => { | ||
event.preventDefault(); | ||
|
||
await axios.post('http://localhost:4000/posts', { | ||
title | ||
}); | ||
|
||
setTitle(''); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<form onSubmit={onSubmit}> | ||
<div className="form-group"> | ||
<label>Title</label> | ||
<input | ||
value={title} | ||
onChange={e => setTitle(e.target.value)} | ||
className="form-control" | ||
/> | ||
</div> | ||
<button className="btn btn-primary">Submit</button> | ||
</form> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import React, { useState, useEffect } from 'react'; | ||
import axios from 'axios'; | ||
import CommentCreate from './CommentCreate'; | ||
import CommentList from './CommentList'; | ||
|
||
export default () => { | ||
const [posts, setPosts] = useState({}); | ||
const fetchPosts = async () => { | ||
const res = await axios.get('http://localhost:4000/posts'); | ||
setPosts(res.data); | ||
}; | ||
useEffect(() => { | ||
fetchPosts(); | ||
}, []); | ||
const renderedPosts = Object.values(posts).map(post => { | ||
console.log(post); | ||
return ( | ||
<div | ||
className="card" | ||
style={{ | ||
width: '30%', | ||
marginBottom: '20%' | ||
}} | ||
key={post.id} | ||
> | ||
<div className="card-body"> | ||
<h3>{post.title}</h3> | ||
<CommentList postId={post.id}/> | ||
<CommentCreate postId={post.id}/> | ||
</div> | ||
</div> | ||
) | ||
}); | ||
return <div className="d-flex flex-row flex-wrap justify-content-between"> | ||
{renderedPosts} | ||
</div>; | ||
} | ||
const [posts, setPosts] = useState({}); | ||
|
||
const fetchPosts = async () => { | ||
const res = await axios.get('http://localhost:4000/posts'); | ||
|
||
setPosts(res.data); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchPosts(); | ||
}, []); | ||
|
||
const renderedPosts = Object.values(posts).map(post => { | ||
return ( | ||
<div | ||
className="card" | ||
style={{ width: '30%', marginBottom: '20px' }} | ||
key={post.id} | ||
> | ||
<div className="card-body"> | ||
<h3>{post.title}</h3> | ||
<CommentList postId={post.id} /> | ||
<CommentCreate postId={post.id} /> | ||
</div> | ||
</div> | ||
); | ||
}); | ||
|
||
return ( | ||
<div className="d-flex flex-row flex-wrap justify-content-between"> | ||
{renderedPosts} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.