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

Add task solution #1497

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

Add task solution #1497

wants to merge 2 commits into from

Conversation

WatarJoy
Copy link

Copy link

@dokrod dokrod 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!

Copy link

@igorkruz igorkruz 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 👍
let's improve your solution

Watch the attached video and fix the bug
https://www.loom.com/share/351ebf9f477e46f0bbe0d5437efdb54d

src/App.tsx Outdated
return <UserWarning />;
}
const [todos, setTodos] = useState<Todo[]>([]);
const [error, setError] = useState<string | 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 [error, setError] = useState<string | null>(null);
const [error, setError] = useState<ErrorMessages>(ErrorMessages.DEFAULT);

src/App.tsx Outdated
const [isEditingId, setIsEditingId] = useState<number | null>(null);

const handleAddTodo = useCallback(async (): Promise<void> => {
if (title.trim() === '') {

Choose a reason for hiding this comment

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

Create a variable for trimmed title as u use it more than once.

src/App.tsx Outdated
} catch {
setError(ErrorMessages.ADDING_TODOS);
setTempTodo(null);
setTimeout(() => setError(null), 3000);

Choose a reason for hiding this comment

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

Consider clearing timeouts when the component unmounts to avoid potential memory leaks and ensure smooth handling of state updates. This will improve the reliability of your code and prevent errors in case the DOM element is no longer available.

src/App.tsx Outdated
Comment on lines 224 to 235
const fetchTodos = async () => {
try {
const data = await getTodos();

setTodos(data);
} catch (err) {
setError(ErrorMessages.LOAD_TODOS);
const timer = setTimeout(() => setError(null), 3000);

return () => clearTimeout(timer);
}
};

Choose a reason for hiding this comment

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

Move the fetch Todos function out from useEffect

return (
<footer className="todoapp__footer" data-cy="Footer">
<span className="todo-count" data-cy="TodosCounter">
{`${activeTodos} items left`}

Choose a reason for hiding this comment

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

Suggested change
{`${activeTodos} items left`}
{activeTodos} items left

onHideError: () => void;
}

export const ErrorNotification: React.FC<ErrorNotificationProps> = ({

Choose a reason for hiding this comment

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

Suggested change
export const ErrorNotification: React.FC<ErrorNotificationProps> = ({
export const ErrorNotification: FC<ErrorNotificationProps> = ({

</span>

<nav className="filter" data-cy="Filter">
{Object.values(FilterStates).map(state => (

Choose a reason for hiding this comment

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

Create a variable for this Object.values(FilterStates)

await onDelete(todo.id);
} catch {
setError(ErrorMessages.DELETING_TODOS);
setTimeout(() => setError(null), 3000);

Choose a reason for hiding this comment

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

Move the setTimeout to the useEffect and add the array dependency with ErrorMessages

};

return (
<div data-cy="Todo" className={`todo ${todo.completed ? 'completed' : ''}`}>

Choose a reason for hiding this comment

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

it's better to use classnames in cases like that, it allows you to dynamically toggle classes based on state or props without manually concatenating strings, making the code more maintainable and easier to read.

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