-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fabio Fernandes
committed
Jun 21, 2024
1 parent
c1d401a
commit b7a3d09
Showing
26 changed files
with
6,842 additions
and
984 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,67 @@ | ||
import React, { Fragment } from "react"; | ||
import React, { Fragment, useEffect, useState } from "react"; | ||
import axios from "axios"; | ||
import "./App.css"; | ||
|
||
// components | ||
// Components | ||
|
||
import InputTodo from "./components/InputTodo"; | ||
import ListTodos from "./components/ListTodos"; | ||
|
||
const baseUrl = | ||
process.env.REACT_APP_ECS_SERVICE_URL || `http://localhost:5000`; | ||
|
||
function App() { | ||
const [todos, setTodos] = useState([]); | ||
|
||
const getTodos = async () => { | ||
try { | ||
const response = await axios.get(`${baseUrl}/todos`); | ||
|
||
setTodos(response.data); | ||
console.log(response.data); | ||
} catch (err) { | ||
console.error(err.message); | ||
} | ||
}; | ||
|
||
const deleteTodo = async (id) => { | ||
try { | ||
await axios.delete(`${baseUrl}/todos/${id}`); | ||
|
||
getTodos(); | ||
} catch (err) { | ||
console.error(err.message); | ||
} | ||
}; | ||
|
||
// Ensures getTodos is called when the component mounts. | ||
useEffect(() => { | ||
getTodos(); | ||
}, []); | ||
|
||
// Re-fetch todos after adding a new one | ||
const handleAddTodo = () => { | ||
getTodos(); | ||
}; | ||
|
||
// Re-fetch todos after an update | ||
const onUpdateTodo = async () => { | ||
await getTodos(); | ||
console.log("Todo Updated"); | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<div className="container"> | ||
<InputTodo /> | ||
<ListTodos /> | ||
<InputTodo onAddTodo={handleAddTodo} /> | ||
<ListTodos | ||
todos={todos} | ||
deleteTodo={deleteTodo} | ||
onUpdateTodo={onUpdateTodo} | ||
/> | ||
</div> | ||
</Fragment> | ||
); | ||
} | ||
|
||
export default App; | ||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.