Skip to content

add task solution #1487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 3 additions & 95 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,104 +1,12 @@
import './App.scss';

// import postsFromServer from './api/posts.json';
// import commentsFromServer from './api/comments.json';
// import usersFromServer from './api/users.json';
import postsFromServer from './api/posts.json';
import { PostList } from './components/PostList';

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:Sincere@april.biz">
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>

<p>
{' Posted by '}

<a className="UserInfo" href="mailto:Julianne.OConner@kory.org">
Patricia Lebsack
</a>
</p>
</div>

<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>

<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:Telly_Lynch@karl.co.uk"
>
Telly_Lynch@karl.co.uk
</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:Nikita@garfield.biz"
>
Nikita@garfield.biz
</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>
<PostList posts={postsFromServer} />
</section>
);
29 changes: 0 additions & 29 deletions src/App.scss
Original file line number Diff line number Diff line change
@@ -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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use destructuring for comment

</div>

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

import { CommentInfo } from '../CommentInfo';

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;
}
36 changes: 35 additions & 1 deletion src/components/PostInfo/PostInfo.jsx
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
export const PostInfo = () => <>Put the post here</>;
import './PostInfo.scss';

import { UserInfo } from '../UserInfo';
import { CommentList } from '../CommentList';
import usersFromServer from '../../api/users.json';
import commentsFromServer from '../../api/comments.json';

export const PostInfo = ({ post }) => {
const foundUser = usersFromServer.find(user => user.id === post.userId);
const postComments = commentsFromServer.filter(
comment => comment.postId === post.id,
);
Comment on lines +9 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this logic to App component for fix failed tests


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use destructuring for post

<p>
{' Posted by '}

<UserInfo user={foundUser} />
</p>
</div>

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

{postComments.length > 0 ? (
<CommentList comments={postComments} />
) : (
<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';

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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use destructuring for user

);
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments

Suggested change
// add styles here

.UserInfo {
font-weight: bold;
}