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

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

Develop #1535

wants to merge 5 commits into from

Conversation

OkMoroz
Copy link

@OkMoroz OkMoroz commented Dec 17, 2024

src/App.tsx Outdated
return <UserWarning />;
}
const [todos, setTodos] = useState<Todo[]>([]);
const [errorMessage, setErrorMessage] = useState<string>('');

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 можна покласти довільний рядок

Copy link
Author

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>({});

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

Choose a reason for hiding this comment

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

краще вказати перевірку !!todos.length

Copy link
Author

Choose a reason for hiding this comment

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

чому саме той варіант кращий?

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

Copy link

@VolodymyrKirichenko VolodymyrKirichenko 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 let's make some changes

src/App.tsx Outdated
return <UserWarning />;
}
const [todos, setTodos] = useState<Todo[]>([]);
const [errorMessage, setErrorMessage] = useState<ErrorMessage | string>('');

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

Suggested change
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> => {

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)

Suggested change
const handleAdd = (newTodo: Todo): Promise<Todo | void> => {
const handleAdd = (newTodo: Todo): Promise<void> => {

src/App.tsx Outdated
onDelete={handleDelete}
/>

{todos.length > 0 && (

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
Comment on lines 4 to 5
export const USER_ID = 2132;
export const TODOS_ENDPOINT = '/todos';

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;

Choose a reason for hiding this comment

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

loading state?

Comment on lines 16 to 18
const filtersValue = Object.values(Filters);
const activeTodosCount = todos.filter(todo => !todo.completed).length;
const isCompleted = todos.some(todo => todo.completed);

Choose a reason for hiding this comment

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

useMemo?

{filtersValue.map(filter => (
<a
key={filter}
href={`#/${filter !== Filters.All ? filter.toLowerCase() : ''}`}

Choose a reason for hiding this comment

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

will it be better?

Suggested change
href={`#/${filter !== Filters.All ? filter.toLowerCase() : ''}`}
href={`#/${filter !== Filters.All && filter.toLowerCase()}`}

import { Todo } from '../types/Todo';
import { Loading } from '../types/Loading';

enum TodoKey {

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

data-cy="TodoLoader"
className={cn('modal overlay', {
'is-active':
Object.hasOwn(loadingId, todo.id) || isLoading || todo.id === 0,

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

/>
))}

{tempTodo !== null && (

Choose a reason for hiding this comment

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

the same

Suggested change
{tempTodo !== null && (
{!tempTodo && (

Copy link

@StasSokolov1 StasSokolov1 left a 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🔥

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