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

feat(todo): implement modal opening, filtering, and state management #2752

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

Conversation

misha-vynnyk
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 implementing the task requirements effectively! 🎉 While there are some minor areas for improvement, such as enhancing accessibility with aria-labels and refining some logic for better readability, these do not impact the core functionality. Keep up the good work and consider these suggestions for future enhancements! 😊

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

}, []);

useEffect(() => {
if (!currentTodo || currentTodo.user) {

Choose a reason for hiding this comment

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

The condition !currentTodo || currentTodo.user might lead to unexpected behavior if currentTodo.user is falsy but valid. Ensure this logic correctly reflects the intended check for whether the user data needs to be fetched.

Comment on lines +50 to +55
setCurrentTodo(prevTodo => {
if (prevTodo?.id === currentTodo.id) {
return { ...prevTodo, user };
}

return prevTodo;

Choose a reason for hiding this comment

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

The logic inside setCurrentTodo could be simplified or clarified. Ensure that the condition prevTodo?.id === currentTodo.id is necessary and correctly handles all cases where the user data should be updated.

</span>

<span className="icon is-right" style={{ pointerEvents: 'all' }}>
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}

Choose a reason for hiding this comment

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

The comment indicates that the button lacks an associated label, which can affect accessibility. Consider adding an aria-label or similar attribute to the button to improve accessibility for screen readers.

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

Choose a reason for hiding this comment

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

Consider adding a meaningful class name to the tr element for better readability and maintainability, especially if additional styling or logic is added in the future.

Comment on lines 45 to 48
className={classNames({
'has-text-success': todo.completed,
'has-text-danger': !todo.completed,
})}

Choose a reason for hiding this comment

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

The use of classNames is correct, but consider extracting the logic into a separate variable for improved readability, especially if more conditions are added later.

@@ -15,25 +37,36 @@ export const TodoModal: React.FC = () => {
className="modal-card-title has-text-weight-medium"
data-cy="modal-header"
>
Todo #2
Todo #{currentTodo.id}
</div>

{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}

Choose a reason for hiding this comment

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

The comment indicates that the button lacks an associated label, which can affect accessibility. Consider adding an aria-label or similar attribute to the button to improve accessibility for screen readers.

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Good job 👍
Let's improve your code

src/App.tsx Outdated
Comment on lines 37 to 39
.then(data => {
setTodos(data);
})

Choose a reason for hiding this comment

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

Suggested change
.then(data => {
setTodos(data);
})
.then(setTodos)

src/App.tsx Outdated
Comment on lines 60 to 61
// // eslint-disable-next-line no-console
// console.log('Modal state:', isModalOpen, 'ModalLoader:', modalLoading);

Choose a reason for hiding this comment

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

Remove comments everywhere

Suggested change
// // eslint-disable-next-line no-console
// console.log('Modal state:', isModalOpen, 'ModalLoader:', modalLoading);

src/App.tsx Outdated
Comment on lines 64 to 66
// #endregion State

// #region Handler

Choose a reason for hiding this comment

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

Suggested change
// #endregion State
// #region Handler

src/App.tsx Outdated
Comment on lines 79 to 81
if (filterValue === 'completed') {
return todo.completed === true;
} else if (filterValue === 'active') {

Choose a reason for hiding this comment

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

Create a enum for 'all', 'active', 'completed' and use it everywhere. Also, will be better if you use switch case here instead of if conditions

src/App.tsx Outdated
return todos
.filter(todo => {
if (filterValue === 'completed') {
return todo.completed === true;

Choose a reason for hiding this comment

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

Suggested change
return todo.completed === true;
return todo.completed;

src/App.tsx Outdated
if (filterValue === 'completed') {
return todo.completed === true;
} else if (filterValue === 'active') {
return todo.completed === false;

Choose a reason for hiding this comment

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

Suggested change
return todo.completed === false;
return !todo.completed;

Comment on lines 22 to 24
<option value="all">All</option>
<option value="active">Active</option>
<option value="completed">Completed</option>

Choose a reason for hiding this comment

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

Use enum here

Comment on lines 30 to 31
{todos.map(todo => {
return (

Choose a reason for hiding this comment

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

Suggested change
{todos.map(todo => {
return (
{todos.map(todo => (

Comment on lines 30 to 32
{todos.map(todo => {
return (
<tr data-cy="todo" className="" key={todo.id}>

Choose a reason for hiding this comment

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

Suggested change
{todos.map(todo => {
return (
<tr data-cy="todo" className="" key={todo.id}>
{todos.map(todo => {
return (
<tr data-cy="todo" key={todo.id}>

'has-text-danger': !todo.completed,
})}
>
{todo.title}

Choose a reason for hiding this comment

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

Use destructuring for todo

…mmented code, destructure todo, and improve UI
Copy link

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants