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 #762

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

Conversation

DariaNastas
Copy link

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 job on your work so far! 😊 However, there are a few improvements that need to be made. Please consider renaming your methods to make them more descriptive and check if the input value is not composed of spaces only before filtering. Keep up the good work! 💪

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


useEffect(() => {
const timeoutId = setTimeout(() => {
if (inputValue.trim() === '') {

Choose a reason for hiding this comment

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

According to the checklist, the filter function shouldn't be called if the user entered spaces only. However, in this case, if the input value is only spaces, you will set all people as suggestions. To avoid unnecessary filtering, you should also check if the input value is not composed of spaces only.

<div className="dropdown-content">
{suggestions.map(person => (
<div
key={person.slug}

Choose a reason for hiding this comment

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

The checklist mentions not to generate keys on render. In this case, you are using 'person.slug' as a key which is fine as long as 'slug' is unique for each person and doesn't change over time.

onSelected(person);
};

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {

Choose a reason for hiding this comment

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

It's recommended to follow the naming conventions for methods. The method name 'handleInputChange' is fine, but it's better to specify what is changing. A more descriptive name could be 'handleInputValueChange'.

return () => clearTimeout(timeoutId);
}, [inputValue, people, delay]);

const handleSelect = (person: Person) => {

Choose a reason for hiding this comment

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

The same applies to the 'handleSelect' method. It would be better to rename it to 'handlePersonSelect' to make it clear what is being selected.

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 job! Your code is well-structured and readable. I've noticed a few areas for improvement, but they don't significantly impact the functionality of your code. Keep up the good work! 👍

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

const timeoutId = setTimeout(() => {
const trimmedInput = inputValue.trim();

if (trimmedInput === '') {

Choose a reason for hiding this comment

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

According to the checklist, the filter function should not be called if the user entered only spaces. But in the current implementation, if the user enters spaces, the filter function will be called. To avoid this, you should check not only that the trimmedInput is not an empty string, but also that it is not composed entirely of spaces.

Comment on lines +77 to +85
{suggestions.map(person => (
<div
key={person.slug}
className="dropdown-item"
onClick={() => handlePersonSelect(person)}
data-cy="suggestion-item"
>
<p className="has-text-link">{person.name}</p>
</div>

Choose a reason for hiding this comment

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

According to the checklist, keys should not be generated on render. In this case, you are using the slug property of the person object as a key, which is fine as long as slug is unique for each person and does not change during the component's lifecycle. If slug can change or is not unique, you will need to find another solution. Always ensure that keys are stable, predictable, and unique for each element in the list.

Comment on lines +42 to +46
const handlePersonSelect = (person: Person) => {
setInputValue(person.name);
setSelectedPerson(person);
setSuggestions([]);
onSelected(person);

Choose a reason for hiding this comment

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

The checklist mentions that you should follow specific naming conventions for methods. Your method handlePersonSelect is correctly named according to the conventions. However, handleInputValueChange could be renamed to handleInputChange to be more concise and still clear.

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