Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This requires a few changes before it can be approved. You've done a great job implementing the core functionality, like debouncing the input and displaying suggestions. However, there are a few key requirements that need to be addressed.
In src/App.tsx, the onSelected prop is not being called when a user selects a person. This is a core part of the component's functionality.
Additionally, the filtering logic has a couple of issues:
- It runs on every render, even when the input text hasn't changed. This should be memoized, for example, with the
useMemohook. - The filter is still triggered if the user only types spaces, which should be prevented [CHECKLIST ITEM #1]. You can fix this by trimming the input value before filtering.
Please address these points, and your solution will be ready for approval!
✨ 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
src/App.tsx
Outdated
| onSelected?: (person: Person) => void; | ||
| }; | ||
|
|
||
| export const App: React.FC<AppProps> = ({ debounceDelay = 300 }) => { |
There was a problem hiding this comment.
The onSelected prop is defined in AppProps but is not being destructured and used. To meet the requirement to "pass the selected person to the onSelected callback passed via props", you need to get it from the props here and call it when a selection is made.
src/App.tsx
Outdated
| const filteredPeople = peopleFromServer.filter(person => { | ||
| return person.name.toLowerCase().includes(debouncedValue.toLowerCase()); | ||
| }); |
There was a problem hiding this comment.
This filtering logic has two issues:
- It runs on every component render, not only when
debouncedValuechanges. This violates the requirement: "don't run filtering again if the text has not changed". - The filter is executed even if the user enters only spaces, which violates checklist item react_autocomplete #1: "make sure that filter won't be called if user enred spaces only".
Both issues can be resolved by wrapping this logic in a useMemo hook and checking if the trimmed debouncedValue is empty before filtering.
| onMouseDown={() => { | ||
| setInputValue(person.name); | ||
| setSelectedPerson(person); | ||
| setIsFocused(false); | ||
| }} |
There was a problem hiding this comment.
When a person is selected, you also need to call the onSelected prop (which should be destructured from the component's props) with the selected person.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Great work on this update! You've successfully addressed all the feedback from the previous review, and the component is very close to being perfect.
I'm requesting one small change to fix a bug in the filtering logic. Currently, the search fails if the input has leading or trailing spaces (e.g., " Ada "). This is because you are using the original debouncedValue for the search comparison inside your useMemo hook in src/App.tsx.
To fix this, please ensure you use the trimmed value for the actual filtering, just as you do for the check to see if the input is empty. Once you've made that adjustment, this will be ready to merge!
✨ 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
src/App.tsx
Outdated
| } | ||
|
|
||
| return peopleFromServer.filter(person => { | ||
| return person.name.toLowerCase().includes(debouncedValue.toLowerCase()); |
There was a problem hiding this comment.
The filtering is being performed with debouncedValue, which might include leading or trailing spaces. To ensure correct matching, you should use the trimmedValue here for the search, just as you did for the check on line 32.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this pull request! I am approving your solution as you have successfully addressed the previous feedback, and the component now correctly handles search terms with leading or trailing whitespace. The code is clean, well-structured, and correctly implements the debouncing, filtering, and state management logic. The component now meets all functional and technical requirements perfectly. Great job!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.