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

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

add task solution #812

wants to merge 2 commits into from

Conversation

yar0man
Copy link

@yar0man yar0man commented Sep 27, 2023

Copy link

@Denys14Samoilenko Denys14Samoilenko 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! 🔥
I leave some comments for you!

.catch(() => {
setErrorMesssage('Unable to load todos');

setTimeout(() => {

Choose a reason for hiding this comment

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

I think you need to clear this timeout

data-cy="HideErrorButton"
type="button"
className="delete"
onClick={() => onErrorMesssageChange('')}

Choose a reason for hiding this comment

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

You can use your const removeErrorMessage here i think

Choose a reason for hiding this comment

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

Good point.

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

const [title, setTitle] = useState('');
const [tempTodo, setTempTodo] = useState<Todo | null>(null);
const [isDisable, setIsDisable] = useState(false);

Choose a reason for hiding this comment

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

Suggested change
const [isDisable, setIsDisable] = useState(false);
const [isDisabled, setIsDisabled] = useState(false);

src/App.tsx Outdated
onErrorMesssageChange={setErrorMesssage}
/>

{filteredTodos.length > 0 && (

Choose a reason for hiding this comment

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

Suggested change
{filteredTodos.length > 0 && (
{!!filteredTodos.length && (

src/App.tsx Outdated
/>
)}

{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 && (

src/App.tsx Outdated
onSelectedFilter={setSelectedFilter}
/>
)}

Choose a reason for hiding this comment

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

Suggested change

return (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{`${countTodos(todos, false)} items left`}

Choose a reason for hiding this comment

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

If there is one item, there should not be a plural in the text.

@@ -0,0 +1,102 @@
/* 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

@@ -0,0 +1,162 @@
/* eslint-disable max-len */

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

};

const updateTitle = () => {
if (editedTitle.trim() === todo.title) {

Choose a reason for hiding this comment

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

You use editedTitle.trim() three times, it's better to put it in a variable and reuse it.

data-cy="Todo"
key={todo.id}
className={classNames('todo', {
completed: 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
completed: todo.completed === true,
completed: todo.completed

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 👍
Left a few suggestons

Comment on lines +53 to +66
setTempTodo({
id: 0,
userId: USER_ID,
title: title.trim(),
completed: false,
});

setIsDisabled(true);

addTodo({
userId: USER_ID,
title: title.trim(),
completed: false,
})

Choose a reason for hiding this comment

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

Suggested change
setTempTodo({
id: 0,
userId: USER_ID,
title: title.trim(),
completed: false,
});
setIsDisabled(true);
addTodo({
userId: USER_ID,
title: title.trim(),
completed: false,
})
const newTodo = {
userId: USER_ID,
title: title.trim(),
completed: false,
};
setTempTodo({
...newTodo,
id: 0,
});
setIsDisabled(true);
addTodo(newTodo)

Don't repeat yourself

Comment on lines +34 to +36
setTimeout(() => {
setErrorMesssage('');
}, 3000);

Choose a reason for hiding this comment

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

You can trigger timeout in the ErrorNotification component in case of any error

return (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{`${countTodos(todos, false)} ${countTodos(todos, false) === 1 ? 'item' : 'items'} left`}

Choose a reason for hiding this comment

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

countTodos(todos, false) You do it twice here, create a variable

Comment on lines +8 to +18
let todosCopy = [...todos];

if (selectedFilter) {
todosCopy = todosCopy.filter(({ completed }) => {
switch (selectedFilter) {
case FilterStatus.Active:
return !completed;
case FilterStatus.Completed:
return completed;
default:
return todosCopy;

Choose a reason for hiding this comment

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

In the default case, you get an array of todosCopy arrays. And filter creates a new array so you don't need to create copy in this case

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