Skip to content

Commit

Permalink
add solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Olifan committed Feb 15, 2025
1 parent 9de0191 commit ac2d656
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 130 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ This task is similar to [Static List of TODOs](https://github.com/mate-academy/r
- Install Prettier Extention and use this [VSCode settings](https://mate-academy.github.io/fe-program/tools/vscode/settings.json) to enable format on save.
- Implement a solution following the [React task guideline](https://github.com/mate-academy/react_task-guideline#react-tasks-guideline).
- Open one more terminal and run tests with `npm test` to ensure your solution is correct.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://<your_account>.github.io/react_static-list-of-posts-js/) and add it to the PR description.
- Replace `<your_account>` with your Github username in the [DEMO LINK](https://olifan.github.io/react_static-list-of-posts-js/) and add it to the PR description.
114 changes: 19 additions & 95 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,104 +1,28 @@
import './App.scss';

// import postsFromServer from './api/posts.json';
// import commentsFromServer from './api/comments.json';
// import usersFromServer from './api/users.json';
import commentsFromServer from './api/comments.json';
import postsFromServer from './api/posts.json';
import usersFromServer from './api/users.json';

export const App = () => (
<section className="App">
<h1 className="App__title">Static list of posts</h1>

<div className="PostList">
<div className="PostInfo">
<div className="PostInfo__header">
<h3 className="PostInfo__title">qui est esse</h3>

<p>
{' Posted by '}

<a className="UserInfo" href="mailto:[email protected]">
Leanne Graham
</a>
</p>
</div>

<p className="PostInfo__body">
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
</p>

<hr />

<b data-cy="NoCommentsMessage">No comments yet</b>
</div>

<div className="PostInfo">
<div className="PostInfo__header">
<h3 className="PostInfo__title">doloremque illum aliquid sunt</h3>
import { PostList } from './components/PostList/PostList';

<p>
{' Posted by '}
function getCommentsByPostId(postId) {
return commentsFromServer.filter(comment => comment.postId === postId);
}

<a className="UserInfo" href="mailto:[email protected]">
Patricia Lebsack
</a>
</p>
</div>
function getUserById(userId) {
return usersFromServer.find(user => user.id === userId) || null;
}

<p className="PostInfo__body">
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
</p>
export const preparedPosts = postsFromServer.map(post => ({
...post,
user: getUserById(post.userId),
comments: getCommentsByPostId(post.id),
}));

<div className="CommentList">
<div className="CommentInfo">
<div className="CommentInfo__title">
<strong className="CommentInfo__name">pariatur omnis in</strong>

{' by '}

<a
className="CommentInfo__email"
href="mailto:[email protected]"
>
[email protected]
</a>
</div>

<div className="CommentInfo__body">
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
</div>
</div>

<div className="CommentInfo">
<div className="CommentInfo__title">
<strong className="CommentInfo__name">
odio adipisci rerum aut animi
</strong>

{' by '}

<a
className="CommentInfo__email"
href="mailto:[email protected]"
>
[email protected]
</a>
</div>

<div className="CommentInfo__body">
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
</div>
</div>
</div>
</div>
</div>
export const App = () => (
<section className="App">
<h1 className="App__title">Static list of posts</h1>
<PostList posts={preparedPosts} />
</section>
);
29 changes: 0 additions & 29 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 15 additions & 1 deletion src/components/CommentInfo/CommentInfo.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
export const CommentInfo = () => <>Put the comment here</>;
export const CommentInfo = ({ comment }) => (
<div className="CommentInfo">
<div className="CommentInfo__title">
<strong className="CommentInfo__name">{comment.name}</strong>

{' by '}

<a className="CommentInfo__email" href={`mailto:${comment.email}`}>
{comment.email}
</a>
</div>

<div className="CommentInfo__body">{comment.body}</div>
</div>
);
11 changes: 10 additions & 1 deletion src/components/CommentList/CommentList.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export const CommentList = () => <>Put the list here</>;
import { CommentInfo } from '../CommentInfo/CommentInfo';
import './CommentList.scss';

export const CommentList = ({ comments }) => (
<div className="CommentList">
{comments.map(comment => (
<CommentInfo key={comment.id} comment={comment} />
))}
</div>
);
7 changes: 7 additions & 0 deletions src/components/CommentList/CommentList.scss
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// add styles here
.CommentList {
display: flex;
flex-direction: column;
gap: 0.7em;
background-color: #eee;
padding: 1em;
}
27 changes: 26 additions & 1 deletion src/components/PostInfo/PostInfo.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
export const PostInfo = () => <>Put the post here</>;
import { CommentList } from '../CommentList/CommentList';
import { UserInfo } from '../UserInfo/UserInfo';
import './PostInfo.scss';

export const PostInfo = ({ post }) => (
<div className="PostInfo">
<div className="PostInfo__header">
<h3 className="PostInfo__title">{post.title}</h3>

<p>
{' Posted by '}
<UserInfo user={post.user} />
</p>
</div>

<p className="PostInfo__body">{post.body}</p>

<hr />

{post.comments.length > 0 ? (
<CommentList comments={post.comments} />
) : (
<b data-cy="NoCommentsMessage">No comments yet</b>
)}
</div>
);
16 changes: 16 additions & 0 deletions src/components/PostInfo/PostInfo.scss
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
// 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;
}
}
10 changes: 9 additions & 1 deletion src/components/PostList/PostList.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export const PostList = () => <>Put the list here</>;
import { PostInfo } from '../PostInfo/PostInfo';

export const PostList = ({ posts }) => (
<div className="PostList">
{posts.map(post => (
<PostInfo key={post.id} post={post} />
))}
</div>
);
8 changes: 7 additions & 1 deletion src/components/UserInfo/UserInfo.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export const UserInfo = () => <>Put the user here</>;
import './UserInfo.scss';

export const UserInfo = ({ user }) => (
<a className="UserInfo" href={`mailto:${user.email}`}>
{user.name}
</a>
);
3 changes: 3 additions & 0 deletions src/components/UserInfo/UserInfo.scss
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// add styles here
.UserInfo {
font-weight: bold;
}

0 comments on commit ac2d656

Please sign in to comment.