-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
add task test solution #2626
base: master
Are you sure you want to change the base?
add task test solution #2626
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.
Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the Loader
component is not being used correctly across the application, which affects the user experience by not indicating loading states properly. Additionally, ensure that the useEffect
hook dependencies are complete to prevent potential bugs. Once these issues are resolved, your code will be in great shape! Keep up the great work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/App.tsx
Outdated
@@ -22,13 +43,23 @@ export const App: React.FC = () => { | |||
|
|||
<div className="block"> | |||
<Loader /> |
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 Loader
component is always rendered, which might not be the intended behavior. Consider adding a loading state to conditionally render the Loader
only when the todos are being fetched.
<div className="modal-background" /> | ||
|
||
{true ? ( | ||
{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.
The condition for rendering the Loader
is hardcoded as false
. Consider using a state variable to dynamically control when the Loader
should be displayed, such as when the user data is being fetched.
|
||
useEffect(() => { | ||
getCurrentUser(); | ||
}, []); |
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 useEffect
hook should include todo.userId
in its dependency array to ensure that getCurrentUser
is called whenever the todo.userId
changes.
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.
Great job on implementing the Todo application using React! 🎉 While the code meets most of the task requirements, there are a few areas for improvement to enhance functionality and maintainability:
-
State Management: Avoid using the global
allTodos
variable. Instead, manage this state within the component using React's state management hooks to prevent potential side effects. -
Search Functionality: The search input and clear search button are currently not functional. Implement the necessary event handlers to filter todos based on the search query and reset the list when cleared.
-
Dynamic Class Management: Ensure the
classnames
library is correctly toggling between 'fa-eye' and 'fa-eye-slash' icons as intended. -
Error Handling: Add error handling to the
getCurrentUser
function to manage cases where user data cannot be fetched, improving the application's robustness. -
Conditional Rendering: Ensure user data is available before rendering the email link to prevent incomplete or broken links.
-
Key Prop Generation: Ensure that the
key
prop for each todo is a stable identifier, such astodo.id
, and not generated during render.
These improvements will help you create a more robust and maintainable application. Keep up the great work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
src/App.tsx
Outdated
completed: false, | ||
}; | ||
|
||
let allTodos: Todo[] = []; |
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.
Using a global variable allTodos
can lead to potential side effects and makes the code harder to maintain. Consider managing this state within the component using React's state management hooks.
src/App.tsx
Outdated
function getAllTodos() { | ||
getTodos() | ||
.then(resultTodos => { | ||
allTodos = resultTodos; | ||
setTodos(resultTodos); | ||
}) | ||
.finally(() => setLoading(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.
The getAllTodos
function directly modifies the global allTodos
variable. It's better to manage this state within the component to avoid unintended side effects and improve maintainability.
<input | ||
data-cy="searchInput" | ||
type="text" | ||
className="input" | ||
placeholder="Search..." | ||
/> |
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 search input is currently not functional. Consider implementing a function to filter todos based on the search query entered by the user.
<button | ||
data-cy="clearSearchButton" | ||
type="button" | ||
className="delete" | ||
/> |
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 clear search button is present but not functional. Implement an event handler to clear the search input and reset the todos list when this button is clicked.
className={cn('far', { | ||
'fa-eye': todo.id !== iconEyeId, | ||
'fa-eye-slash': todo.id === iconEyeId, | ||
})} |
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.
Ensure that the classnames
library is correctly managing the dynamic classes for the icons. Verify that the logic for toggling between 'fa-eye' and 'fa-eye-slash' is working as intended.
function getCurrentUser() { | ||
getUser(todo.userId) | ||
.then(setUser) | ||
.finally(() => setLoading(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.
Consider adding error handling to the getCurrentUser
function to manage cases where the user data cannot be fetched. This will improve the robustness of the application.
|
||
{' by '} | ||
|
||
<a href="mailto:[email protected]">Leanne Graham</a> | ||
<a 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.
Ensure that the user data is available before rendering the email link. You might want to add a conditional check to handle cases where user
is undefined to prevent rendering incomplete or broken links.
https://VictorKomara.github.io/react_dynamic-list-of-todos/