-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #797
base: master
Are you sure you want to change the base?
add task solution #797
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy your app and add the link to preview so interviewers can test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 👍
Left some suggestions, take a look. Also, add loaders for todos when the user changes todo status or clicks toggleAll
button
src/App.tsx
Outdated
|
||
const USER_ID = 0; | ||
const filterTodos = (todos: Todo[], filterStatus: Status): Todo[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to utils/helpers folder
src/App.tsx
Outdated
.catch(() => { | ||
setErrorMessage(ErrorMessages.UnableAddTodo); | ||
setTempTodo(null); | ||
throw new Error(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to throw an error here as you handle errors in this block
src/App.tsx
Outdated
TodoSevise.updateTodo({ | ||
id: todo.id, | ||
title: newTitle, | ||
userId: todo.userId, | ||
completed: todo.completed, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TodoSevise.updateTodo({ | |
id: todo.id, | |
title: newTitle, | |
userId: todo.userId, | |
completed: todo.completed, | |
}) | |
TodoSevise.updateTodo({ | |
...todo, | |
title: newTitle, | |
}) |
src/App.tsx
Outdated
TodoSevise.updateTodo({ | ||
id: todo.id, | ||
title: todo.title, | ||
userId: todo.userId, | ||
completed: !todo.completed, | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same
src/App.tsx
Outdated
<section className="todoapp__main" data-cy="TodoList"> | ||
{visibleTodos.map(todo => ( | ||
<TodoItem | ||
todo={todo} | ||
onTodoDelete={handleDeleteTodo} | ||
isLoading={isLoading} | ||
handleLoading={handleLoading} | ||
key={todo.id} | ||
onTodoUpdate={handleUpdateTodo} | ||
onToggleChange={handleToggleChange} | ||
/> | ||
))} | ||
|
||
{(tempTodo) && ( | ||
<TodoItem | ||
todo={tempTodo} | ||
onTodoDelete={handleDeleteTodo} | ||
isLoading={isLoading} | ||
handleLoading={handleLoading} | ||
onTodoUpdate={handleUpdateTodo} | ||
onToggleChange={handleToggleChange} | ||
key={tempTodo.id} | ||
/> | ||
)} | ||
</section> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a TodoList
component
src/App.tsx
Outdated
<div | ||
data-cy="ErrorNotification" | ||
className={classNames( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/Header.tsx
Outdated
setTodoTitle: (value: string) => void; | ||
}; | ||
|
||
const USER_ID = 11516; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this constant created in the API too. It must be only one USER_ID
, move it constants and use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, but you should get rid of all comments and there are still no loaders when the user changes the todo status
https://www.loom.com/share/b891778c03f74e2f9d8f14c3546b0014?sid=17028e00-2bb8-43b2-b192-005624336478
src/App.tsx
Outdated
|
||
const USER_ID = 0; | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
// import classNames from 'classnames'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments
src/App.tsx
Outdated
/* const timerId: React.MutableRefObject<number> = useRef<number>(0); | ||
|
||
useEffect(() => { | ||
if (timerId.current) { | ||
window.clearTimeout(timerId.current); | ||
} | ||
|
||
timerId.current = window.setTimeout(() => { | ||
setErrorMessage(''); | ||
}, 3000); | ||
}, [errorMessage]); */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of all comments in your code
src/components/TodoItem.tsx
Outdated
<> | ||
<div |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you have only one element in a row you don't need to use the react fragment
src/components/TodoItem.tsx
Outdated
</div> | ||
|
||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't leave blank lines between parent and child components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work 👍
But, don't forget to get rid of comments
.catch(() => { | ||
setErrorMessage(ErrorMessages.UnableAddTodo); | ||
setTempTodo(null); | ||
// throw new Error(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to remove comments
{/* <section className="todoapp__main" data-cy="TodoList"> | ||
{visibleTodos.map(todo => ( | ||
<TodoItem | ||
todo={todo} | ||
onTodoDelete={handleDeleteTodo} | ||
isLoading={isLoading} | ||
handleLoading={handleLoading} | ||
key={todo.id} | ||
onTodoUpdate={handleUpdateTodo} | ||
onToggleChange={handleToggleChange} | ||
/> | ||
))} | ||
|
||
{(tempTodo) && ( | ||
<TodoItem | ||
todo={tempTodo} | ||
onTodoDelete={handleDeleteTodo} | ||
isLoading={isLoading} | ||
handleLoading={handleLoading} | ||
onTodoUpdate={handleUpdateTodo} | ||
onToggleChange={handleToggleChange} | ||
key={tempTodo.id} | ||
/> | ||
)} | ||
</section> */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of all commented code
DEMO LINK