-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db36ad5
commit 43b1eed
Showing
14 changed files
with
187 additions
and
147 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,33 @@ | ||
import React from 'react'; | ||
|
||
import './App.scss'; | ||
import { PostList } from './components/PostList'; | ||
|
||
// import postsFromServer from './api/posts'; | ||
// import commentsFromServer from './api/comments'; | ||
// import usersFromServer from './api/users'; | ||
|
||
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 /> | ||
import postsFromServer from './api/posts'; | ||
import commentsFromServer from './api/comments'; | ||
import usersFromServer from './api/users'; | ||
import { Comment, Post, User } from './types'; | ||
|
||
<b data-cy="NoCommentsMessage">No comments yet</b> | ||
</div> | ||
function getUser(userId: number): User | null { | ||
const foundUser = usersFromServer.find(user => user.id === userId); | ||
|
||
<div className="PostInfo"> | ||
<div className="PostInfo__header"> | ||
<h3 className="PostInfo__title"> | ||
doloremque illum aliquid sunt | ||
</h3> | ||
return foundUser || null; | ||
} | ||
|
||
<p> | ||
{' Posted by '} | ||
function getComments(id: number): Comment[] { | ||
const foundComments = commentsFromServer | ||
.filter(comment => comment.postId === id); | ||
|
||
<a className="UserInfo" href="mailto:[email protected]"> | ||
Patricia Lebsack | ||
</a> | ||
</p> | ||
</div> | ||
return foundComments; | ||
} | ||
|
||
<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> | ||
const posts: Post[] = postsFromServer.map(post => ({ | ||
...post, | ||
user: getUser(post.userId), | ||
comments: getComments(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={posts} /> | ||
</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,5 +1,30 @@ | ||
import React from 'react'; | ||
import { Comment } from '../../types'; | ||
|
||
export const CommentInfo: React.FC = () => ( | ||
<>Put the comment here</> | ||
); | ||
interface Props { | ||
comment: Comment; | ||
} | ||
|
||
export const CommentInfo = ({ comment }: Props) => { | ||
const { name, email, body } = comment; | ||
|
||
return ( | ||
<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,7 @@ | ||
// 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,5 +1,15 @@ | ||
import React from 'react'; | ||
import { CommentInfo } from '../CommentInfo'; | ||
import { Comment } from '../../types'; | ||
import './CommentList.scss'; | ||
|
||
export const CommentList: React.FC = () => ( | ||
<>Put the list here</> | ||
interface Props { | ||
comments: Comment[]; | ||
} | ||
|
||
export const CommentList = ({ comments }: Props) => ( | ||
<div className="CommentList"> | ||
{comments.map(comment => ( | ||
<CommentInfo key={comment.id} comment={comment} /> | ||
))} | ||
</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,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; | ||
} | ||
} |
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,5 +1,42 @@ | ||
import React from 'react'; | ||
import './PostInfo.scss'; | ||
import { CommentList } from '../CommentList'; | ||
import { UserInfo } from '../UserInfo'; | ||
import { Post } from '../../types'; | ||
|
||
export const PostInfo: React.FC = () => ( | ||
<>Put the post here</> | ||
interface Props { | ||
post: Post; | ||
} | ||
|
||
export const PostInfo = ({ | ||
post: { | ||
title, | ||
user, | ||
userId, | ||
body, | ||
comments, | ||
}, | ||
} : Props) => ( | ||
<div className="PostInfo"> | ||
<div className="PostInfo__header"> | ||
<h3 className="PostInfo__title"> | ||
{title} | ||
</h3> | ||
|
||
{user && <UserInfo key={userId} user={user} />} | ||
</div> | ||
|
||
<p className="PostInfo__body"> | ||
{body} | ||
</p> | ||
|
||
{comments.length | ||
? <CommentList comments={comments} /> | ||
: ( | ||
<> | ||
<hr /> | ||
<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,5 +1,17 @@ | ||
import React from 'react'; | ||
import { Post } from '../../types'; | ||
import { PostInfo } from '../PostInfo'; | ||
|
||
export const PostList: React.FC = () => ( | ||
<>Put the list here</> | ||
interface Props { | ||
posts: Post[]; | ||
} | ||
|
||
export const PostList = ({ posts } : Props) => ( | ||
<div className="PostList"> | ||
{posts.map(post => ( | ||
<PostInfo | ||
key={post.id} | ||
post={post} | ||
/> | ||
))} | ||
</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,3 @@ | ||
// 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,5 +1,16 @@ | ||
import React from 'react'; | ||
import { User } from '../../types'; | ||
import './UserInfo.scss'; | ||
|
||
export const UserInfo: React.FC = () => ( | ||
<>Put the user here</> | ||
interface Props { | ||
user: User; | ||
} | ||
|
||
export const UserInfo = ({ user }: Props) => ( | ||
<p> | ||
{' Posted by '} | ||
|
||
<a className="UserInfo" href={`mailto:${user.email}`}> | ||
{user.name} | ||
</a> | ||
</p> | ||
); |
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 { Comment } from './Comment'; | ||
import { User } from './User'; | ||
|
||
export interface Post { | ||
userId: number, | ||
id: number, | ||
title: string, | ||
body: string, | ||
user: User | null, | ||
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, | ||
} |
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,3 @@ | ||
export * from './Comment'; | ||
export * from './Post'; | ||
export * from './User'; |