-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 solution #2719
base: master
Are you sure you want to change the base?
add task solution #2719
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 pull request! 😊 While your implementation is mostly on the right track, there are a few critical issues that need to be addressed to fully meet the task requirements:
-
Error Handling in
getUser
Function: Ensure that the function handles errors gracefully, providing feedback to the user if user data cannot be fetched. -
Type Casting in
TodoFilter.tsx
: Validate the value before casting toOptionType
to avoid potential runtime errors. -
Search Input Filtering: Make sure the
searchInput
is used to filter todos by title, as required by the task. -
Loader Component Usage: Ensure the
Loader
is displayed while waiting for todos to be fetched from the server.
Please address these issues to ensure the functionality and requirements are fully met. Keep up the great work, and feel free to reach out if you need any help! 🚀
✨ 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
useEffect(() => { | ||
const fetchData = async () => { | ||
setListLoading(true); | ||
const todosDb = await getTodos(); | ||
|
||
setTodos(todosDb); | ||
setListLoading(false); | ||
}; | ||
|
||
fetchData(); | ||
}, []); |
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 the Loader
component is displayed while waiting for the todos to be fetched. This aligns with the task requirement to show the Loader
when waiting for any data from the server .
src/App.tsx
Outdated
useEffect(() => { | ||
let filtered = todos; | ||
|
||
switch (option) { | ||
case 'active': | ||
filtered = todos.filter(todo => !todo.completed); | ||
break; | ||
case 'completed': | ||
filtered = todos.filter(todo => todo.completed); | ||
break; | ||
default: | ||
filtered = todos; | ||
} | ||
|
||
setFilteredTodos(filtered); | ||
}, [option, todos]); |
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 filtering logic based on the option
state is correct. However, ensure that the searchInput
is also used to filter the todos by title, as required by the task .
<span className="select"> | ||
<select | ||
data-cy="statusSelect" | ||
onChange={e => setOption(e.currentTarget.value as OptionType)} |
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 type casting of e.currentTarget.value
to OptionType
is safe. Consider validating the value before casting to avoid potential runtime errors if the value is not one of the expected OptionType
values.
const user = await getUser(todo.userId); | ||
|
||
setLoading(false); | ||
setCurrentUser(user); |
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 getUser
function handles errors gracefully. Consider adding error handling to manage cases where the user data cannot be fetched, and provide feedback to the user if necessary.
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 work on implementing the main functionality of your application! 🎉 While the overall structure is solid, there are a few critical issues to address for improved robustness and user experience:
-
Error Handling in
getUser
Function: Implement error handling in thegetUser
function to manage cases where user data cannot be fetched. Consider using.catch()
to handle errors and provide feedback to the user. -
Type Casting in
handleSelectedOption
: Ensure the value fromevent.target.value
is validated before casting toFilter
to avoid potential runtime errors. -
Loader Component Usage: While the
Loader
component is correctly used for todos, ensure similar handling for user loading. -
Search Input Filtering: Double-check that the
query
parameter is correctly used to filter todos by title. -
Filter Logic: Verify that the default case in the switch statement correctly handles the 'all' filter option to display all todos when no specific filter is applied.
-
User Email Link: Ensure the email link dynamically uses the correct email address from the
user
object. -
Type Casting in Filter Options: Ensure
Filter
values used inoption
elements are correctly referenced, possibly converting them to strings if necessary.
These improvements will enhance the functionality and reliability of your 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! ✨
getUser(todo.userId) | ||
.then(setSelectedUser) | ||
.finally(() => setLoadingUser(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 getUser
function call should include error handling to manage cases where the user data cannot be fetched. Consider using .catch()
to handle errors and provide user feedback.
const [query, setQuery] = useState<string>(''); | ||
|
||
function handleSelectedOption(event: React.ChangeEvent<HTMLSelectElement>) { | ||
setSelectedOption(event.target.value as Filter); |
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 value from event.target.value
is validated before casting to Filter
. This will help avoid potential runtime errors if the value is not a valid Filter
type.
<option value="all">{Filter.all}</option> | ||
<option value="active">{Filter.active}</option> | ||
<option value="completed">{Filter.completed}</option> |
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 Filter
values used in the option
elements are correctly referenced. If Filter.all
, Filter.active
, and Filter.completed
are not strings, you may need to convert them to strings or use their string representations.
|
||
if (filterQuery) { | ||
filteredTodos = filteredTodos.filter(todo => | ||
todo.title.toLowerCase().includes(query.toLowerCase()), |
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 query
parameter is correctly used to filter todos by title. The current implementation seems correct, but double-check that query
is being passed and used as intended.
default: | ||
break; |
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 default case in the switch statement is correctly handling the 'all' filter option. This is important to ensure that all todos are displayed when no specific filter is applied.
|
||
{' by '} | ||
|
||
<a href="mailto:[email protected]">Leanne Graham</a> | ||
<a href="mailto:[email protected]">{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 email link uses the correct email address from the user
object. Currently, it seems hardcoded. Consider using user?.email
to dynamically display the user's email.
<your_account>
with your Github username in the DEMO LINK and add it to the PR description.