diff --git a/src/App.jsx b/src/App.jsx index 22ae1b9c..bdb4edf5 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,104 +1,32 @@ import './App.scss'; +import postsFromServer from './api/posts.json'; +import commentsFromServer from './api/comments.json'; +import usersFromServer from './api/users.json'; +import { PostList } from './components/PostList' -// import postsFromServer from './api/posts.json'; -// import commentsFromServer from './api/comments.json'; -// import usersFromServer from './api/users.json'; +const getUserById = userId => { + return usersFromServer.find(user => userId === user.id) || null +} -export const App = () => ( -
-

Static list of posts

- -
-
-
-

qui est esse

- -

- {' Posted by '} - - - Leanne Graham - -

-
- -

- est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae ea - dolores neque fugiat blanditiis voluptate porro vel nihil molestiae ut - reiciendis qui aperiam non debitis possimus qui neque nisi nulla -

- -
- - No comments yet -
- -
-
-

doloremque illum aliquid sunt

+export const posts = postsFromServer.map(post => { + return { + ...post, + user: getUserById(post.userId), + comments: commentsFromServer.filter(comment => comment.postId === post.id) + } +}) -

- {' Posted by '} +console.log(posts) - - Patricia Lebsack - -

-
-

- deserunt eos nobis asperiores et hic est debitis repellat molestiae - optio nihil ratione ut eos beatae quibusdam distinctio maiores earum - voluptates et aut adipisci ea maiores voluptas maxime -

-
-
-
- pariatur omnis in - - {' by '} - - - Telly_Lynch@karl.co.uk - -
- -
- dolorum voluptas laboriosam quisquam ab totam beatae et aut - aliquid optio assumenda voluptas velit itaque quidem voluptatem - tempore cupiditate in itaque sit molestiae minus dolores magni -
-
- -
-
- - odio adipisci rerum aut animi - - - {' by '} - - - Nikita@garfield.biz - -
- -
- quia molestiae reprehenderit quasi aspernatur aut expedita - occaecati aliquam eveniet laudantium omnis quibusdam delectus - saepe quia accusamus maiores nam est cum et ducimus et vero - voluptates excepturi deleniti ratione -
-
-
-
-
+export const App = () => ( +
+

Static list of posts

+ {posts.map(post => { + return ( + + ) + })}
); diff --git a/src/App.scss b/src/App.scss index 98bb3956..64365095 100644 --- a/src/App.scss +++ b/src/App.scss @@ -5,32 +5,3 @@ iframe { .App__title { text-align: center; } - -.PostInfo { - margin: 10px auto; - width: 90%; - border: 1px solid #000; - border-radius: 8px; - background-color: lightgray; - padding: 1em; - - &__title { - margin: 0; - } - - &__header { - margin-bottom: 1em; - } -} - -.UserInfo { - font-weight: bold; -} - -.CommentList { - display: flex; - flex-direction: column; - gap: 0.7em; - background-color: #eee; - padding: 1em; -} diff --git a/src/components/CommentInfo/CommentInfo.jsx b/src/components/CommentInfo/CommentInfo.jsx index f99e2778..f119856e 100644 --- a/src/components/CommentInfo/CommentInfo.jsx +++ b/src/components/CommentInfo/CommentInfo.jsx @@ -1 +1,22 @@ -export const CommentInfo = () => <>Put the comment here; +export const CommentInfo = ({ comment }) => { + return ( +
+
+ {comment.name} + + {' by '} + + + {comment.email} + +
+ +
+ {comment.body} +
+
+ ) +} diff --git a/src/components/CommentInfo/CommentInfo.scss b/src/components/CommentInfo/CommentInfo.scss index f1b40ee0..e69de29b 100644 --- a/src/components/CommentInfo/CommentInfo.scss +++ b/src/components/CommentInfo/CommentInfo.scss @@ -1 +0,0 @@ -// add styles here diff --git a/src/components/CommentList/CommentList.jsx b/src/components/CommentList/CommentList.jsx index 263dfbc7..27cd50de 100644 --- a/src/components/CommentList/CommentList.jsx +++ b/src/components/CommentList/CommentList.jsx @@ -1 +1,23 @@ -export const CommentList = () => <>Put the list here; +import './CommentList.scss' +import { CommentInfo } from '../CommentInfo' + +export const CommentList = ({ comments }) => { + if (comments.length === 0) { + return ( + <> +
+ + No comments yet + + ); + } + + return ( +
+ {comments.map(comment => ( + + ))} +
+ ); +} + diff --git a/src/components/CommentList/CommentList.scss b/src/components/CommentList/CommentList.scss index f1b40ee0..91c2ed5f 100644 --- a/src/components/CommentList/CommentList.scss +++ b/src/components/CommentList/CommentList.scss @@ -1 +1,7 @@ -// add styles here +.CommentList { + display: flex; + flex-direction: column; + gap: 0.7em; + background-color: #eee; + padding: 1em; +} diff --git a/src/components/PostInfo/PostInfo.jsx b/src/components/PostInfo/PostInfo.jsx index eb3efb78..c424a6dd 100644 --- a/src/components/PostInfo/PostInfo.jsx +++ b/src/components/PostInfo/PostInfo.jsx @@ -1 +1,27 @@ -export const PostInfo = () => <>Put the post here; +import './PostInfo.scss' +import { CommentList } from '../CommentList' +import { UserInfo } from '../UserInfo' + +export const PostInfo = ({ post }) => { + const {title, user, comments} = post + + return ( +
+
+

{title}

+ +

+ {' Posted by '} + + +

+
+ +

+ {post.body} +

+ + +
+ ) +} diff --git a/src/components/PostInfo/PostInfo.scss b/src/components/PostInfo/PostInfo.scss index f1b40ee0..1ad49fd3 100644 --- a/src/components/PostInfo/PostInfo.scss +++ b/src/components/PostInfo/PostInfo.scss @@ -1 +1,16 @@ -// add styles here +.PostInfo { + margin: 10px auto; + width: 90%; + border: 1px solid #000; + border-radius: 8px; + background-color: lightgray; + padding: 1em; + + &__title { + margin: 0; + } + + &__header { + margin-bottom: 1em; + } +} diff --git a/src/components/PostList/PostList.jsx b/src/components/PostList/PostList.jsx index 4487a96c..fa7eb664 100644 --- a/src/components/PostList/PostList.jsx +++ b/src/components/PostList/PostList.jsx @@ -1 +1,11 @@ -export const PostList = () => <>Put the list here; +import { PostInfo } from '../PostInfo' + +export const PostList = ({ post }) => { + return ( +
+ {post && ( + + )} +
+ ) +} diff --git a/src/components/UserInfo/UserInfo.jsx b/src/components/UserInfo/UserInfo.jsx index 6264e2f7..0937e0ab 100644 --- a/src/components/UserInfo/UserInfo.jsx +++ b/src/components/UserInfo/UserInfo.jsx @@ -1 +1,13 @@ -export const UserInfo = () => <>Put the user here; +import './UserInfo.scss' + +export const UserInfo = ({ user }) => { + if (user === null) { + return null; + } + + return ( + + {user.name} + + ) +} diff --git a/src/components/UserInfo/UserInfo.scss b/src/components/UserInfo/UserInfo.scss index f1b40ee0..5080de7c 100644 --- a/src/components/UserInfo/UserInfo.scss +++ b/src/components/UserInfo/UserInfo.scss @@ -1 +1,3 @@ -// add styles here +.UserInfo { + font-weight: bold; +}