Add sports to single request

main
sudoer777 2022-03-07 12:27:10 -07:00
parent cc66467197
commit 1e78e37913
1 changed files with 9 additions and 4 deletions

View File

@ -1,9 +1,14 @@
import * as Data from "./data.js";
export async function populateSports(sportDropdown, selectedSportID = undefined) {
export async function populateSports(sportDropdown, selectedSportID = undefined, data = undefined) {
sportDropdown.innerHTML = "";
const sportsList = await Data.getSports();
let sportsList;
if(data) {
sportsList = data.sports;
} else {
sportsList = await Data.getSports();
}
let currentIndex = 0;
let selectedSportIndex;
@ -13,7 +18,7 @@ export async function populateSports(sportDropdown, selectedSportID = undefined)
option.value = sport.id;
sportDropdown.appendChild(option);
if(sport.id == selectedSportID) selectedSportIndex = currentIndex;
if(sport.id == selectedSportID || (data && sport.id == data.latestGame.sportID)) selectedSportIndex = currentIndex;
currentIndex++;
});
@ -30,7 +35,7 @@ export async function populateSeasons(seasonDropdown, selectedSeasonID = undefin
} else {
seasonsList = await Data.getSeasons();
}
console.log(data);
let currentIndex = 0;
let selectedSeasonIndex;
seasonsList.forEach(season => {