From c95dbbbf5080cf144e07a134c3e30668085d2e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Oliva?= Date: Mon, 29 May 2023 00:28:38 -0600 Subject: First instance for pagination. Sorting and Filtering now WON'T be computed on Front End, but on Back End instead. --- src/api/axios_methods.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/api/axios_methods.js') diff --git a/src/api/axios_methods.js b/src/api/axios_methods.js index f983157..822c334 100644 --- a/src/api/axios_methods.js +++ b/src/api/axios_methods.js @@ -87,6 +87,55 @@ export function set_undone_function() { }; } +// setFiltersAndSorters(). +export function set_fil_sort_function() { + // Set filters and sorters for our to dos. + // POST "/todos/setFiltSort" + return async (data) => { + try { + await api.post("/todos/setFiltSort", { + filters: { + name: data.filter.name, + priority: data.filter.priority, + done: data.filter.state, + }, + sortField: data.sort.field, + sortOrder: data.sort.order, + }); + } catch (err) { + console.log(err); + } + }; +} + +// getPage(). +export function get_todos_page_function() { + // Return a page of max 10 to dos with sorting and filters added. + // GET "/todos/filtSort/{page}" + return async (handler, data) => { + try { + const response = await api.get(`/todos/filtSort/${data.page}`); + handler(response.data); + } catch (err) { + console.log(err); + } + }; +} + +// getNumberOfPages(). +export function get_nu_pages_function() { + // Return the number of pages in total. + // GET "/todos/filtSort/pages" + return async () => { + try { + const response = await api.get("/todos/filtSort/pages"); + return response.data; + } catch (err) { + console.log(err); + } + }; +} + // giveMeLastID(). export function get_last_id_function() { // Retrieve last index used. -- cgit v1.2.3