-
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 #854
base: master
Are you sure you want to change the base?
Solution #854
Conversation
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.
Good job! There are things that should be fixed:
- try to fix empty fields with string.trim()
src/App.tsx
Outdated
const [selectedUser, setSelectedUser] = useState<User | null>(null); | ||
const [posts, setPosts] = useState<Post[] | null>(null); | ||
const [currentPost, setCurrentPost] = useState<Post | null>(null); | ||
const [loadingPosts, setLoadingPosts] = useState(false); |
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.
Fix it everywhere with tips on naming boolean variables
const [loadingPosts, setLoadingPosts] = useState(false); | |
const [isLoadingPosts, setIsLoadingPosts] = useState(false); |
src/App.tsx
Outdated
async function fetchUsers() { | ||
const data = await client.get<User[]>('/users'); | ||
|
||
setUsers(data); | ||
} |
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.
Move this function out from useEffect
src/App.tsx
Outdated
const addComment = async ({ | ||
postId, name, email, body, | ||
}: CommentData) => { |
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.
const addComment = async ({ | |
postId, name, email, body, | |
}: CommentData) => { | |
const addComment = async ({ | |
postId, | |
name, | |
email, | |
body, | |
}: CommentData) => { |
src/App.tsx
Outdated
|
||
return [response]; | ||
}); | ||
} catch (error: any) { |
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.
src/components/PostDetails.tsx
Outdated
{!loadingComments && comments && comments.length > 0 && ( | ||
<p className="title is-4">Comments:</p>)} | ||
{comments && comments.length > 0 && !loadingComments && comments.map( | ||
comment => ( |
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.
Destructure comment
src/components/PostsList.tsx
Outdated
voluptate et itaque vero tempora molestiae | ||
</td> | ||
<tbody> | ||
{posts && posts.map(post => ( |
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.
Destructure post
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.
destructure post
Still not resolved
src/components/UserSelector.tsx
Outdated
<a | ||
href={`#user-${user.id}`} | ||
key={user.id} | ||
className={`dropdown-item ${selectedUser && selectedUser.id === user.id ? 'is-active' : ''}`} |
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.
Use classnames library to add classes conditionally
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.
Almost good!
wasn't able to test your work because of server error, could you rerequest review please when it'll be fixed?
src/App.tsx
Outdated
<div className="notification is-warning" data-cy="NoPostsYet"> | ||
No posts yet | ||
</div> | ||
{posts && posts.length === 0 && ( |
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.
{posts && posts.length === 0 && ( | |
{posts && !posts.length && ( |
src/components/PostsList.tsx
Outdated
voluptate et itaque vero tempora molestiae | ||
</td> | ||
<tbody> | ||
{posts && posts.map(post => ( |
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.
destructure post
Still not resolved
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.
Good job!
https://VadymTsyndra.github.io/react_dynamic-list-of-posts