-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
static-list resolving #1391
base: master
Are you sure you want to change the base?
static-list resolving #1391
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = () => ( | ||
<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> | ||
export const posts = postsFromServer.map(post => { | ||
return { | ||
...post, | ||
user: getUserById(post.userId), | ||
comments: commentsFromServer.filter(comment => comment.postId === post.id) | ||
} | ||
}) | ||
|
||
<p> | ||
{' Posted by '} | ||
console.log(posts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to delete |
||
|
||
<a className="UserInfo" href="mailto:[email protected]"> | ||
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:[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> | ||
{posts.map(post => { | ||
return ( | ||
<PostList post={post} key={post.id}/> | ||
) | ||
})} | ||
</section> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
export const CommentInfo = () => <>Put the comment here</>; | ||
export const CommentInfo = ({ comment }) => { | ||
return ( | ||
<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> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
// add styles here | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<> | ||
<hr /> | ||
|
||
<b data-cy="NoCommentsMessage">No comments yet</b> | ||
</> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="CommentList"> | ||
{comments.map(comment => ( | ||
<CommentInfo key={comment.id} comment={comment} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
// add styles here | ||
.CommentList { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.7em; | ||
background-color: #eee; | ||
padding: 1em; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className="PostInfo"> | ||
<div className="PostInfo__header"> | ||
<h3 className="PostInfo__title">{title}</h3> | ||
|
||
<p> | ||
{' Posted by '} | ||
|
||
<UserInfo user={user}/> | ||
</p> | ||
</div> | ||
|
||
<p className="PostInfo__body"> | ||
{post.body} | ||
</p> | ||
|
||
<CommentList comments={comments}/> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
export const PostList = () => <>Put the list here</>; | ||
import { PostInfo } from '../PostInfo' | ||
|
||
export const PostList = ({ post }) => { | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The component name |
||
<div className="PostList"> | ||
{post && ( | ||
<PostInfo post={post}/> | ||
)} | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
export const UserInfo = () => <>Put the user here</>; | ||
import './UserInfo.scss' | ||
|
||
export const UserInfo = ({ user }) => { | ||
if (user === null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<a className="UserInfo" href={`mailto:${user.email}`}> | ||
{user.name} | ||
</a> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
// add styles here | ||
.UserInfo { | ||
font-weight: bold; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good practice to add a semicolon at the end of import statements to avoid potential issues in environments that require semicolons.