-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Task solution #2021
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
base: master
Are you sure you want to change the base?
Task solution #2021
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,3 +1,20 @@ | ||
| import React from 'react'; | ||
| import { Comment } from '../Types/Comments'; | ||
|
|
||
| export const CommentInfo: React.FC = () => <>Put the comment here</>; | ||
| export const CommentInfo: React.FC<{ comment: Comment }> = ({ 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 +1,8 @@ | ||
| // 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,3 +1,26 @@ | ||
| /* eslint-disable max-len */ | ||
| import React from 'react'; | ||
| import '../CommentList/CommentList.scss'; | ||
|
|
||
| export const CommentList: React.FC = () => <>Put the list here</>; | ||
| import { Comment } from '../Types/Comments'; | ||
| import { CommentInfo } from '../CommentInfo'; | ||
|
|
||
| export const CommentList: React.FC<{ comments: Comment[] }> = ({ | ||
| comments, | ||
| }) => { | ||
| return ( | ||
| <div className="CommentList"> | ||
| {comments.length > 0 ? ( | ||
| comments.map(comment => ( | ||
| <CommentInfo key={comment.id} comment={comment} /> | ||
| )) | ||
| ) : ( | ||
| <> | ||
| <hr /> | ||
|
|
||
| <b data-cy="NoCommentsMessage">No comments yet</b> | ||
| </> | ||
|
Comment on lines
+18
to
+22
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. Avoid using a React fragment ( |
||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
| 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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,24 @@ | ||
| import React from 'react'; | ||
| import '../PostInfo/PostInfo.scss'; | ||
|
|
||
| export const PostInfo: React.FC = () => <>Put the post here</>; | ||
| import { Post } from '../Types/Posts'; | ||
| import { CommentList } from '../CommentList'; | ||
| import { UserInfo } from '../UserInfo'; | ||
|
|
||
| export const PostInfo: React.FC<{ post: Post }> = ({ post }) => { | ||
| return ( | ||
| <> | ||
| <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> | ||
| <CommentList comments={post.comments} /> | ||
| </div> | ||
| </> | ||
|
Comment on lines
+10
to
+22
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. Avoid using a React fragment ( |
||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| import React from 'react'; | ||
| import { Post } from '../Types/Posts'; | ||
| import { PostInfo } from '../PostInfo'; | ||
|
|
||
| export const PostList: React.FC = () => <>Put the list here</>; | ||
| export const PostList: React.FC<{ posts: Post[] }> = ({ posts }) => { | ||
| return ( | ||
| <> | ||
| {posts.map(post => ( | ||
| <PostInfo key={post.id} post={post} /> | ||
| ))} | ||
| </> | ||
|
Comment on lines
+7
to
+11
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. Avoid using a React fragment ( |
||
| ); | ||
| }; | ||
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { User } from './Users'; | ||
| import { Comment } from './Comments'; | ||
|
|
||
| export interface Post { | ||
| userId: number; | ||
| id: number; | ||
| title: string; | ||
| body: string; | ||
| user: User; | ||
| comments: Comment[]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export interface User { | ||
| id: number; | ||
| name: string; | ||
| email: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| // add styles here | ||
| .UserInfo { | ||
| font-weight: bold; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| import React from 'react'; | ||
| import '../UserInfo/UserInfo.scss'; | ||
| import { User } from '../Types/Users'; | ||
|
|
||
| export const UserInfo: React.FC = () => <>Put the user here</>; | ||
| export const UserInfo: React.FC<{ user: User }> = ({ user }) => { | ||
| return ( | ||
| <a className="UserInfo" href={`mailto:${user.email}`}> | ||
| {user.name} | ||
| </a> | ||
| ); | ||
| }; |
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.
The function
getUsershould be renamed togetUserByIdto clearly indicate that it retrieves a user by their ID. This aligns with the checklist item: "If you are searching some entity by some filter, specify it in function/method name".