Skip to content

Commit 4557ae4

Browse files
committed
ft(add new comments to state)
1 parent ac73b53 commit 4557ae4

File tree

7 files changed

+82
-12
lines changed

7 files changed

+82
-12
lines changed

instagram-app/src/App.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ import './App.css';
66

77
function App() {
88
const [post] = useState(data);
9+
910
return (
1011
<div className="App">
1112
<SearchBar />
1213
{post.map((userPost, index)=>{
13-
return <PostContainer key={index} post={userPost}/>
14+
return (
15+
<PostContainer
16+
key={index}
17+
props={userPost}
18+
/>)
1419
})
1520
}
1621

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.form__input {
2+
width: 100%;
3+
height: 2rem;
4+
border: 0;
5+
padding: 1rem;
6+
font-size: 1rem;
7+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import './Form.css';
3+
4+
const Form = ({ inputValue, changeHandler, addComment }) => {
5+
return (
6+
<form onSubmit={(e) => addComment(e)}>
7+
<input
8+
className="form__input"
9+
type="text"
10+
value={inputValue}
11+
onChange={changeHandler}
12+
placeholder="Add a comment..."
13+
/>
14+
</form>)
15+
}
16+
17+
export default Form;

instagram-app/src/components/PostContainer/PostContainer.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
width: 50%;
55
margin: 5rem auto;
66
border: 1px solid lightgray;
7+
overflow: hidden;
78
}
89
.user__deets {
910
width: 100%;
@@ -47,6 +48,7 @@
4748
justify-content: flex-start;
4849
align-items: flex-start;
4950
color: gray;
50-
margin-bottom: 1rem;
51+
margin: 0 .5rem;
5152
padding: 1rem;
53+
border-bottom: 1px solid lightgrey;
5254
}

instagram-app/src/components/PostContainer/PostContainer.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,54 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
2+
import uuidv4 from 'uuid/v4';
23
import { IoIosHeartEmpty} from "react-icons/io";
34
import { FaRegComment } from "react-icons/fa";
45
import CommentSection from '../CommentSection/CommentSection';
6+
import Form from '../Form/Form';
57
import './PostContainer.css';
68

7-
const PostContainer = (props) => {
9+
const PostContainer = ({ props }) => {
10+
const { comments, thumbnailUrl, imageUrl, timestamp, likes, username } = props;
11+
const [inputValue, setChange] = useState('');
12+
const [inputComment, setComment] = useState(comments);
13+
const handleChange = (e) =>{
14+
setChange(e.target.value);
15+
}
16+
const postComment = (e) => {
17+
e.preventDefault();
18+
const newComment = {
19+
id: uuidv4(),
20+
username: "user",
21+
text: inputValue
22+
};
23+
setComment(comments.concat(newComment));
24+
}
25+
826
return (
927
<div className="post__container">
1028
<div className="user__deets">
11-
<img className="profile__pix" src={props.post.thumbnailUrl} alt="user-profile" />
12-
<p>{props.post.username}</p>
29+
<img className="profile__pix" src={thumbnailUrl} alt="user-profile" />
30+
<p>{username}</p>
1331
</div>
1432
<div className="user__post">
15-
<img className="post__image" src={props.post.imageUrl} alt="user-post"/>
33+
<img className="post__image" src={imageUrl} alt="user-post"/>
1634
</div>
1735
<div className="reaction">
1836
<div className="post__icons">
1937
<IoIosHeartEmpty /> <FaRegComment/>
2038
</div>
21-
{props.post.likes} likes</div>
22-
{props.post.comments.map((comment, index) =>{
23-
console.log("===",comment);
24-
return <CommentSection key={index} props={comment}/>
39+
{likes} likes</div>
40+
{
41+
inputComment.map((comment) =>{
42+
return <CommentSection key={comment.id} props={comment}/>
2543
})
2644
}
2745
<div className="timestamp">
28-
{props.post.timestamp}</div>
46+
{timestamp}</div>
47+
<Form
48+
inputValue={inputValue}
49+
changeHandler={handleChange}
50+
addComment={postComment}
51+
/>
2952
</div>
3053
)
3154
}

instagram-app/src/dummy-data.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@ const dummyData = [
1010
timestamp: "July 17th 2017, 12:42:40 pm",
1111
comments: [
1212
{
13+
id: 1,
1314
username: "philzcoffee",
1415
text:
1516
"We've got more than just delicious coffees to offer at our shops!"
1617
},
1718
{
19+
id: 2,
1820
username: "biancasaurus",
1921
text: "Looks delicious!"
2022
},
2123
{
24+
id: 3,
2225
username: "martinseludo",
2326
text: "Can't wait to try it!"
2427
}
@@ -34,22 +37,27 @@ const dummyData = [
3437
timestamp: "July 15th 2017, 03:12:09 pm",
3538
comments: [
3639
{
40+
id: 4,
3741
username: "twitch",
3842
text: "Epic Street Fighter action here in Las Vegas at #EVO2017!"
3943
},
4044
{
45+
id: 5,
4146
username: "michaelmarzetta",
4247
text: "Omg that match was crazy"
4348
},
4449
{
50+
id: 6,
4551
username: "themexican_leprechaun",
4652
text: "What a setup"
4753
},
4854
{
55+
id: 7,
4956
username: "dennis_futbol",
5057
text: "It that injustice"
5158
},
5259
{
60+
id: 8,
5361
username: "dennis_futbol",
5462
text: "Is"
5563
}
@@ -65,14 +73,17 @@ const dummyData = [
6573
timestamp: "July 14th 2017, 10:04:08 am",
6674
comments: [
6775
{
76+
id: 9,
6877
username: "playhearthstone",
6978
text: "Love this shot!"
7079
},
7180
{
81+
id: 10,
7282
username: "awaywetravel",
7383
text: "Yosemite is my most favorite place in the universe"
7484
},
7585
{
86+
id: 11,
7687
username: "awesomebt28",
7788
text: "I like how Half Dome looks so old and useless"
7889
}

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)