-
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
Develop #1535
base: master
Are you sure you want to change the base?
Develop #1535
Conversation
OkMoroz
commented
Dec 17, 2024
- DEMO LINK
src/App.tsx
Outdated
return <UserWarning />; | ||
} | ||
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [errorMessage, setErrorMessage] = useState<string>(''); |
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.
в тебе є enum по помилкам, типізуй useState типом Error
щоб не робити тут додаткової перевірки на пустий рядок, то можеж в enum прописати, наприклад Nothing: '', aбо Empty: ''
Бо в даному випадку в цей state можна покласти довільний рядок
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.
Дякую, візьму до уваги
const [errorMessage, setErrorMessage] = useState<string>(''); | ||
const [tempTodo, setTempTodo] = useState<Todo | null>(null); | ||
const [filter, setFilter] = useState<Filters>(Filters.All); | ||
const [loadingId, setLoadingId] = useState<Loading>({}); |
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.
краще зберігати саму id, без об'єкта і судячи з назви там має бути id
src/App.tsx
Outdated
onDelete={handleDelete} | ||
/> | ||
|
||
{todos.length > 0 && ( |
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.
краще вказати перевірку !!todos.length
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.
чому саме той варіант кращий?
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.
@OkMoroz !!
- converts the value to boolean type and more readable i think
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 job 🔥
But let's make some changes
src/App.tsx
Outdated
return <UserWarning />; | ||
} | ||
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [errorMessage, setErrorMessage] = useState<ErrorMessage | string>(''); |
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.
it will be safer that way
const [errorMessage, setErrorMessage] = useState<ErrorMessage | string>(''); | |
const [errorMessage, setErrorMessage] = useState<ErrorMessage>(ErrorMessage.Default); |
src/App.tsx
Outdated
return () => clearTimeout(timeoutId); | ||
}, []); | ||
|
||
const handleAdd = (newTodo: Todo): Promise<Todo | void> => { |
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.
why u need Todo in this place?
you don't use this feature to get an item(onSubmit - ur logic)
const handleAdd = (newTodo: Todo): Promise<Todo | void> => { | |
const handleAdd = (newTodo: Todo): Promise<void> => { |
src/App.tsx
Outdated
onDelete={handleDelete} | ||
/> | ||
|
||
{todos.length > 0 && ( |
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.
@OkMoroz !!
- converts the value to boolean type and more readable i think
src/api/todos.ts
Outdated
export const USER_ID = 2132; | ||
export const TODOS_ENDPOINT = '/todos'; |
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 it to a separate file - constants
const filtersValue = Object.values(Filters); | ||
const activeTodosCount = todos.filter(todo => !todo.completed).length; | ||
const isCompleted = todos.some(todo => todo.completed); | ||
let isDeleteCompleted = false; |
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.
loading state?
src/components/Footer.tsx
Outdated
const filtersValue = Object.values(Filters); | ||
const activeTodosCount = todos.filter(todo => !todo.completed).length; | ||
const isCompleted = todos.some(todo => 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.
useMemo?
src/components/Footer.tsx
Outdated
{filtersValue.map(filter => ( | ||
<a | ||
key={filter} | ||
href={`#/${filter !== Filters.All ? filter.toLowerCase() : ''}`} |
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.
will it be better?
href={`#/${filter !== Filters.All ? filter.toLowerCase() : ''}`} | |
href={`#/${filter !== Filters.All && filter.toLowerCase()}`} |
import { Todo } from '../types/Todo'; | ||
import { Loading } from '../types/Loading'; | ||
|
||
enum TodoKey { |
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 all the enums to the separate directory
src/components/TodoItem.tsx
Outdated
data-cy="TodoLoader" | ||
className={cn('modal overlay', { | ||
'is-active': | ||
Object.hasOwn(loadingId, todo.id) || isLoading || todo.id === 0, |
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 it to a variable, I don't fully understand what it is
src/components/TodoList.tsx
Outdated
/> | ||
))} | ||
|
||
{tempTodo !== null && ( |
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
{tempTodo !== null && ( | |
{!tempTodo && ( |
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 much more better, I'm approving it🔥