From 3c9d972b48690c1d5f379398831f98a0c3c11430 Mon Sep 17 00:00:00 2001 From: William Noris Date: Tue, 19 Oct 2021 12:37:14 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20getPage=20dans=20util.js=20et=20r?= =?UTF-8?q?=C3=A9cup=C3=A9ration=20de=20la=20page=20cournate=20dans=20plan?= =?UTF-8?q?ets.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/planets.js | 5 ++++- scripts/util.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/planets.js b/scripts/planets.js index 40463ca..af1ccbf 100644 --- a/scripts/planets.js +++ b/scripts/planets.js @@ -1,4 +1,4 @@ -import { api_call, API_URL } from "./util"; +import { api_call, API_URL, getPage } from "./util"; const planetes = document.getElementById("resultats"); @@ -48,7 +48,10 @@ function remplissage(results){ } //Pagination + const currentPage = previousUrl == null ? getPage(nextUrl) - 1 : getPage(previousUrl) + 1; + } + api_call(API_URL + "/planets", remplissage); \ No newline at end of file diff --git a/scripts/util.js b/scripts/util.js index e5c8ae1..9397675 100644 --- a/scripts/util.js +++ b/scripts/util.js @@ -21,3 +21,16 @@ export const api_call = (url, callback) => { }); } +/** + * Récupère le numéro de la page courante + * @param {string} url l'url d'un résultat multipage (qui se termine par ?page=2 par exemple) + * @returns Le numéro de la page de l'url + */ +export const getPage = (url) => { + tabUrl = url.split('/'); + pageEgal = tabUrl[tabUrl.length - 1]; + tabPageEgal = pageEgal.split('='); + numeroPage = tabPageEgal[tabPageEgal.length - 1]; + + return numeroPage; +}