Skip to content

Commit

Permalink
123
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvalera committed Oct 3, 2024
1 parent c08a6bb commit d3a8150
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
24 changes: 14 additions & 10 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ export const Header = () => {
setTitle('');
};

const toogleTodoComplete = () => {
{
const allCompleted = todos.every((todo: Todo) => todo.completed);

setTodos((currentTodos: Todo[]) =>
currentTodos.map((todo: Todo) => ({
...todo,
completed: !allCompleted,
})),
);
}
};

return (
<header className="todoapp__header">
{todos.length > 0 ? (
<button
type="button"
className={`todoapp__toggle-all ${isAllCompleted ? 'active' : ''}`}
data-cy="ToggleAllButton"
onClick={() => {
const allCompleted = todos.every((todo: Todo) => todo.completed);

setTodos((currentTodos: Todo[]) =>
currentTodos.map((todo: Todo) => ({
...todo,
completed: !allCompleted,
})),
);
}}
onClick={toogleTodoComplete}
/>
) : null}

Expand Down
33 changes: 15 additions & 18 deletions src/components/state.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, {
useState,
createContext,
Expand All @@ -9,6 +8,7 @@ import React, {
import { Todo } from '../Types/Todo';
import { Filter } from '../Types/Filter';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const MyContext = createContext<any>(null);

interface MyProviderProps {
Expand All @@ -31,7 +31,6 @@ export const MyProvider = ({ children }: MyProviderProps) => {
if (savedTodos) {
setTodos(JSON.parse(savedTodos));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
Expand All @@ -46,22 +45,20 @@ export const MyProvider = ({ children }: MyProviderProps) => {
}
}, [todos]);

const contextValue = {
todos,
setTodos,
title,
setTitle,
filter,
setFilter,
editingTodoId,
setEditingTodoId,
deleteTodo,
inputRef,
};

return (
<MyContext.Provider
value={{
todos,
setTodos,
title,
setTitle,
filter,
setFilter,
editingTodoId,
setEditingTodoId,
deleteTodo,
inputRef,
}}
>
{children}
</MyContext.Provider>
<MyContext.Provider value={contextValue}>{children}</MyContext.Provider>
);
};

0 comments on commit d3a8150

Please sign in to comment.