Skip to content

almost solution#1124

Open
despair849 wants to merge 2 commits intomate-academy:masterfrom
despair849:develop
Open

almost solution#1124
despair849 wants to merge 2 commits intomate-academy:masterfrom
despair849:develop

Conversation

@despair849
Copy link
Copy Markdown

Copy link
Copy Markdown

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

Review Summary

Great work on implementing the core features of the Autocomplete component! The debouncing and state management in the App component are well done. However, a couple of changes are needed to meet all the requirements.

First, the filter is triggered even when the input contains only spaces, which goes against a specific requirement [CHECKLIST ITEM #1]. You can fix this by using .trim() on the query within your useEffect hook before deciding whether to run the filter.

Second, after selecting a person, if you click away and then re-focus the input, the suggestion list is empty. This is because the filteredPeople state is cleared on selection. Removing the line that sets setFilteredPeople([]) in your selection handler will resolve this, allowing the useEffect hook to correctly repopulate the suggestions.

Please address these two points. I'm looking forward to seeing the updated version!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +26 to +37
const handler = setTimeout(() => {
const normalizedQuery = query.toLowerCase();

setFilteredPeople(
query
? people.filter(person =>
person.name.toLowerCase().includes(normalizedQuery),
)
: people,
);
lastRefQuery.current = query;
}, delay);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This effect doesn't handle the case where the query consists only of whitespace. This violates checklist item #1: 'make sure that filter won't be called if user enred spaces only'. You should trim() the query before using it to decide whether to filter.

setQuery(person.name);
setIsOpen(false);
lastRefQuery.current = person.name;
setFilteredPeople([]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing filteredPeople here leads to an empty suggestion list if the user re-focuses the input after making a selection. Consider removing this line. The useEffect hook will correctly repopulate the suggestions when query is updated, and since the dropdown is closed, the user won't see the intermediate state.

Copy link
Copy Markdown

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

Review Summary

Excellent work on this update! You've successfully addressed all the feedback from the previous review, and the component now functions perfectly according to all requirements. I am approving your submission. As a minor suggestion, you can simplify the logic inside the useEffect in src/components/Autocomplete.tsx. Since you already handle the case where query.trim() === '' at the top of the hook, the ternary operator used for filtering is redundant. This is just a small refinement, and your current implementation is solid. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment on lines +36 to +40
query
? people.filter(person =>
person.name.toLowerCase().includes(normalizedQuery),
)
: people,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are already handling the case where query.trim() === '' earlier in the useEffect hook, the query variable will always be a non-empty string at this point. This makes the ternary operator redundant.

You can simplify this logic by removing the check and the else branch, leaving only the filtering logic.

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