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

Develop #2596

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

Develop #2596

wants to merge 4 commits into from

Conversation

Svidruk
Copy link

@Svidruk Svidruk commented Oct 11, 2024

Copy link

@Sholudyvyy Sholudyvyy left a comment

Choose a reason for hiding this comment

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

Well done!

Comment on lines +28 to +49
const filteredTodos = (() => {
const newTodos = todos.filter(todo => {
const matchesFilter = (() => {
switch (filterOption) {
case TodoState.completed:
return todo.completed;
case TodoState.active:
return !todo.completed;
default:
return true;
}
})();

const matchesQuery = todo.title
.toLocaleLowerCase()
.includes(query.toLocaleLowerCase());

return matchesFilter && matchesQuery;
});

return newTodos;
})();

Choose a reason for hiding this comment

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

You can create folder "utils" and move this function there

className="input"
placeholder="Search..."
value={query}
onChange={event => setQuery(event.target.value.trimStart())}

Choose a reason for hiding this comment

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

You don't need trim this. In example, we can write with space, and this change result

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 the code! There are a few minor issues to address, but they don't 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! ✨

);
<tbody>
{todos.map(todo => (
<tr key={todo.id} data-cy="todo" className="">

Choose a reason for hiding this comment

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

The key is generated on render, which may lead to performance issues. It's better to use a unique and consistent key, like todo.id.

data-cy="selectButton"
className="button"
type="button"
onClick={() => setActiveTodo(todo)}

Choose a reason for hiding this comment

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

The naming conventions for event handlers are not followed. It is recommended to use the handle prefix for methods that are used as event handlers. In this case, the method could be named handleSetActiveTodo.

>
<span className="icon">
<i
className={!activeTodo ? 'far fa-eye' : 'far fa-eye-slash'}

Choose a reason for hiding this comment

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

The classnames library can be used here to conditionally set the class for this element. This will make the code cleaner and easier to read.

getUser(activeTodo.userId)
.then(setTodoUser)
.finally(() => setIsLoading(false));
}, []);

Choose a reason for hiding this comment

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

You have an empty array as a dependency for your useEffect hook. This means that the effect will only run once after the initial render. However, you're using activeTodo.userId inside the effect, which is a prop. If activeTodo changes, your effect won't run again as expected. You should include activeTodo.userId in the dependency array to ensure that the effect runs whenever activeTodo.userId changes.

type="button"
className="delete"
data-cy="modal-close"
onClick={() => setActiveTodo(null)}

Choose a reason for hiding this comment

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

You're directly manipulating the DOM by setting setActiveTodo to null in your onClick event handler. In React, it's better to avoid direct DOM manipulation as much as possible. Consider using a more React-like approach, such as setting state or using context.


{' by '}

<a href="mailto:[email protected]">Leanne Graham</a>
{todoUser && (
<a href={`mailto:${todoUser.email}`}>{todoUser.name}</a>

Choose a reason for hiding this comment

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

You're generating a new function on each render by using an inline function for the href attribute. It's better to avoid generating new functions during render because it can lead to unnecessary re-renders and negatively impact performance. Consider moving this function outside of the component or memoizing it with useCallback.

@@ -15,25 +32,35 @@
className="modal-card-title has-text-weight-medium"
data-cy="modal-header"
>

Choose a reason for hiding this comment

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

You're generating a new string on each render by using a template literal for the Todo #${activeTodo.id} text. It's better to avoid generating new values during render because it can lead to unnecessary re-renders and negatively impact performance. Consider moving this value outside of the component or memoizing it with useMemo.

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.

3 participants