From c08445f56f8650cf4928e494f0d1646f6a0ce698 Mon Sep 17 00:00:00 2001 From: Shanukumar Singh <91169674+Shanu2409@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:18:50 +0530 Subject: [PATCH 1/2] upgraded the completeTodo method --- client/src/App.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 48d41f7..8dc7f1e 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -17,18 +17,19 @@ function App() { .catch((err) => console.error("Error: ", err)); } - const completeTodo = async id => { - const data = await fetch(api_base + '/todo/complete/' + id).then(res => res.json()); - - setTodos(todos => todos.map(todo => { - if (todo._id === data._id) { - todo.complete = data.complete; - } - - return todo; - })); - - } + const completeTodo = async (id: string) => { + const response = await fetch(api + "/todo/complete/" + id); + const data = await response.json(); + + setTodos((todos: any) => + todos.map((todo: Todo) => { + if (todo._id === data._id) { + todo.complete = data.complete; + } + return todo; + }) + ); + }; const addTodo = async () => { const data = await fetch(api_base + "/todo/new", { From cc363b0d07ef018b1642423b9586402021382937 Mon Sep 17 00:00:00 2001 From: Shanukumar Singh <91169674+Shanu2409@users.noreply.github.com> Date: Mon, 3 Apr 2023 17:20:10 +0530 Subject: [PATCH 2/2] Update App.js --- client/src/App.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 8dc7f1e..12576e9 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -17,12 +17,12 @@ function App() { .catch((err) => console.error("Error: ", err)); } - const completeTodo = async (id: string) => { + const completeTodo = async (id) => { const response = await fetch(api + "/todo/complete/" + id); const data = await response.json(); - setTodos((todos: any) => - todos.map((todo: Todo) => { + setTodos((todos) => + todos.map((todo) => { if (todo._id === data._id) { todo.complete = data.complete; } @@ -31,6 +31,7 @@ function App() { ); }; + const addTodo = async () => { const data = await fetch(api_base + "/todo/new", { method: "POST",