-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Showing
24 changed files
with
627 additions
and
389 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,3 @@ | |
} | ||
} | ||
} | ||
|
||
.message-body { | ||
white-space: pre-line; | ||
} |
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,60 +1,98 @@ | ||
import classNames from 'classnames'; | ||
|
||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
import { useState } from 'react'; | ||
import cn from 'classnames'; | ||
import './App.scss'; | ||
|
||
import { User, Post } from './types'; | ||
import { getPosts } from './services'; | ||
|
||
import { PostsList } from './components/PostsList'; | ||
import { PostDetails } from './components/PostDetails'; | ||
import { UserSelector } from './components/UserSelector'; | ||
import { Loader } from './components/Loader'; | ||
|
||
export const App = () => ( | ||
<main className="section"> | ||
<div className="container"> | ||
<div className="tile is-ancestor"> | ||
<div className="tile is-parent"> | ||
<div className="tile is-child box is-success"> | ||
<div className="block"> | ||
<UserSelector /> | ||
</div> | ||
export const App = () => { | ||
const [selectedUser, setSelectedUser] = useState<User | null>(null); | ||
const [posts, setPosts] = useState<Post[]>([]); | ||
const [hasPostsLoadingError, setHasPostsLoadingError] = useState(false); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [selectedPost, setSelectedPost] = useState<Post | null>(null); | ||
|
||
<div className="block" data-cy="MainContent"> | ||
<p data-cy="NoSelectedUser">No user selected</p> | ||
const showNoPostsYet = | ||
!!selectedUser && !isLoading && !hasPostsLoadingError && !posts.length; | ||
|
||
<Loader /> | ||
const showPostList = | ||
!!selectedUser && !isLoading && !hasPostsLoadingError && !!posts.length; | ||
|
||
<div | ||
className="notification is-danger" | ||
data-cy="PostsLoadingError" | ||
> | ||
Something went wrong! | ||
</div> | ||
const handleLoadPosts = (userId: User['id']) => { | ||
setIsLoading(true); | ||
setHasPostsLoadingError(false); | ||
setSelectedPost(null); | ||
|
||
getPosts(userId) | ||
.then(setPosts) | ||
.catch(() => setHasPostsLoadingError(true)) | ||
.finally(() => setIsLoading(false)); | ||
}; | ||
|
||
<div className="notification is-warning" data-cy="NoPostsYet"> | ||
No posts yet | ||
return ( | ||
<main className="section"> | ||
<div className="container"> | ||
<div className="tile is-ancestor"> | ||
<div className="tile is-parent"> | ||
<div className="tile is-child box is-success"> | ||
<div className="block"> | ||
<UserSelector | ||
selectedUser={selectedUser} | ||
onSelectedUser={setSelectedUser} | ||
onLoadPosts={handleLoadPosts} | ||
/> | ||
</div> | ||
|
||
<PostsList /> | ||
<div className="block" data-cy="MainContent"> | ||
{!selectedUser && ( | ||
<p data-cy="NoSelectedUser">No user selected</p> | ||
)} | ||
|
||
{isLoading && <Loader />} | ||
|
||
{hasPostsLoadingError && ( | ||
<div | ||
className="notification is-danger" | ||
data-cy="PostsLoadingError" | ||
> | ||
Something went wrong! | ||
</div> | ||
)} | ||
|
||
{showNoPostsYet && ( | ||
<div className="notification is-warning" data-cy="NoPostsYet"> | ||
No posts yet | ||
</div> | ||
)} | ||
|
||
{showPostList && ( | ||
<PostsList | ||
posts={posts} | ||
selectedPost={selectedPost} | ||
onSelectedPost={setSelectedPost} | ||
/> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div | ||
data-cy="Sidebar" | ||
className={classNames( | ||
'tile', | ||
'is-parent', | ||
'is-8-desktop', | ||
'Sidebar', | ||
'Sidebar--open', | ||
)} | ||
> | ||
<div className="tile is-child box is-success "> | ||
<PostDetails /> | ||
<div | ||
data-cy="Sidebar" | ||
className={cn('tile is-parent is-8-desktop Sidebar', { | ||
'Sidebar--open': !!selectedPost, | ||
})} | ||
> | ||
<div className="tile is-child box is-success "> | ||
{!!selectedPost && <PostDetails post={selectedPost} />} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
</main> | ||
); | ||
}; |
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,37 @@ | ||
import { FC } from 'react'; | ||
import { Comment } from '../../types'; | ||
|
||
interface Props { | ||
comments: Comment[]; | ||
onDeleteComment: (commentId: Comment['id']) => void; | ||
} | ||
|
||
export const CommentsList: FC<Props> = ({ comments, onDeleteComment }) => { | ||
return ( | ||
<> | ||
<p className="title is-4">Comments:</p> | ||
|
||
{comments.map(({ id, email, name, body }) => ( | ||
<article key={id} className="message is-small" data-cy="Comment"> | ||
<div className="message-header"> | ||
<a href={`mailto:${email}`} data-cy="CommentAuthor"> | ||
{name} | ||
</a> | ||
|
||
<button | ||
data-cy="CommentDelete" | ||
type="button" | ||
className="delete is-small" | ||
aria-label="delete" | ||
onClick={() => onDeleteComment(id)} | ||
/> | ||
</div> | ||
|
||
<div className="message-body" data-cy="CommentBody"> | ||
{body} | ||
</div> | ||
</article> | ||
))} | ||
</> | ||
); | ||
}; |
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 @@ | ||
export * from './CommentsList'; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.