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

Closed
wants to merge 6 commits into from
Closed

Develop #789

wants to merge 6 commits into from

Conversation

Koliras
Copy link

@Koliras Koliras commented Sep 25, 2023

Copy link

@Vannnkof Vannnkof 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!
Found just one bug
image

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.
Also, pay attention to the previous comment about the visual component of the application.

className="todoapp__new-todo"
placeholder="What needs to be done?"
value={newTodoTitle}
onChange={(event) => setNewTodoTitle(event.target.value)}

Choose a reason for hiding this comment

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

Suggested change
onChange={(event) => setNewTodoTitle(event.target.value)}
onChange={({ target }) => setNewTodoTitle(target.value)}

const [filterKey, setFilterKey] = useState<FilterKey>(FilterKey.All);
const [tempTodo, setTempTodo] = useState<Todo | null>(null);

const areAllTodosCompleted = todos.every(({ completed }) => completed);

Choose a reason for hiding this comment

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

I know that "are" would be lexically correct, but in programming it is customary to use "is" in all cases :)

{!!todos.length && (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{`${activeTodos.length} 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.

Copy link
Author

@Koliras Koliras Sep 27, 2023

Choose a reason for hiding this comment

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

Firstly, I wrote a code that would not use plural to a single todo, but tests required it to be plural
image

<div
data-cy="ErrorNotification"
className={
classNames('notification is-danger is-light has-text-weight-normal', {

Choose a reason for hiding this comment

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

Suggested change
classNames('notification is-danger is-light has-text-weight-normal', {
classNames('notification', 'is-danger', 'is-light', 'has-text-weight-normal', {

const { title, completed, id } = todo;
const [isBeingEdited, setIsBeingEdited] = useState(false);
const [newTitle, setNewTitle] = useState(title);
const editedInput = useRef<HTMLInputElement | null>(null);

Choose a reason for hiding this comment

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

Suggested change
const editedInput = useRef<HTMLInputElement | null>(null);
const editedInputRef = useRef<HTMLInputElement | null>(null);

ref={editedInput}
onChange={handleChangeOfTitle}
onKeyUp={handleKeyUp}
onBlur={() => handleNewTitleSubmit()}

Choose a reason for hiding this comment

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

Suggested change
onBlur={() => handleNewTitleSubmit()}
onBlur={handleNewTitleSubmit}

Comment on lines 177 to 179
className={classNames('modal overlay', {
'is-active': todo.id === 0 || todoIdsWithLoader.includes(id),
})}

Choose a reason for hiding this comment

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

Suggested change
className={classNames('modal overlay', {
'is-active': todo.id === 0 || todoIdsWithLoader.includes(id),
})}
className={classNames('modal', 'overlay', {
'is-active': !todo.id || todoIdsWithLoader.includes(id),
})}

event.preventDefault();

if (!newTodoTitle.trim()) {
onNewError('Title should not be empty');

Choose a reason for hiding this comment

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

It would be good to put error texts in a separate constant.

Comment on lines 65 to 81
todosToUpdate.forEach(todo => {
updateTodo(todo.id, { completed: !todo.completed })
.then(() => {
const todosCopy = [...todos];
const searchedTodo = todos.find(
({ id }) => todo.id === id,
) as Todo;

searchedTodo.completed = !searchedTodo.completed;

setTodos(todosCopy);
})
.catch(() => onNewError(ErrorMessage.UnableUpdate))
.finally(() => setTodoIdsWithLoader(
prevTodoIds => prevTodoIds.filter((todoId) => todoId !== todo.id),
));
});

Choose a reason for hiding this comment

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

Let's use Promise.all for updating todos

Comment on lines 93 to 100
deleteTodo(todo.id)
.then(() => {
setTodos(prevTodos => prevTodos.filter(({ id }) => id !== todo.id));
})
.catch(() => onNewError(ErrorMessage.UnableDelete))
.finally(() => setTodoIdsWithLoader(
prevTodoIds => prevTodoIds.filter((id) => todo.id !== id),
));

Choose a reason for hiding this comment

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

Also, try to use Promise.all

Comment on lines 135 to 137
<label
className="todo__status-label"
>

Choose a reason for hiding this comment

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

Suggested change
<label
className="todo__status-label"
>
<label className="todo__status-label">

import { ErrorContext } from '../ErrorContextProvider/ErrorContextProvider';
import { ErrorMessage } from '../../types/ErrorMessage';

function getFilteredTodos(key: FilterKey, todos: Todo[]) {

Choose a reason for hiding this comment

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

I would move this to separate file as a helper function

/>

{!!todos.length && (
<footer className="todoapp__footer" data-cy="Footer">

Choose a reason for hiding this comment

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

I would move footer to separate component

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.

Good work 🚀
Approved, but left a few suggestions, take a look.

return client.delete(`/todos/${todoId}`);
};

export const updateTodo = (todoId: number, changes: object) => {

Choose a reason for hiding this comment

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

changes have to have another type instead of an object, as we update a todo in this case, and not every object suits.
You can use some of the utility types, for example, Partial.
https://www.typescriptlang.org/docs/handbook/utility-types.html

Comment on lines +4 to +8
export const ErrorContext = React.createContext({
errorMessage: ErrorMessage.None,
setErrorMessage: () => {},
onNewError: () => {},
} as ErrorContextProps);

Choose a reason for hiding this comment

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

Suggested change
export const ErrorContext = React.createContext({
errorMessage: ErrorMessage.None,
setErrorMessage: () => {},
onNewError: () => {},
} as ErrorContextProps);
export const ErrorContext = React.createContext<ErrorContextProps>({
errorMessage: ErrorMessage.None,
setErrorMessage: () => {},
onNewError: () => {},
});

Don't use as, createContext accepts generic

Comment on lines +74 to +91
<header className="todoapp__header">
{!!todos.length && (
<button
type="button"
data-cy="ToggleAllButton"
className={classNames('todoapp__toggle-all', {
active: isAllTodosCompleted,
})}
aria-label="toggle_all_todos"
onClick={handleAllTodosToggle}
/>
)}

<NewTodo
setTempTodo={setTempTodo}
tempTodo={tempTodo}
/>
</header>

Choose a reason for hiding this comment

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

You can create a Header component

Comment on lines +112 to +119
const todosCopy = [...todos];
const searchedTodo = todos.find(
({ id: todoId }) => todoId === id,
) as Todo;

searchedTodo.completed = !event.target.checked;

setTodos(todosCopy);

Choose a reason for hiding this comment

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

Suggested change
const todosCopy = [...todos];
const searchedTodo = todos.find(
({ id: todoId }) => todoId === id,
) as Todo;
searchedTodo.completed = !event.target.checked;
setTodos(todosCopy);
setTodos(prevTodos => (
prevTodos.map(todo => todoId === todo.id ? updatedTodo : todo)
));

Use map instead of find.

@Koliras Koliras closed this by deleting the head repository Dec 16, 2024
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.

5 participants