Skip to content

Commit

Permalink
fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksymMohyla committed Nov 7, 2024
1 parent ba8c4e4 commit fc3c968
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
24 changes: 13 additions & 11 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';
import { Header } from './components/Header';
import { TodoList } from './components/TodoList';
import { Footer } from './components/Footer';
import { TodosContext, TodosProvider } from './services/TodosContext&Provider';
import { TodosContext } from './services/TodosContext&Provider';

export const App: React.FC = () => {
const { todos } = useContext(TodosContext);

useEffect(() => {
console.log(todos);

Check failure on line 11 in src/App.tsx

View workflow job for this annotation

GitHub Actions / run_linter (20.x)

Unexpected console statement
}, [todos]);

return (
<TodosProvider>
<div className="todoapp">
<h1 className="todoapp__title">todos</h1>
<Header />
<div className="todoapp">
<h1 className="todoapp__title">todos</h1>
<Header />

<div className="todoapp__content">
<TodoList />
<div className="todoapp__content">
<TodoList />

{!!todos.length && <Footer />}
</div>
{!!todos.length && <Footer />}
</div>
</TodosProvider>
</div>
);
};
3 changes: 1 addition & 2 deletions src/components/TodoList/TodoItem/TodoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ export const TodoItem: React.FC<Props> = ({ todo }) => {
type="checkbox"
className="todo__status"
checked={todo.completed}
onClick={() => toggleTodo(todo.id)}
onChange={() => toggleTodo(todo.id)}
/>
</label>

{/* This form is shown instead of the title and remove button upon editing todo*/}
{selectedTodo === todo ? (
<form
onSubmit={ev => {
Expand Down
7 changes: 6 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { createRoot } from 'react-dom/client';
import './styles/index.scss';

import { App } from './App';
import { TodosProvider } from './services/TodosContext&Provider';

const container = document.getElementById('root') as HTMLDivElement;

createRoot(container).render(<App />);
createRoot(container).render(
<TodosProvider>
<App />
</TodosProvider>,
);
1 change: 1 addition & 0 deletions src/services/TodoHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const useTodo = () => {

return {
todos,
setTodos,
addTodo,
removeTodo,
clearCompleted,
Expand Down
4 changes: 2 additions & 2 deletions src/services/TodosContext&Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type TodosContextType = {
setSelectedFilter: (filter: TodoFilter) => void;
};

const storedTodos = localStorage.getItem('todos');
export const storedTodos = localStorage.getItem('todos');

export const TodosContext = React.createContext<TodosContextType>({
todos: JSON.parse(storedTodos),
todos: storedTodos ? JSON.parse(storedTodos) : [],
setTodos: () => {},
selectedFilter: TodoFilter.All,
setSelectedFilter: () => {},
Expand Down

0 comments on commit fc3c968

Please sign in to comment.