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 rename todo and completed status todo #807

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

Conversation

Denys14Samoilenko
Copy link

@Denys14Samoilenko Denys14Samoilenko commented Sep 26, 2023

Copy link

@roman-mirzoian roman-mirzoian 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, but there is quite a bit of work to be done.

src/App.tsx Outdated
Comment on lines 1 to 2
/* eslint-disable max-len */
/* eslint-disable 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.

Try to rewrite the code so that it is not necessary to disable the linter

src/App.tsx Outdated
.then(setTodos)
.catch((error) => {
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE);
throw error;

Choose a reason for hiding this comment

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

Suggested change
throw error;
throw Error(error.message);

Fix this in all code.

src/App.tsx Outdated
});
}, []);

const timerId = useRef<number>(0);

Choose a reason for hiding this comment

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

Suggested change
const timerId = useRef<number>(0);
const timerIdRef = useRef<number>(0);

src/App.tsx Outdated
Comment on lines 57 to 65
useEffect(() => {
if (timerId.current) {
window.clearTimeout(timerId.current);
}

timerId.current = window.setTimeout(() => {
setErrorMessage('');
}, 3000);
}, [errorMessage]);

Choose a reason for hiding this comment

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

src/App.tsx Outdated
<h1 className="todoapp__title">todos</h1>

<div className="todoapp__content">

Choose a reason for hiding this comment

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

Suggested change


return (
<header className="todoapp__header">
{/* this buttons is active only if there are some active todos */}

Choose a reason for hiding this comment

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

Do not leave unnecessary comments.

className="todoapp__toggle-all active"
data-cy="ToggleAllButton"
/>
{/* Add a todo on form submit */}

Choose a reason for hiding this comment

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

Do not leave unnecessary comments.

'modal',
'overlay',
{
'is-active': isProcessing || todoId === 0,

Choose a reason for hiding this comment

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

Suggested change
'is-active': isProcessing || todoId === 0,
'is-active': isProcessing || !todoId,

}
};

const titleInput = useRef<HTMLInputElement | null>(null);

Choose a reason for hiding this comment

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

Suggested change
const titleInput = useRef<HTMLInputElement | null>(null);
const titleInputRef = useRef<HTMLInputElement | null>(null);

Comment on lines 108 to 110
onClick={() => {
onDeleteTodo();
}}

Choose a reason for hiding this comment

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

Suggested change
onClick={() => {
onDeleteTodo();
}}
onClick={onDeleteTodo}

Copy link

@Vayts Vayts 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!

Copy link

@roman-mirzoian roman-mirzoian 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.

src/App.tsx Outdated
Comment on lines 186 to 190
if (isAllCompleted) {
Promise.all(visibleTodos.map(updateTodoStatus));
} else {
Promise.all(activeTodos.map(updateTodoStatus));
}

Choose a reason for hiding this comment

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

"DRY"

Suggested change
if (isAllCompleted) {
Promise.all(visibleTodos.map(updateTodoStatus));
} else {
Promise.all(activeTodos.map(updateTodoStatus));
}
const todosForUpdate = isAllCompleted ? visibleTodos : activeTodos;
Promise.all(todosForUpdate.map(updateTodoStatus));

src/App.tsx Outdated
/>

<section className="todoapp__main" data-cy="TodoList">

Choose a reason for hiding this comment

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

Not fixed 😢

: `${todosLength} items left`}
</span>

{/* Active filter should have a 'selected' class */}

Choose a reason for hiding this comment

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

Not fixed 😢

type="button"
className="todoapp__clear-completed"
data-cy="ClearCompletedButton"
style={{ visibility: completedTodosLength ? 'visible' : 'hidden' }}

Choose a reason for hiding this comment

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

Nit fixed 😢

Copy link

@ArtemTeslenko ArtemTeslenko left a comment

Choose a reason for hiding this comment

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

There are some not fixed issues. Please, pay attention))

src/App.tsx Outdated
.then(setTodos)
.catch((error) => {
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE);
throw Error(error.message);

Choose a reason for hiding this comment

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

it seems that your error message is in 'errorMessage', which you set on previous line, also add new 'throw new Error'

Choose a reason for hiding this comment

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

We can pass a pure error to the constructor of the Error class to see more information in the console

src/App.tsx Outdated
})
.catch((error) => {
setErrorMessage(TodosError.ADD_ERROR_MESSAGE);
throw Error(error.message);

Choose a reason for hiding this comment

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

See comment above.

Copy link

@roman-mirzoian roman-mirzoian 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.
Now, if you update the title with only spaces, it will not be deleted, but will remain empty.
Also now, when there is only one item left, the inscription is displayed in the plural 1 items:
https://gyazo.com/da8bbe584d9275ad69b48843c104f688

src/App.tsx Outdated
.then(setTodos)
.catch((error) => {
setErrorMessage(TodosError.DOWNLOAD_ERROR_MESSAGE);
throw Error(error.message);

Choose a reason for hiding this comment

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

We can pass a pure error to the constructor of the Error class to see more information in the console

src/App.tsx Outdated
.then(() => {
setTodoTitle('');
})
.catch();

Choose a reason for hiding this comment

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

In the catch block, we must work with the error and not leave it empty

Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

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

Good work 👍

Comment on lines +54 to +62
const timerIdRef = useRef<number>(0);

useEffect(() => {
timerIdRef.current = window.setTimeout(() => {
setErrorMessage('');
}, 3000);

return () => clearTimeout(timerIdRef.current);
}, [errorMessage]);

Choose a reason for hiding this comment

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

You can keep related logic in the ErrorNotification component

Comment on lines +23 to +25
{todosSortBy === TodosSortType.All
? `${todosLength - completedTodosLength} items left`
: `${todosLength} items left`}

Choose a reason for hiding this comment

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

It is better to put the number calculation in a separate variable for better readability.

Don't forget about all comments

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.

5 participants