|
1 | 1 | import './App.scss';
|
2 |
| - |
3 |
| -// import postsFromServer from './api/posts.json'; |
4 |
| -// import commentsFromServer from './api/comments.json'; |
5 |
| -// import usersFromServer from './api/users.json'; |
| 2 | +import postsFromServer from './api/posts.json'; |
| 3 | +import commentsFromServer from './api/comments.json'; |
| 4 | +import usersFromServer from './api/users.json'; |
| 5 | +import { PostList } from './components/PostList'; |
| 6 | + |
| 7 | +export const findUserById = userId => |
| 8 | + usersFromServer.find(user => user.id === userId); |
| 9 | +export const findCommentsByPostId = postId => |
| 10 | + commentsFromServer.filter(comment => comment.postId === postId); |
| 11 | + |
| 12 | +export const posts = postsFromServer.map(post => ({ |
| 13 | + ...post, |
| 14 | + user: findUserById(post.userId), |
| 15 | + comments: findCommentsByPostId(post.id), |
| 16 | +})); |
6 | 17 |
|
7 | 18 | export const App = () => (
|
8 | 19 | <section className="App">
|
9 | 20 | <h1 className="App__title">Static list of posts</h1>
|
10 |
| - |
11 |
| - <div className="PostList"> |
12 |
| - <div className="PostInfo"> |
13 |
| - <div className="PostInfo__header"> |
14 |
| - <h3 className="PostInfo__title">qui est esse</h3> |
15 |
| - |
16 |
| - <p> |
17 |
| - {' Posted by '} |
18 |
| - |
19 |
| - <a className="UserInfo" href="mailto:[email protected]"> |
20 |
| - Leanne Graham |
21 |
| - </a> |
22 |
| - </p> |
23 |
| - </div> |
24 |
| - |
25 |
| - <p className="PostInfo__body"> |
26 |
| - est rerum tempore vitae sequi sint nihil reprehenderit dolor beatae ea |
27 |
| - dolores neque fugiat blanditiis voluptate porro vel nihil molestiae ut |
28 |
| - reiciendis qui aperiam non debitis possimus qui neque nisi nulla |
29 |
| - </p> |
30 |
| - |
31 |
| - <hr /> |
32 |
| - |
33 |
| - <b data-cy="NoCommentsMessage">No comments yet</b> |
34 |
| - </div> |
35 |
| - |
36 |
| - <div className="PostInfo"> |
37 |
| - <div className="PostInfo__header"> |
38 |
| - <h3 className="PostInfo__title">doloremque illum aliquid sunt</h3> |
39 |
| - |
40 |
| - <p> |
41 |
| - {' Posted by '} |
42 |
| - |
43 |
| - <a className="UserInfo" href="mailto:[email protected]"> |
44 |
| - Patricia Lebsack |
45 |
| - </a> |
46 |
| - </p> |
47 |
| - </div> |
48 |
| - |
49 |
| - <p className="PostInfo__body"> |
50 |
| - deserunt eos nobis asperiores et hic est debitis repellat molestiae |
51 |
| - optio nihil ratione ut eos beatae quibusdam distinctio maiores earum |
52 |
| - voluptates et aut adipisci ea maiores voluptas maxime |
53 |
| - </p> |
54 |
| - |
55 |
| - <div className="CommentList"> |
56 |
| - <div className="CommentInfo"> |
57 |
| - <div className="CommentInfo__title"> |
58 |
| - <strong className="CommentInfo__name">pariatur omnis in</strong> |
59 |
| - |
60 |
| - {' by '} |
61 |
| - |
62 |
| - <a |
63 |
| - className="CommentInfo__email" |
64 |
| - |
65 |
| - > |
66 |
| - |
67 |
| - </a> |
68 |
| - </div> |
69 |
| - |
70 |
| - <div className="CommentInfo__body"> |
71 |
| - dolorum voluptas laboriosam quisquam ab totam beatae et aut |
72 |
| - aliquid optio assumenda voluptas velit itaque quidem voluptatem |
73 |
| - tempore cupiditate in itaque sit molestiae minus dolores magni |
74 |
| - </div> |
75 |
| - </div> |
76 |
| - |
77 |
| - <div className="CommentInfo"> |
78 |
| - <div className="CommentInfo__title"> |
79 |
| - <strong className="CommentInfo__name"> |
80 |
| - odio adipisci rerum aut animi |
81 |
| - </strong> |
82 |
| - |
83 |
| - {' by '} |
84 |
| - |
85 |
| - <a |
86 |
| - className="CommentInfo__email" |
87 |
| - |
88 |
| - > |
89 |
| - |
90 |
| - </a> |
91 |
| - </div> |
92 |
| - |
93 |
| - <div className="CommentInfo__body"> |
94 |
| - quia molestiae reprehenderit quasi aspernatur aut expedita |
95 |
| - occaecati aliquam eveniet laudantium omnis quibusdam delectus |
96 |
| - saepe quia accusamus maiores nam est cum et ducimus et vero |
97 |
| - voluptates excepturi deleniti ratione |
98 |
| - </div> |
99 |
| - </div> |
100 |
| - </div> |
101 |
| - </div> |
102 |
| - </div> |
| 21 | + <PostList posts={posts} /> |
103 | 22 | </section>
|
104 | 23 | );
|
0 commit comments