diff --git a/src/main/webapp/js/requests.js b/src/main/webapp/js/requests.js index 2e2177632e292c5668a4cc339ba56b843f1d1c3e..abddde5484de322188f926854f298a27bdcfa9e4 100644 --- a/src/main/webapp/js/requests.js +++ b/src/main/webapp/js/requests.js @@ -62,18 +62,3 @@ function createPokemonTypesTable() { ` } -function createTrainer() { - const name = document.getElementById('trainerName').value; - const profileurl = document.getElementById('profileUrl').value; - const data = { - profileUrl: profileurl, - name: name - } - fetch('/pokemon/api/trainers', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify(data) - }).then(response => updateTrainerTable()) -} \ No newline at end of file diff --git a/src/main/webapp/js/trainers.js b/src/main/webapp/js/trainers.js index c114fed8b48ab1607ecc100e5e6e3e5f3682d46c..357ca1944e86a66b45f9ae65930ae476ec8e34a7 100644 --- a/src/main/webapp/js/trainers.js +++ b/src/main/webapp/js/trainers.js @@ -60,4 +60,33 @@ function createPokemonTypesTable() { </tbody> </table> ` +} + +function createTrainer() { + const name = document.getElementById('trainerName').value; + const profileurl = document.getElementById('profileUrl').value; + const data = { + profileUrl: profileurl, + name: name + } + fetch('/pokemon/api/trainers', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }).then(response => updateTrainerTable()) +} + +function updateTrainerTable() { + fetch('/pokemon/api/trainers') + .then(res => res.json()) + .then(data => { + pokemonTypes = data; + createTrainerTable(); + }) + .catch(err => { + console.error(`Unable to fetch Pokemon Types: ${err.status}`); + console.error(err); + }); } \ No newline at end of file diff --git a/src/main/webapp/trainers.html b/src/main/webapp/trainers.html index 764dc874a3c981ee40e5b6a8fb5cc3f77e64fbdb..ad18d6ec24b328fc9b8018511719a5b8ea1fca6f 100644 --- a/src/main/webapp/trainers.html +++ b/src/main/webapp/trainers.html @@ -14,7 +14,7 @@ </head> <body> -<script src="js/requests.js"></script> +<script src="js/trainers.js"></script> <script> tableParentId = "tableDiv"; detailsParentId = "detailsDiv";