From 8b0c617c995e4f40d5c602e01d094513d3e7ca02 Mon Sep 17 00:00:00 2001 From: William Noris Date: Tue, 19 Oct 2021 15:23:08 +0200 Subject: [PATCH] Boutons pagination en cours --- scripts/planets.js | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/scripts/planets.js b/scripts/planets.js index af1ccbf..03436ff 100644 --- a/scripts/planets.js +++ b/scripts/planets.js @@ -4,6 +4,7 @@ const planetes = document.getElementById("resultats"); console.log('planet.js loaded'); + function remplissage(results){ planetes.innerHTML = ""; @@ -48,10 +49,35 @@ function remplissage(results){ } //Pagination - const currentPage = previousUrl == null ? getPage(nextUrl) - 1 : getPage(previousUrl) + 1; - + console.log("Url précédente : " + previousUrl); + console.group("Url suivante : " + nextUrl); + const currentPage = (previousUrl == null ? parseInt(getPage(nextUrl)) - 1 : parseInt(getPage(previousUrl)) + 1); + console.log("Page courante : " + currentPage); + let firstPage = false; + let lastPage = false; + if(previousUrl == null) firstPage = true; + if(nextUrl == null) lastPage = true; + let previousButton = ``; + let currentButton = `${currentPage}`; + let nextButton = ``; + if(!firstPage) { + planetes.innerHTML += previousButton; + console.log(document.getElementById("prevButton")); + document.getElementById("prevButton").addEventListener("click", () => { + api_call(previousUrl, remplissage); + }); + } + planetes.innerHTML += currentButton; + if(!lastPage) { + planetes.innerHTML += nextButton; + document.getElementById("nextButton").addEventListener("click", () => { + api_call(nextUrl, remplissage); + }); + }; + + + } - -api_call(API_URL + "/planets", remplissage); \ No newline at end of file +api_call(API_URL + "/planets", remplissage);