From 0ad9788941c3b4baa654603055d27f492c5e23c7 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Fri, 5 Apr 2019 22:41:32 +0200 Subject: [PATCH] Replace some old syntax --- client/src/helpers/functions.js | 22 +++++++++++----------- client/src/views/Summoner.vue | 27 +++++++-------------------- server/server.js | 24 ++++++++++++------------ 3 files changed, 30 insertions(+), 43 deletions(-) diff --git a/client/src/helpers/functions.js b/client/src/helpers/functions.js index f594493..aa5409e 100644 --- a/client/src/helpers/functions.js +++ b/client/src/helpers/functions.js @@ -3,12 +3,12 @@ * @param previous : time we want to get difference */ export function timeDifference(previous) { - var current = new Date(); - var msPerMinute = 60 * 1000; - var msPerHour = msPerMinute * 60; - var msPerDay = msPerHour * 24; - var msPerWeek = msPerDay * 7; - var elapsed = current - previous; + const current = new Date(); + const msPerMinute = 60 * 1000; + const msPerHour = msPerMinute * 60; + const msPerDay = msPerHour * 24; + const msPerWeek = msPerDay * 7; + const elapsed = current - previous; if (elapsed < msPerMinute) { return Math.round(elapsed / 1000) + 's'; @@ -19,9 +19,9 @@ export function timeDifference(previous) { } else if (elapsed < msPerWeek) { return Math.round(elapsed / msPerDay) + 'j'; } else { - var oldDate = new Date(previous); - var day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate(); - var month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1); + const oldDate = new Date(previous); + const day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate(); + const month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1); return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2); } } @@ -32,8 +32,8 @@ export function timeDifference(previous) { * @param sec : time in seconds to convert */ export function secToTime(sec) { - var min = Math.floor(sec / 60); - var newSec = sec - min * 60; + const min = Math.floor(sec / 60); + const newSec = sec - min * 60; return min + ':' + (newSec < 10 ? '0' + newSec : newSec); // } diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index a90890e..35aeb25 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -82,8 +82,8 @@ export default { this.loading = true; this.axios({ method: "POST", - url: "https://vue.valentinkaelin.ch/api", - //url: "http://localhost:5000/api", + // url: "https://vue.valentinkaelin.ch/api", + url: "http://localhost:5000/api", headers: { "Content-Type": "application/json" }, @@ -131,20 +131,10 @@ export default { // Loop on all matches for (let i = 0; i < matches.length; i++) { const currentMatch = matches[i]; - let participantId; - for (let i = 0; i < currentMatch.participantIdentities.length; i++) { - if (currentMatch.participantIdentities[i].player.accountId === userStats.accountId) - participantId = currentMatch.participantIdentities[i].participantId; - } + const participantId = currentMatch.participantIdentities.find((p) => p.player.accountId === userStats.accountId).participantId const teamId = currentMatch.participants[participantId - 1].teamId; - let win = false; - for (let i = 0; i < currentMatch.teams.length; i++) { - if (currentMatch.teams[i].teamId === teamId) { - if (currentMatch.teams[i].win === 'Win') - win = true; - } - } + const win = currentMatch.teams.find((t) => t.teamId === teamId).win === 'Win' const map = maps[currentMatch.mapId]; let mode = gameModes[currentMatch.queueId]; @@ -189,7 +179,7 @@ export default { firstSum: this.getSummonerLink(firstSum), secondSum: this.getSummonerLink(secondSum) }); - } + } // end loop matches console.log(matchesInfos); this.localInfos = { @@ -219,11 +209,8 @@ export default { return `url('https://cdn.valentinkaelin.ch/riot/${itemImage.sprite}') -${itemImage.x}px -${itemImage.y}px`; }, getSummonerLink(id) { - for(var prop in summonersJSON.data) { - if(summonersJSON.data[prop].key == id) { - return `https://cdn.valentinkaelin.ch/riot/spells/${summonersJSON.data[prop].id}.png`; - } - } + const spellName = Object.entries(summonersJSON.data).find(([, spell]) => Number(spell.key) === id)[0] + return `https://cdn.valentinkaelin.ch/riot/spells/${spellName}.png`; }, redirect() { this.$router.push("/summoner/" + this.search) diff --git a/server/server.js b/server/server.js index a23fa91..b0a9f0f 100644 --- a/server/server.js +++ b/server/server.js @@ -20,21 +20,21 @@ let finalJSON = []; app.set('port', (process.env.PORT || 5000)) /* DEV */ -//var cors = require('cors'); -//app.use(cors({origin: '*'})); +var cors = require('cors'); +app.use(cors({origin: '*'})); /* PRODUCTION */ -const staticFileMiddleware = express.static(path.join(__dirname + '/dist')); -app.use(staticFileMiddleware); -app.use(history({ - disableDotRule: true, - verbose: true -})); -app.use(staticFileMiddleware); +// const staticFileMiddleware = express.static(path.join(__dirname + '/dist')); +// app.use(staticFileMiddleware); +// app.use(history({ +// disableDotRule: true, +// verbose: true +// })); +// app.use(staticFileMiddleware); -app.get('/', function (req, res) { - res.render(path.join(__dirname + '/dist/index.html')); -}); +// app.get('/', function (req, res) { +// res.render(path.join(__dirname + '/dist/index.html')); +// }); /* To retrieve data of post request */ app.use(bodyParser.json()); // to support JSON-encoded bodies