aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 18:28:55 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 18:28:55 -0600
commitdaee56ba5509a4576fa066adfcc0d1bc05f98802 (patch)
tree0c0fd7ebb94ca5c4ad82dbea16ba2b58e91900a2
parent4285674ab37c74a24b265ace4d15d4848457d375 (diff)
downloadToDo-App-FE-daee56ba5509a4576fa066adfcc0d1bc05f98802.tar.gz
ToDo-App-FE-daee56ba5509a4576fa066adfcc0d1bc05f98802.zip
Adding new to dos is now synchronized with database.
Changed the `refreshToDos` to also refresh the last index used.
Diffstat (limited to '')
-rw-r--r--src/App.jsx10
-rw-r--r--src/ToDo-UI/NewToDo.jsx28
-rw-r--r--src/features/todo/reducer.js1
-rw-r--r--src/refreshToDos.js18
4 files changed, 29 insertions, 28 deletions
diff --git a/src/App.jsx b/src/App.jsx
index 87aa833..9ef710e 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -5,7 +5,6 @@ import { ListToDos } from "./ToDo-UI/ListToDo";
import { useDispatch, useSelector } from "react-redux";
import {
- set_last_id,
select_current_filters,
select_current_sorting,
select_current_page,
@@ -22,15 +21,6 @@ function App() {
const my_curr_page = useSelector(select_current_page);
refresh_todos(my_filters, my_sorters, my_curr_page, dispatch);
- // Finally, retrieve the last index used for a to do.
- const last_id_api = get_last_id_function();
- last_id_api((response) => {
- dispatch(
- set_last_id({
- id: response,
- })
- );
- });
return (
<div>
diff --git a/src/ToDo-UI/NewToDo.jsx b/src/ToDo-UI/NewToDo.jsx
index dc062db..313456b 100644
--- a/src/ToDo-UI/NewToDo.jsx
+++ b/src/ToDo-UI/NewToDo.jsx
@@ -1,14 +1,16 @@
import React, { useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import {
- add_todo,
- sort_todo,
- refresh_filtered_todos,
select_last_index,
+ select_current_filters,
+ select_current_sorting,
+ select_current_page,
} from "../features/todo/reducer";
import { new_todo_function } from "../api/axios_methods";
+import { refresh_todos } from "../refreshToDos";
+
function new_button(trigger_id) {
return (
<div className="container mt-3 mb-3">
@@ -46,6 +48,10 @@ export function NewToDo() {
const [new_due_date, set_new_due_date] = useState("");
const [new_priority, set_new_priority] = useState("Low");
+ const my_filters = useSelector(select_current_filters);
+ const my_sorters = useSelector(select_current_sorting);
+ const my_curr_page = useSelector(select_current_page);
+
const new_todo_api = new_todo_function();
function handle_exit_modal() {
@@ -65,19 +71,9 @@ export function NewToDo() {
: new Date(new_due_date).toISOString(),
priority: new_priority,
});
- dispatch(
- add_todo({
- text: new_text,
- due_date:
- new_due_date.length == 0
- ? ""
- : new Date(new_due_date).toISOString(),
- priority: new_priority,
- creation_date: new Date().toISOString(),
- })
- );
- dispatch(sort_todo());
- dispatch(refresh_filtered_todos());
+ setTimeout(() => {
+ refresh_todos(my_filters, my_sorters, my_curr_page, dispatch);
+ }, 100);
handle_exit_modal();
}
diff --git a/src/features/todo/reducer.js b/src/features/todo/reducer.js
index 8a2e9b8..edd2b73 100644
--- a/src/features/todo/reducer.js
+++ b/src/features/todo/reducer.js
@@ -53,7 +53,6 @@ export const todo_slice = createSlice({
creation_date: action.payload.creation_date,
},
];
- state.last_id++;
} else {
state.todos[selected_todo].text = action.payload.text;
state.todos[selected_todo].due_date = action.payload.due_date;
diff --git a/src/refreshToDos.js b/src/refreshToDos.js
index c599606..a6b1368 100644
--- a/src/refreshToDos.js
+++ b/src/refreshToDos.js
@@ -1,9 +1,15 @@
-import { set_todo, empty_todos, change_page } from "./features/todo/reducer";
+import {
+ set_last_id,
+ set_todo,
+ empty_todos,
+ change_page,
+} from "./features/todo/reducer";
import {
set_fil_sort_function,
get_todos_page_function,
get_nu_pages_function,
+ get_last_id_function,
} from "./api/axios_methods";
export function refresh_todos(my_filters, my_sorters, my_curr_page, dispatch) {
@@ -64,4 +70,14 @@ export function refresh_todos(my_filters, my_sorters, my_curr_page, dispatch) {
}
get_todos_api(handle_new_todos_page, { page: my_curr_page });
+
+ // Finally, retrieve the last index used for a to do.
+ const last_id_api = get_last_id_function();
+ last_id_api((response) => {
+ dispatch(
+ set_last_id({
+ id: response,
+ })
+ );
+ });
}