Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add task solution #2719

wants to merge 2 commits into from

Conversation

zhudim
Copy link

@zhudim zhudim commented Jan 6, 2025

  • Replace <your_account> with your Github username in the DEMO LINK and add it to the PR description.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Error Handling in getUser Function: Ensure that the function handles errors gracefully, providing feedback to the user if user data cannot be fetched.

  2. Type Casting in TodoFilter.tsx: Validate the value before casting to OptionType to avoid potential runtime errors.

  3. Search Input Filtering: Make sure the searchInput is used to filter todos by title, as required by the task.

  4. 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
Comment on lines 22 to 32
useEffect(() => {
const fetchData = async () => {
setListLoading(true);
const todosDb = await getTodos();

setTodos(todosDb);
setListLoading(false);
};

fetchData();
}, []);

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
Comment on lines 34 to 49
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]);

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)}

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.

Comment on lines 19 to 22
const user = await getUser(todo.userId);

setLoading(false);
setCurrentUser(user);

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

  1. Error Handling in getUser Function: Implement error handling in the getUser function to manage cases where user data cannot be fetched. Consider using .catch() to handle errors and provide feedback to the user.

  2. Type Casting in handleSelectedOption: Ensure the value from event.target.value is validated before casting to Filter to avoid potential runtime errors.

  3. Loader Component Usage: While the Loader component is correctly used for todos, ensure similar handling for user loading.

  4. Search Input Filtering: Double-check that the query parameter is correctly used to filter todos by title.

  5. 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.

  6. User Email Link: Ensure the email link dynamically uses the correct email address from the user object.

  7. Type Casting in Filter Options: Ensure Filter values used in option 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! ✨

Comment on lines +37 to +39
getUser(todo.userId)
.then(setSelectedUser)
.finally(() => setLoadingUser(false));

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);

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.

Comment on lines +20 to +22
<option value="all">{Filter.all}</option>
<option value="active">{Filter.active}</option>
<option value="completed">{Filter.completed}</option>

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()),

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.

Comment on lines +37 to +38
default:
break;

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>

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants