diff --git a/public/summoner.js b/public/summoner.js index 445da20..d50552e 100644 --- a/public/summoner.js +++ b/public/summoner.js @@ -1,8 +1,7 @@ var req = new XMLHttpRequest(); var url = '/api'; -var params = 'playerName=Kalane'; var nameChosen = ''; -var infos = {}; +var localInfos = {}; var itemsJSON; // Get username from param @@ -37,38 +36,15 @@ async function main() { req.open('POST', url, true); document.querySelector('.loader--overlay').style.display = 'block'; req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - // req.send(params); req.send('playerName=' + nameChosen); } - /* Debug button to reset localstorage */ document.querySelector('.debug').addEventListener('click', () => { console.log('CLEAR LOCALSTORAGE'); localStorage.clear(); }); - /* Form to change username */ - var changeName = document.querySelector('#changeName'); - var nameToPick = document.querySelector('#name') - changeName.addEventListener('submit', function (e) { - e.preventDefault(); - - console.log('here') - - nameChosen = nameToPick.value; - if (localStorage[nameChosen]) { - console.log('cached on search'); - document.querySelector('#refresh').style.display = 'block'; - displayContent(localStorage[nameChosen]); - } else { - document.querySelector('.loader--overlay').style.display = 'block'; - req.open('POST', url, true); - req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - req.send('playerName=' + nameToPick.value); - } - }); - /* Refresh button */ var refreshBtn = document.querySelector('#refresh'); refreshBtn.addEventListener('click', (e) => { @@ -177,22 +153,22 @@ function createObject(JSONData) { } console.log(matchesInfos); - infos.accountId = userStats.accountId; - infos.matches = matchesInfos; - infos.profileIconId = userStats.profileIconId; - infos.name = userStats.name; - infos.level = userStats.summonerLevel; - infos.rank = soloQStats ? soloQStats.tier + ' ' + soloQStats.rank : 'Joueur non classé'; - infos.rankImgLink = getRankImg(soloQStats); - infos.rankedWins = soloQStats.wins; - infos.rankedLosses = soloQStats.losses; + localInfos.accountId = userStats.accountId; + localInfos.matches = matchesInfos; + localInfos.profileIconId = userStats.profileIconId; + localInfos.name = userStats.name; + localInfos.level = userStats.summonerLevel; + localInfos.rank = soloQStats ? soloQStats.tier + ' ' + soloQStats.rank : 'Joueur non classé'; + localInfos.rankImgLink = getRankImg(soloQStats); + localInfos.rankedWins = soloQStats.wins; + localInfos.rankedLosses = soloQStats.losses; nameChosen = userStats.name; console.log('====== Saved infos ======'); - console.log(infos); + console.log(localInfos); - localStorage[nameChosen] = JSON.stringify(infos); + localStorage[nameChosen] = JSON.stringify(localInfos); displayContent(localStorage[nameChosen]); } diff --git a/server.js b/server.js index fd79597..486af32 100644 --- a/server.js +++ b/server.js @@ -38,6 +38,7 @@ app.listen(app.get('port'), () => console.log(`RiotAPI test app listening on por + async function apicall(urlApi) { //console.log(urlApi); return rp({ url: 'https://euw1.api.riotgames.com/lol/match/v4/matches/' + urlApi + '?api_key=' + key, json: true }).then(function (obj) { @@ -59,6 +60,7 @@ function getRanked(callback) { // send data of rankeds and of username app.post('/api', function (req, res) { //console.log(req.body.playerName); + console.time('all') pseudo = req.body.playerName; getAccountInfos(function (account) { @@ -72,6 +74,7 @@ app.post('/api', function (req, res) { finalJSON.push(matches); console.log('Data sent to front'); res.send(finalJSON); + console.timeEnd('all') }); }); }); @@ -90,6 +93,7 @@ function getAccountInfos(callback) { callback(JSONBody); } else { + console.log(response.statusCode); console.log('username not found'); callback(null); } @@ -109,7 +113,7 @@ function getMatches(callback) { matchsId[i] = JSONMatches.matches[i].gameId; } - Promise.mapSeries(matchsId, function (item) { + Promise.map(matchsId, function (item) { // old: .mapSeries return apicall(item); }).then(() => { console.timeEnd('getMatches'); @@ -117,6 +121,7 @@ function getMatches(callback) { callback(JSONMatches); }).catch(err => { console.log('Error'); + console.log(err.statusCode); }); } @@ -126,7 +131,6 @@ function getMatches(callback) { function addMatchToJSON(obj) { //console.log(obj.gameId); - for (var i = 0; i < JSONMatches.matches.length; i++) { if (JSONMatches.matches[i].gameId == obj.gameId) { //console.log('yes'); diff --git a/summoner.html b/summoner.html index 76f2636..0bd3618 100644 --- a/summoner.html +++ b/summoner.html @@ -28,8 +28,8 @@