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

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

Develop #792

wants to merge 6 commits into from

Conversation

AndrMar1939
Copy link

@AndrMar1939 AndrMar1939 commented Sep 25, 2023

DEMO LINK
This is a new PR. I've closed the previous one because it didn't contain any tests.
Sorry O.Budnik, your great review remain under the old PR

#780

Copy link

@polinavafik polinavafik left a comment

Choose a reason for hiding this comment

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

Everything works as expected! great job!

Comment on lines 9 to 11
// import USER_ID from '../../helpers/USER_ID';
// import { getTodos } from '../../api/todos';
// import { loadTodosAction } from '../actions/actionCreators';

Choose a reason for hiding this comment

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

remove that if you don't need it anymore

Choose a reason for hiding this comment

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

Not fixed 😢

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.


const activeTodosNumber = getActiveTodos(todos).length;
const completedTodos = getCompletedTodos(todos);
const isClearCompletedInvisible = completedTodos.length === 0;

Choose a reason for hiding this comment

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

Suggested change
const isClearCompletedInvisible = completedTodos.length === 0;
const isClearCompletedInvisible = !completedTodos.length;

return (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{`${activeTodosNumber} 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.

const ref = useRef<HTMLInputElement>(null);
const [inputValue, setInputValue] = useState('');

const isToggleVisible = 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
const isToggleVisible = todos.length > 0;
const isToggleVisible = !!todos.length;

dispatch(patchAction);
});

if (rejected.length > 0) {

Choose a reason for hiding this comment

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

Suggested change
if (rejected.length > 0) {
if (rejected.length) {


return (
<header className="todoapp__header">
{/* 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

Comment on lines 54 to 56
onClick={() => {
setAddClassName(true);
}}

Choose a reason for hiding this comment

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

Suggested change
onClick={() => {
setAddClassName(true);
}}
onClick={() => setAddClassName(true)}

Comment on lines 9 to 11
// import USER_ID from '../../helpers/USER_ID';
// import { getTodos } from '../../api/todos';
// import { loadTodosAction } from '../actions/actionCreators';

Choose a reason for hiding this comment

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

Not fixed 😢

Comment on lines 43 to 51
// useEffect(() => {
// getTodos(USER_ID)
// .then((data) => {
// const action = loadTodosAction(data);

// dispatch(action);
// })
// .catch(e => setApiError(e));
// }, []);

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.

Comment on lines 68 to 70
const url = value === FiltersType.ALL
? ''
: value.toLowerCase();

Choose a reason for hiding this comment

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

You can change the FiltersType a little and then you won't need to add an extra check:

export enum FiltersType {
  ALL = '',
  ACTIVE = 'Active',
  COMPLETED = 'Completed',
}
...
const url = value.toLowerCase();

Copy link
Author

Choose a reason for hiding this comment

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

Brilliant!

Comment on lines 12 to 22
switch (filter) {
case FiltersType.ALL:
default:
return todos;

case FiltersType.ACTIVE:
return getActiveTodos(todos);

case FiltersType.COMPLETED:
return getCompletedTodos(todos);
}

Choose a reason for hiding this comment

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

Suggested change
switch (filter) {
case FiltersType.ALL:
default:
return todos;
case FiltersType.ACTIVE:
return getActiveTodos(todos);
case FiltersType.COMPLETED:
return getCompletedTodos(todos);
}
switch (filter) {
case FiltersType.ACTIVE:
return getActiveTodos(todos);
case FiltersType.COMPLETED:
return getCompletedTodos(todos);
default:
return todos;
}

@AndrMar1939
Copy link
Author

AndrMar1939 commented Sep 27, 2023

Hello mentor! There is a component Footer with handleClearCompletedClick - row 31. The handler is ok or not?

@BudnikOleksii
Copy link

Hello mentor! There is a component Footer with handleClearCompletedClick - row 31. The handler is ok or not?

It's ok. You can do it in different ways. You can collect requests and then handle them with Promise.all or with Promise.allsettled but we discussed that it's okay to do it without them. Only one moment that you don't need to return deletedTodos from this handler, just send requests with forEach or for of

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.

Nicely done 🚀

Comment on lines +97 to +99
/* eslint-disable @typescript-eslint/no-explicit-any */
Promise.allSettled(toggledTodos)
.then((data: any) => {

Choose a reason for hiding this comment

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

🔥
If you are interested you can google how to handle type for Promise.allSettled
https://stackoverflow.com/questions/64928212/how-to-use-promise-allsettled-with-typescript

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