Skip to content

Commit

Permalink
Bug Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierLora committed Apr 1, 2024
1 parent b486399 commit a95f1f7
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions stats/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ async function getTeamStats() {
throw new Error('Error fetching NBA Teams');
}
}
function handleScroll(event) {
const playerListContainer = event.target.matches('.player-list-container');

if (playerListContainer) {
// Calculate visible range of players based on scroll position
const scrollTop = playerListContainer.scrollTop;
const visibleHeight = playerListContainer.clientHeight;
const visibleStart = Math.floor(scrollTop / playerRowHeight);
console.log(playerRowHeight);
const visibleEnd = Math.min(
Math.ceil((scrollTop + visibleHeight) / playerRowHeight),
players.length
);

// Render only the visible players
let playerRows = '';
for (let i = visibleStart; i < visibleEnd; i++) {
let obj = players[i];
playerRows += generatePlayerRow(obj);
}
playerListContainer.innerHTML = playerRows;
}
}

// Attach scroll event listener to a parent element using event delegation
document.addEventListener('scroll', handleScroll);

document.addEventListener('DOMContentLoaded', async function(){
const teams = await Promise.all([getTeamStats()]);
Expand Down Expand Up @@ -229,7 +255,7 @@ const teamsMachine = (obj) => {
<th>Reb</th>
</tr>
</thead>
<tbody>
<tbody class="player-list-container">
<!-- row 1 -->
${generateTeamPlayerRows(obj.athletes)}
Expand All @@ -253,15 +279,17 @@ const teamsMachine = (obj) => {
}



const generateTeamPlayerRows = (playerList) => {
// Get the first array from playerData to iterate over
let playerRows = '';


for (let i = 0; i < playerList.length; i++) {
let obj = playerList[i];
playerRows += `
let obj = playerList[i];
playerRows += generatePlayerRow(obj);
}
return playerRows;
}

const generatePlayerRow = (obj) => {
return `
<tr>
<th class="text-sm">${obj.players.jersey}</th>
<td class="text-sm" id="playerNameGamesContainer">
Expand All @@ -276,11 +304,8 @@ const generateTeamPlayerRows = (playerList) => {
<td class="text-sm">${obj.stats.splits.categories[2].stats[32].displayValue}</td>
<td class="text-sm">${obj.stats.splits.categories[1].stats[15].displayValue}</td>
</tr>
`;
}

return playerRows;
}
`;
};

const generateTeamPlayers = (players) => {
let playerHtml = '';
Expand Down

0 comments on commit a95f1f7

Please sign in to comment.