From 4285674ab37c74a24b265ace4d15d4848457d375 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= <adrian.oliva@cimat.mx>
Date: Mon, 29 May 2023 12:42:46 -0600
Subject: Pagination now works on to do's list.

Only 10 to dos will be shown at a time. You can sort by priority or due
date and it should work on all of our to dos. Edit and delete also
works.
---
 src/App.jsx | 57 ++++++++-------------------------------------------------
 1 file changed, 8 insertions(+), 49 deletions(-)

(limited to 'src/App.jsx')

diff --git a/src/App.jsx b/src/App.jsx
index 9d5cbd8..87aa833 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -6,63 +6,22 @@ import { ListToDos } from "./ToDo-UI/ListToDo";
 import { useDispatch, useSelector } from "react-redux";
 import {
     set_last_id,
-    set_todo,
     select_current_filters,
     select_current_sorting,
+    select_current_page,
 } from "./features/todo/reducer";
 
-import {
-    set_fil_sort_function,
-    get_todos_page_function,
-    get_last_id_function,
-} from "./api/axios_methods";
-
-function App() {
-    // Set default sorting and filters on back end.
-    const set_fil_sor_api = set_fil_sort_function();
+import { get_last_id_function } from "./api/axios_methods";
 
-    const my_filters = useSelector(select_current_filters);
-    const my_sorting = useSelector(select_current_sorting);
-    set_fil_sor_api({
-        filter: {
-            name: my_filters.name,
-            priority: my_filters.priority,
-            state: my_filters.state,
-        },
-        sort: {
-            field: my_sorting.split("/")[0],
-            order: my_sorting.split("/")[1],
-        },
-    });
+import { refresh_todos } from "./refreshToDos";
 
-    // Retrieve the first page of our to dos.
-    const get_todos_api = get_todos_page_function();
+function App() {
     const dispatch = useDispatch();
+    const my_filters = useSelector(select_current_filters);
+    const my_sorters = useSelector(select_current_sorting);
+    const my_curr_page = useSelector(select_current_page);
 
-    function write_todos_redux(data) {
-        data.map((todo) => {
-            const due_date = new Date(todo.dueDate);
-            const offset = due_date.getTimezoneOffset();
-
-            dispatch(
-                set_todo({
-                    id: todo.id,
-                    text: todo.text,
-                    due_date:
-                        todo.dueDate != null
-                            ? new Date(due_date - offset * 60 * 1000)
-                                  .toISOString()
-                                  .slice(0, -1)
-                            : "",
-                    done: todo.done,
-                    priority: todo.priority,
-                    creation_date: todo.creationDate,
-                })
-            );
-        });
-    }
-    get_todos_api(write_todos_redux, { page: 1 });
-
+    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) => {
-- 
cgit v1.2.3

