aboutsummaryrefslogtreecommitdiff
path: root/src/refreshToDos.js
diff options
context:
space:
mode:
authorAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 21:49:56 -0600
committerAdrián Oliva <adrian.oliva@cimat.mx>2023-05-29 21:49:56 -0600
commitac0d9f421f1304306d9b3a264a225966fa9d5677 (patch)
tree4673c200a6ccc318b49ac6d42cb87ff123204d1f /src/refreshToDos.js
parente0ce800a647a1b173979f0e7f20d1d54b9f9bd7d (diff)
downloadToDo-App-FE-ac0d9f421f1304306d9b3a264a225966fa9d5677.tar.gz
ToDo-App-FE-ac0d9f421f1304306d9b3a264a225966fa9d5677.zip
IT NOW HAS PAGING.
Diffstat (limited to '')
-rw-r--r--src/refreshToDos.js28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/refreshToDos.js b/src/refreshToDos.js
index a6b1368..250b399 100644
--- a/src/refreshToDos.js
+++ b/src/refreshToDos.js
@@ -29,17 +29,27 @@ export function refresh_todos(my_filters, my_sorters, my_curr_page, dispatch) {
});
// Get the total number of pages. Change the current page if necessary.
- const get_nu_pages_api = get_nu_pages_function();
- const total_pages_api = get_nu_pages_api();
-
- if (total_pages_api < my_curr_page) {
- dispatch(
- change_page({
- page: total_pages_api,
- })
- );
+ function handle_out_of_bounds(total_pages) {
+ if (total_pages == 0) {
+ dispatch(
+ change_page({
+ page: 1,
+ })
+ );
+ } else if (total_pages < my_curr_page) {
+ dispatch(
+ change_page({
+ page: total_pages,
+ })
+ );
+ }
}
+ const get_nu_pages_api = get_nu_pages_function();
+ const total_pages_api = get_nu_pages_api((nu_pages) => {
+ handle_out_of_bounds(nu_pages);
+ });
+
// Delete all current to dos we have stored and retrieve new to dos from API.
const get_todos_api = get_todos_page_function();