From 3212bff64c99b490fe3394c5aa898e9bcf24bfa6 Mon Sep 17 00:00:00 2001 From: NEWJIN Date: Thu, 30 Nov 2023 00:29:14 +0900 Subject: [PATCH] Update challenge_result.js ... --- challenge_result.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/challenge_result.js b/challenge_result.js index 4769072..0d67133 100644 --- a/challenge_result.js +++ b/challenge_result.js @@ -16,7 +16,6 @@ const itemsPerPage = 5; // 대결 전적 정보 연결 document.addEventListener("DOMContentLoaded", loadName); -document.addEventListener("DOMContentLoaded", loadChallengeInfo); function loadName() { const userId = localStorage.getItem("userId"); @@ -45,7 +44,9 @@ function loadName() { if (objects["status"] == "ok") { userName = objects["name"]; - console.log(userName); + console.log("계정주 이름:" + userName); + loadChallengeInfo(); + updateList(1); } } catch (e) { console.error("Error parsing response:", e); @@ -57,6 +58,7 @@ function loadName() { }; } + function loadChallengeInfo() { const userId = localStorage.getItem("userId"); jwt = localStorage.getItem("jwt"); @@ -97,6 +99,12 @@ function loadChallengeInfo() { } function updateList(pageNumber) { + if (!userName) { + console.error("userName is not loaded yet"); + return; + } + console.log("UserName in another function:", userName); + const startIndex = (pageNumber - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; const paginatedItems = challengess.slice(startIndex, endIndex); @@ -105,7 +113,11 @@ function updateList(pageNumber) { listElement.innerHTML = ""; paginatedItems.forEach((challenge, index) => { - const nameToShow = (userName === challenge.challenger) ? challenge.challenger : challenge.contender; + let nameToShow; + if (userName === challenge.challenger) + nameToShow = challenge.contender; + if (userName === challenge.contender) + nameToShow = challenge.challenger; console.log(nameToShow); const challengeRow = document.createElement("div"); challengeRow.innerHTML = `