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

Todo app #1495

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

Todo app #1495

wants to merge 7 commits into from

Conversation

MaksymMohyla
Copy link

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
It's bad practice to write so much code in one component, you need to separate the logic into different components, for example Header, Footer, TodoItem, TodoList

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.

Almost done!
Let's make your code better

src/App.tsx Outdated
Comment on lines 54 to 60
case 'All':
visibleTodos = todos;
break;
case 'Active':
visibleTodos = todos.filter(todo => !todo.completed);
break;
case 'Completed':

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

src/App.tsx Outdated
Comment on lines 95 to 98
//#endregion

//#region add Todos
// input

Choose a reason for hiding this comment

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

Remove all comments, it's redundant here

src/App.tsx Outdated
titleRef={titleRef}
/>

{todos.length !== 0 && (

Choose a reason for hiding this comment

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

Suggested change
{todos.length !== 0 && (
{!!todos.length && (

return (
<footer className="footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{todos.filter(todo => !todo.completed).length} items left

Choose a reason for hiding this comment

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

Move this logic to the helper variable and use it here

Comment on lines 32 to 63
<a
href="#/"
className={cn('filter__link', {
selected: selectedFilter === 'All',
})}
data-cy="FilterLinkAll"
onClick={onFilterAll}
>
All
</a>

<a
href="#/active"
className={cn('filter__link', {
selected: selectedFilter === 'Active',
})}
data-cy="FilterLinkActive"
onClick={onFilterActive}
>
Active
</a>

<a
href="#/completed"
className={cn('filter__link', {
selected: selectedFilter === 'Completed',
})}
data-cy="FilterLinkCompleted"
onClick={onFilterCompleted}
>
Completed
</a>

Choose a reason for hiding this comment

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

Use Object.values(your created enum) and render these options with map() method

}) => {
return (
<header className="header">
{todos.length !== 0 && (

Choose a reason for hiding this comment

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

Suggested change
{todos.length !== 0 && (
{!!todos.length && (

active: todos.every(todo => todo.completed),
})}
data-cy="ToggleAllButton"
onClick={() => onToggleAll()}

Choose a reason for hiding this comment

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

Suggested change
onClick={() => onToggleAll()}
onClick={onToggleAll}

data-cy="TodoStatus"
type="checkbox"
className="todo__status"
checked={todo.completed}

Choose a reason for hiding this comment

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

Use destructuring for todo

Copy link

@etojeDenys etojeDenys left a comment

Choose a reason for hiding this comment

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

  1. show loaders on todos that you need to update on toggle all
  2. show loaders on todos that you need to delete on completedAll
Screen.Recording.2024-10-25.at.10.08.32.mov

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.

Great! 🔥

//#endregion

//#region rename Todo
const [redactingQuery, setRedactingQuery] = useState(selectedTodo?.title);

Choose a reason for hiding this comment

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

All states must be declared at the beginning of the component

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