aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 15:48:23 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-27 15:48:23 -0600
commitc1f97240230ada378d77eeb8db726e0d936169c8 (patch)
treeec3b573878432099b2aba9adc7cf0116c9b9892b
parentac4a146682ede7bf661938b78a970d7da8bd868a (diff)
downloadToDo-App-FE-c1f97240230ada378d77eeb8db726e0d936169c8.tar.gz
ToDo-App-FE-c1f97240230ada378d77eeb8db726e0d936169c8.zip
Can now set a to do as done or undone.
Diffstat (limited to '')
-rw-r--r--src/ToDo-UI/ListToDo.jsx17
-rw-r--r--src/api/axios_methods.js26
2 files changed, 40 insertions, 3 deletions
diff --git a/src/ToDo-UI/ListToDo.jsx b/src/ToDo-UI/ListToDo.jsx
index 74c36de..c777f8f 100644
--- a/src/ToDo-UI/ListToDo.jsx
+++ b/src/ToDo-UI/ListToDo.jsx
@@ -11,7 +11,12 @@ import {
select_current_sorting,
} from "../features/todo/reducer";
-import { edit_todo_function, remove_todo_function } from "../api/axios_methods";
+import {
+ edit_todo_function,
+ remove_todo_function,
+ set_done_function,
+ set_undone_function,
+} from "../api/axios_methods";
function sort_table_header(prefix, current_sorting) {
if (prefix.toLowerCase().startsWith(current_sorting.substr(0, 3))) {
@@ -56,6 +61,9 @@ function list_of_todos(edit_button, delete_button) {
dispatch(refresh_filtered_todos());
}
+ const set_done_api = set_done_function();
+ const set_undone_api = set_undone_function();
+
// Table contents
var table_head = (
<thead>
@@ -90,13 +98,16 @@ function list_of_todos(edit_button, delete_button) {
checked={item.done}
id={"list-todo-done-" + item.id}
onChange={(e) => {
+ e.target.checked
+ ? set_done_api({ id: item.id })
+ : set_undone_api({ id: item.id });
dispatch(
change_done({
id: item.id,
done: e.target.checked,
})
- ),
- dispatch(refresh_filtered_todos());
+ );
+ dispatch(refresh_filtered_todos());
}}
></input>
</div>
diff --git a/src/api/axios_methods.js b/src/api/axios_methods.js
index 8748cb7..ffc0c28 100644
--- a/src/api/axios_methods.js
+++ b/src/api/axios_methods.js
@@ -60,3 +60,29 @@ export function remove_todo_function() {
}
};
}
+
+// setDone().
+export function set_done_function() {
+ // Set a to do as done. If already done, don't do anything.
+ // POST "/todos/{id}/done"
+ return async (data) => {
+ try {
+ await api.post(`/todos/${data.id}/done`);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+}
+
+// setUndone().
+export function set_undone_function() {
+ // Set a to do as not done. If it's already not done, don't do anything.
+ // PUT "/todos/{id}/undone"
+ return async (data) => {
+ try {
+ await api.put(`/todos/${data.id}/undone`);
+ } catch (err) {
+ console.log(err);
+ }
+ };
+}