Speed up loading for home page
parent
b2f66b3e34
commit
36de9b3773
|
@ -60,7 +60,8 @@ async function loadTable() {
|
||||||
if(selectedTeamID && selectedDivisionID) {
|
if(selectedTeamID && selectedDivisionID) {
|
||||||
gamesTableHeader.textContent = `Scores for ${teamDropdown.options[teamDropdown.selectedIndex].text}`;
|
gamesTableHeader.textContent = `Scores for ${teamDropdown.options[teamDropdown.selectedIndex].text}`;
|
||||||
|
|
||||||
const gamesList = await Data.getGames(selectedTeamID, selectedDivisionID, selectedSeasonID);
|
const requestURL = `/fetch/index/scores?team=${+selectedTeamID}&division=${+selectedDivisionID}&season=${+selectedSeasonID}`;
|
||||||
|
const gamesList = await (await fetch(requestURL)).json();
|
||||||
if(gamesList.length > 0) {
|
if(gamesList.length > 0) {
|
||||||
await setupGamesTableHeaders();
|
await setupGamesTableHeaders();
|
||||||
|
|
||||||
|
@ -77,8 +78,7 @@ async function loadTable() {
|
||||||
row.appendChild(scoreCell);
|
row.appendChild(scoreCell);
|
||||||
|
|
||||||
const opponentCell = document.createElement('td');
|
const opponentCell = document.createElement('td');
|
||||||
Data.getTeam(game.team2ID)
|
opponentCell.textContent = game.opponent.name;
|
||||||
.then(data => opponentCell.textContent = data.name);
|
|
||||||
row.appendChild(opponentCell);
|
row.appendChild(opponentCell);
|
||||||
|
|
||||||
const dateCell = document.createElement('td');
|
const dateCell = document.createElement('td');
|
||||||
|
|
|
@ -59,4 +59,20 @@ router.get('/index/dropdown', async function(req, res, next) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.get('/index/scores', async function (req, res, next) {
|
||||||
|
try {
|
||||||
|
const seasonID = req.query.season;
|
||||||
|
const divisionID = req.query.division;
|
||||||
|
const teamID = req.query.team;
|
||||||
|
const data = await games.retrieve(teamID, divisionID, seasonID);
|
||||||
|
for (const game of data) {
|
||||||
|
game.opponent = await teams.getFromID(game.team2ID);
|
||||||
|
}
|
||||||
|
res.json(data);
|
||||||
|
} catch(err) {
|
||||||
|
console.error("ERROR: " + err.message);
|
||||||
|
res.status(500).send("An error has occurred");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
Reference in New Issue