-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
task solution #2017
Open
W3zzie
wants to merge
2
commits into
mate-academy:master
Choose a base branch
from
W3zzie:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
task solution #2017
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,104 +2,38 @@ import React from 'react'; | |
|
||
import './App.scss'; | ||
|
||
// import postsFromServer from './api/posts'; | ||
// import commentsFromServer from './api/comments'; | ||
// import usersFromServer from './api/users'; | ||
import postsFromServer from './api/posts'; | ||
import commentsFromServer from './api/comments'; | ||
import usersFromServer from './api/users'; | ||
import { PostList } from './components/PostList'; | ||
import { type Post } from './types/Post'; | ||
import { type User } from './types/User'; | ||
import { Comment } from './types/Comment'; | ||
|
||
const getCommentsByPostId = (postId: Post['id']): Comment[] => { | ||
return commentsFromServer.filter( | ||
(comment: Comment) => comment.postId === postId, | ||
); | ||
}; | ||
|
||
const getUserById = (userId: User['id']): User | undefined => { | ||
return usersFromServer.find((user: User) => user.id === userId); | ||
}; | ||
|
||
const posts: Post[] = postsFromServer.map(post => { | ||
return { | ||
...post, | ||
user: getUserById(post.userId), | ||
comments: getCommentsByPostId(post.id), | ||
}; | ||
}); | ||
|
||
export const App: React.FC = () => ( | ||
<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> | ||
|
||
<p> | ||
{' Posted by '} | ||
|
||
<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 className="PostList"> | ||
<PostList posts={posts} /> | ||
</div> | ||
</div> | ||
</section> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
import React from 'react'; | ||
import { Comment } from '../../types/Comment'; | ||
|
||
export const CommentInfo: React.FC = () => <>Put the comment here</>; | ||
export const CommentInfo: React.FC<{ comment: Comment }> = ({ | ||
comment: { name, email, body }, | ||
}) => ( | ||
<div className="CommentInfo"> | ||
<div className="CommentInfo__title"> | ||
<strong className="CommentInfo__name">{name}</strong> | ||
|
||
{' by '} | ||
|
||
<a className="CommentInfo__email" href={`mailto:${email}`}> | ||
{email} | ||
</a> | ||
</div> | ||
|
||
<div className="CommentInfo__body">{body}</div> | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
import React from 'react'; | ||
import './CommentList.scss'; | ||
import { type Comment } from '../../types/Comment'; | ||
import { CommentInfo } from '../CommentInfo'; | ||
|
||
export const CommentList: React.FC = () => <>Put the list here</>; | ||
export const CommentList: React.FC<{ comments: Comment[] }> = ({ | ||
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. Once you declare the type interface and once you do not, stay consistent with your approach. |
||
comments, | ||
}) => ( | ||
<div className="CommentList"> | ||
{comments.map((comment: Comment) => ( | ||
<CommentInfo comment={comment} key={comment.id} /> | ||
))} | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import React from 'react'; | ||
import './PostInfo.scss'; | ||
import { type Post } from '../../types/Post'; | ||
import { CommentList } from '../CommentList'; | ||
import { UserInfo } from '../UserInfo'; | ||
|
||
export const PostInfo: React.FC = () => <>Put the post here</>; | ||
interface Props { | ||
post: Post; | ||
} | ||
|
||
export const PostInfo: React.FC<Props> = ({ post }) => { | ||
|
||
return ( | ||
<div className="PostInfo"> | ||
<div className="PostInfo__header"> | ||
<h3 className="PostInfo__title">{post.title}</h3> | ||
|
||
<p> | ||
{' Posted by '} | ||
|
||
{post.user && <UserInfo user={post.user} />} | ||
</p> | ||
</div> | ||
|
||
<p className="PostInfo__body">{post.body}</p> | ||
|
||
<hr /> | ||
|
||
{!!post.comments?.length ? ( | ||
<CommentList comments={post.comments} /> | ||
) : ( | ||
<b data-cy="NoCommentsMessage">No comments yet</b> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import React from 'react'; | ||
import { PostInfo } from '../PostInfo'; | ||
import { type Post } from '../../types/Post'; | ||
|
||
export const PostList: React.FC = () => <>Put the list here</>; | ||
interface Props { | ||
posts: Post[]; | ||
} | ||
|
||
export const PostList: React.FC<Props> = ({ posts }) => { | ||
return posts.map((post: Post) => <PostInfo post={post} key={post.id} />); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
// add styles here | ||
.UserInfo { | ||
font-weight: bold; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
import React from 'react'; | ||
import './UserInfo.scss'; | ||
import { type User } from '../../types/User'; | ||
|
||
export const UserInfo: React.FC = () => <>Put the user here</>; | ||
interface Props { | ||
user: User | undefined; | ||
} | ||
|
||
export const UserInfo: React.FC<Props> = ({ user }) => ( | ||
<a className="UserInfo" href={`mailto:${user?.email}`}> | ||
{user?.name} | ||
</a> | ||
); | ||
Comment on lines
+9
to
+13
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. Destructure user object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface Comment { | ||
postId: number; | ||
id: number; | ||
name: string; | ||
email: string; | ||
body: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { type Comment } from './Comment'; | ||
import { type User } from './User'; | ||
|
||
export interface Post { | ||
userId: number; | ||
id: number; | ||
title: string; | ||
body: string; | ||
user?: User; | ||
comments: Comment[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface User { | ||
id: number; | ||
name: string; | ||
username: string; | ||
email: string; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Here is an article on why you shouldn't use React.FC https://dev.to/elhamnajeebullah/react-typescript-what-is-reactfc-and-why-should-i-use-it-4029