Skip to content

Solution#1166

Open
tavokina wants to merge 2 commits into
mate-academy:masterfrom
tavokina:develop
Open

Solution#1166
tavokina wants to merge 2 commits into
mate-academy:masterfrom
tavokina:develop

Conversation

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

Your implementation is close to completion, but there are two critical issues that violate explicit checklist requirements: Critical Issue #1 - Filter runs for spaces-only input (checklist item #4): The condition appliedQuery ? people.filter(...) : people checks appliedQuery which is truthy for whitespace-only input like " ". However, normalizedQuery becomes an empty string after .trim(), causing people.filter() to still execute. Since every string contains an empty substring, all people match. You need to check normalizedQuery instead (or normalizedQuery.length > 0) to properly skip filtering when only spaces are entered. Critical Issue #2 - Function naming violation (checklist item #4): The function isAppliedQuery implies it returns a boolean, but it returns undefined and performs side effects. Rename it to something action-oriented like applyQueryIfChanged. Medium Issue - Redundant wrapper: The onChange handler wraps an existing function unnecessarily: // Current (redundant) onChange={e => { handleQueryChange(e); }} // Should be onChange={handleQueryChange} Once you fix the spaces-only input filtering and rename the function, the core requirements will be met.


✨ 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 thread src/Autocomplete.tsx Outdated
Comment on lines +43 to +46

const filteredPeople = appliedQuery
? people.filter(person =>
person.name.toLowerCase().includes(normalizedQuery))
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 violates checklist item #4: 'make sure that filter won't be called if user entered spaces only'. When appliedQuery is only spaces (e.g., ' '), appliedQuery is truthy so people.filter() still runs. Use normalizedQuery in the condition instead: normalizedQuery ? people.filter(...) : people

Comment thread src/Autocomplete.tsx
Comment on lines +34 to +35
// eslint-disable-next-line react-hooks/exhaustive-deps
const applyQuery = useCallback(debounce(isAppliedQuery, delay), [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.

The debounced function should be cancelled on unmount to prevent memory leaks. Add a useEffect cleanup: useEffect(() => { return () => applyQuery.cancel(); }, []);

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

Your implementation successfully handles all the required functionality, including the spaces-only input filtering using normalizedQuery. The code correctly uses React state, properly implements debouncing, and all features from the task description are working as expected.

However, there are two style improvements to address:

  1. Function naming convention violation ([CHECKLIST ITEM #4]): The function isAppliedQuery in both src/App.tsx and src/Autocomplete.tsx implies a boolean return value, but it returns undefined and performs side effects. Rename it to an action-oriented name like applyQueryIfChanged to match the naming conventions for methods that perform actions rather than return values.

  2. Redundant onChange wrapper: In src/App.tsx (lines 68-70), the onChange handler onChange={e => { handleQueryChange(e); }} can be simplified to onChange={handleQueryChange} since handleQueryChange already accepts the event as its first argument.

The functionality is solid and all core requirements are met—these are style convention fixes that will improve code clarity. Once you update the function names and simplify the wrapper, you'll have a complete, well-structured implementation.


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

Footnotes

  1. Rate AI review example

Comment thread src/App.tsx
Comment on lines +24 to +31
setSelectedPerson(person);
setQuery(person.name);
}}
delay={delayValue}
query={query}
onQueryChange={value => {
setQuery(value);
setSelectedPerson(null);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist item #4 violation: Function name isAppliedQuery implies a boolean return value, but it returns undefined (early return) and performs side effects. Rename to an action-oriented name like applyQueryIfChanged per naming conventions for methods that return undefined and perform actions.

Comment thread src/Autocomplete.tsx
Comment on lines +24 to +31

const isAppliedQuery = (value: string) => {
if (lastAppliedQuery.current === value) {
return;
}

lastAppliedQuery.current = value;
setAppliedQuery(value);
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 function name implies it returns a boolean (is prefix), but it returns undefined and performs side effects. Per the naming conventions requirement, functions that perform actions should have action-oriented names like applyQueryIfChanged.

Comment thread src/Autocomplete.tsx
Comment on lines +68 to +70
value={query}
onChange={e => {
handleQueryChange(e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Redundant wrapper - can be simplified to onChange={handleQueryChange}

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

All functional requirements are met and the implementation works correctly. The spaces-only input filtering is properly handled, debouncing is implemented, and all core features function as expected. The two remaining issues—the misleading function name isAppliedQuery and the redundant onChange wrapper—are style and naming convention issues rather than functional blockers. While the function name does imply a boolean return when it performs side effects, this doesn't break any functionality. For future reference, consider renaming to something action-oriented like applyQueryIfChanged to better communicate its purpose, and simplify onChange={e => { handleQueryChange(e); }} to onChange={handleQueryChange}.


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

Footnotes

  1. Rate AI review example

Comment thread src/App.tsx
<Autocomplete
people={peopleFromServer}
onSelected={person => {
setSelectedPerson(person);
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 violates checklist item #4: 'follow naming conventions for methods'. The function name isAppliedQuery implies it returns a boolean, but it returns undefined with side effects. Rename it to something action-oriented like applyQueryIfChanged.

Comment thread src/Autocomplete.tsx
Comment on lines +24 to +31

const isAppliedQuery = (value: string) => {
if (lastAppliedQuery.current === value) {
return;
}

lastAppliedQuery.current = value;
setAppliedQuery(value);
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 violates checklist item #4 'follow naming conventions for methods'. Function name isAppliedQuery implies it returns a boolean, but it returns undefined and performs side effects. Rename to action-oriented name like applyQueryIfChanged.

Comment thread src/Autocomplete.tsx
Comment on lines +68 to +70
value={query}
onChange={e => {
handleQueryChange(e);
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 violates checklist item #4 - redundant wrapper. Change onChange={e => { handleQueryChange(e); }} to onChange={handleQueryChange}.

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