-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Solution #1186
base: master
Are you sure you want to change the base?
Solution #1186
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 |
---|---|---|
|
@@ -18,6 +18,35 @@ | |
} | ||
} | ||
|
||
.tile { | ||
align-items: stretch; | ||
min-height: min-content; | ||
flex: 1 1 0; | ||
Comment on lines
+21
to
+24
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 |
||
|
||
&.is-ancestor { | ||
margin-left: -0.75rem; | ||
margin-right: -0.75rem; | ||
margin-top: -0.75rem; | ||
|
||
&:last-child { | ||
margin-bottom: -0.75rem; | ||
} | ||
} | ||
|
||
@media (min-width: 769px) { | ||
&:not(.is-child) { | ||
display: flex; | ||
} | ||
} | ||
} | ||
|
||
.message-body { | ||
white-space: pre-line; | ||
} | ||
|
||
.container { | ||
flex-grow: 1; | ||
margin: 0 auto; | ||
position: relative; | ||
width: auto; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,103 @@ | ||
import classNames from 'classnames'; | ||
|
||
/* eslint-disable @typescript-eslint/indent */ | ||
import 'bulma/css/bulma.css'; | ||
import '@fortawesome/fontawesome-free/css/all.css'; | ||
import cn from 'classnames'; | ||
import './App.scss'; | ||
|
||
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> | ||
import { PostsList, PostDetails, UserSelector, Loader } from './components'; | ||
import { User } from './types'; | ||
import { usePosts, useUsers } from './hooks'; | ||
|
||
<div className="block" data-cy="MainContent"> | ||
<p data-cy="NoSelectedUser">No user selected</p> | ||
export const App = () => { | ||
const { | ||
users, | ||
errorMessage: usersErrorMessage, | ||
selectedUser, | ||
setSelectedUser, | ||
} = useUsers(); | ||
const { | ||
posts, | ||
selectedPost, | ||
setSelectedPost, | ||
isLoading, | ||
errorMessage: postsErrorMessage, | ||
} = usePosts(selectedUser?.id); | ||
|
||
<Loader /> | ||
const errorMessage = usersErrorMessage || postsErrorMessage; | ||
|
||
<div | ||
className="notification is-danger" | ||
data-cy="PostsLoadingError" | ||
> | ||
Something went wrong! | ||
</div> | ||
const handleSelectUserId = (user: User) => { | ||
setSelectedUser(user); | ||
setSelectedPost(null); | ||
}; | ||
|
||
<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 | ||
users={users} | ||
selectedUser={selectedUser} | ||
onSelectUser={handleSelectUserId} | ||
/> | ||
</div> | ||
|
||
<PostsList /> | ||
<div className="block" data-cy="MainContent"> | ||
{!selectedUser && ( | ||
<p data-cy="NoSelectedUser">No user selected</p> | ||
)} | ||
|
||
{selectedUser && isLoading && <Loader />} | ||
|
||
{selectedUser && !isLoading && errorMessage && ( | ||
<div | ||
className="notification is-danger" | ||
data-cy="PostsLoadingError" | ||
> | ||
{errorMessage} | ||
</div> | ||
)} | ||
|
||
{selectedUser && | ||
!isLoading && | ||
!errorMessage && | ||
posts?.length === 0 && ( | ||
<div | ||
className="notification is-warning" | ||
data-cy="NoPostsYet" | ||
> | ||
No posts yet | ||
</div> | ||
)} | ||
|
||
{selectedUser && | ||
!isLoading && | ||
!errorMessage && | ||
posts?.length !== 0 && ( | ||
<PostsList | ||
posts={posts} | ||
selectedPost={selectedPost} | ||
onSelectPost={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, | ||
})} | ||
Comment on lines
+91
to
+93
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
Comment on lines
+91
to
+93
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 |
||
> | ||
<div className="tile is-child box is-success "> | ||
{selectedPost && <PostDetails selectedPost={selectedPost} />} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
</main> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Comment } from '../types/Comment'; | ||
import { client } from '../utils/fetchClient'; | ||
|
||
export const getComments = (postId: number) => { | ||
return client.get<Comment[]>(`/comments?postId=${postId}`); | ||
}; | ||
|
||
export const deleteComment = (commentId: number) => { | ||
return client.delete(`/comments/${commentId}`); | ||
}; | ||
|
||
export const addComment = (newComment: Omit<Comment, 'id'>) => { | ||
return client.post<Comment>('/comments', newComment); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Post } from '../types/Post'; | ||
import { client } from '../utils/fetchClient'; | ||
|
||
export const getUserPosts = (selectedUserId: number) => { | ||
return client.get<Post[]>(`/posts?userId=${selectedUserId}`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { User } from '../types/User'; | ||
import { client } from '../utils/fetchClient'; | ||
|
||
export const getUsers = () => { | ||
return client.get<User[]>('/users'); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { FC } from 'react'; | ||
|
||
import { Comment } from '../types'; | ||
|
||
type Props = { | ||
comment: Comment; | ||
onDelete: (commentId: number) => Promise<void>; | ||
}; | ||
|
||
export const CommentItem: FC<Props> = ({ comment, onDelete }) => { | ||
const { id, name, email, body } = comment; | ||
|
||
return ( | ||
<article 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={() => onDelete(id)} | ||
></button> | ||
</div> | ||
|
||
<div className="message-body" data-cy="CommentBody"> | ||
{body} | ||
</div> | ||
</article> | ||
); | ||
}; |
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.
Consider adding a comment or documentation for the
.tile
class to explain its purpose or usage, especially since it contains nested styles and media queries.