diff --git a/public/javascript/user.js b/public/javascript/user.js index 36ecba2..13a7343 100644 --- a/public/javascript/user.js +++ b/public/javascript/user.js @@ -73,15 +73,14 @@ function padNumber(num, size) { return s; } -async function getSongInformation(id) { - const musicData = await musicMetadata(); +async function getSongInformation(musicData,id) { const songMatch = musicData[id]; if (!songMatch) { - return null; + return null; } return songMatch; - } - +} + // Ban Check lmao @@ -144,53 +143,80 @@ request.send(); // User Play Log -async function userPlayLogFormatter(div) { +let scoreIncrement = 0; +let errorIncrement = 0; +let displayedScoreCount = 20; + +async function userPlayLogFormatter(div, loadMoreButton) { const UserPlayLogData = await UserPlayLog(aime_card_id); - const musicIds = UserPlayLogData.map(score => score.music_id); - const songs = await Promise.all(musicIds.map(getSongInformation)); - - let myDiv = document.getElementById("scoreWrapper"); - if (myDiv === null) { - const scoresWrapperDiv = document.createElement('div'); + let scoresWrapperDiv = document.getElementById("scoreWrapper"); + + // If the scores wrapper div doesn't exist, create it. + if (scoresWrapperDiv === null) { + scoresWrapperDiv = document.createElement('div'); scoresWrapperDiv.id = "scoreWrapper"; - - for (let i = UserPlayLogData.length - 1; i >= 0; i--) { - const newDiv = document.createElement('div'); - let score = JSON.parse(JSON.stringify(UserPlayLogData[i])); - let song = JSON.parse(JSON.stringify(songs[i])); - - if (!song || !song.name) { - console.log(song) - console.log(score.music_id) - console.log("Song or title is undefined"); - continue; - } - - newDiv.innerHTML = ` -
${errorIncrement} Songs Failed to load properly, most likely due to missing information.
`); + } + + // If there are no more scores to load, hide the "Load More" button. + if (startIndex + scoreIncrement >= UserPlayLogData.length) { + loadMoreButton.style.display = "none"; + } } + + //===================================================================== // Now Exiting: User Data ////////////// Now Entering: Nested Div Hell //===================================================================== @@ -238,27 +264,27 @@ function UserPlayLog(aime_card_id) { async function musicMetadata() { const url = "/assets/metadata/musicMetadata.json"; - + try { - const response = await fetch(url, { - method: "GET", - headers: { - "Content-Type": "application/json", - }, - }); - - const data = await response.json(); - - const mapping = {}; - data.forEach((song) => { - mapping[song.name.id] = song; - }); - - return mapping; + const response = await fetch(url, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + }); + + const data = await response.json(); + + const mapping = {}; + data.forEach((song) => { + mapping[song.name.id] = song; + }); + + return mapping; } catch (error) { - console.error(error); + console.error(error); } - } - - - +} + + + diff --git a/views/user.ejs b/views/user.ejs index e66e19f..0e1124e 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -37,7 +37,7 @@