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

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

Conversation

VikaChereushenko
Copy link

@VikaChereushenko VikaChereushenko commented Dec 13, 2024

Copy link

@TarasHoliuk TarasHoliuk left a comment

Choose a reason for hiding this comment

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

GJ 👍 It works perfect. Added comments to refactor your code and make it better

src/App.tsx Outdated
onSubmit={handleSubmit}
loading={loading}
title={title}
onTitleChange={value => setTitle(value)}

Choose a reason for hiding this comment

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

Suggested change
onTitleChange={value => setTitle(value)}
onTitleChange={setTitle}

arg1: React.KeyboardEvent<HTMLInputElement>,
arg2: React.Dispatch<React.SetStateAction<boolean>>,
) => void;
processedIs: number[];

Choose a reason for hiding this comment

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

Suggested change
processedIs: number[];
processedIds: number[];

typo - fix everywhere

onItemTitleUpdate(
id,
newTitle,
setTitleBeingUpdated,

Choose a reason for hiding this comment

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

no need to pass this function as a callback

Just create onBlur function here and call inputRef.current.focus(); there

isTitleChanged,
)
}
onKeyUp={event => onKeyUp(event, setTitleBeingUpdated)}

Choose a reason for hiding this comment

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

same - remove setTitleBeingUpdated state at all

src/App.tsx Outdated
Comment on lines 196 to 198
setTitleBeingUpdated: React.Dispatch<React.SetStateAction<boolean>>,
isTitleChanged: boolean,
e?: React.FormEvent<HTMLFormElement>,

Choose a reason for hiding this comment

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

do not pass it as an arguments

Instead, in TodoItem component create a separate function handler onSubmit. In this function, you should apply local logic (event.preventDefault, input focus, etc.) and just call this function with todo id and new title

Apply the same approach for other functions as well

type Props = {
todos: Todo[];
status: TodoStatus;
onStatusChange: (arg: TodoStatus) => void;

Choose a reason for hiding this comment

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

Suggested change
onStatusChange: (arg: TodoStatus) => void;
onStatusChange: (status: TodoStatus) => void;

arg is a bad name, even in types

}) => {
const activeTodos = todos.filter(todo => !todo.completed);
const isAnyCompleted = todos.some(todo => todo.completed);
const filterOptions = Object.values(TodoStatus);

Choose a reason for hiding this comment

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

nit: you can move this variable outside of the component

const isAnyCompleted = todos.some(todo => todo.completed);
const filterOptions = Object.values(TodoStatus);

const capitalizeFirstLetter = (value: TodoStatus) => {

Choose a reason for hiding this comment

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

Same - you can create this function outside of the component (or even in a separate helpers.ts file and import it here)

title: string;
onItemDelete: (id: number) => void;
onItemStatusUpdate: (id: number) => void;
onItemTitleUpdate: (

Choose a reason for hiding this comment

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

you can simplify this function (see other comments)
Also, write correct names for arguments

src/App.tsx Outdated
.catch(() => setErrorMessage('Unable to load todos'));
}, []);

const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {

Choose a reason for hiding this comment

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

Do not forget about useCallback and useMemo for functions and values

Copy link

@volodymyr-soltys97 volodymyr-soltys97 left a comment

Choose a reason for hiding this comment

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

Great work! 🔥
You can remove empty files
image

@VikaChereushenko
Copy link
Author

got you!)

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.

3 participants