2019-03-30 22:55:48 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2019-04-07 17:44:01 +00:00
|
|
|
<button class="debug" @click="resetLocalStorage"></button>
|
2019-03-30 22:55:48 +00:00
|
|
|
|
2019-04-10 20:05:52 +00:00
|
|
|
<header class="search mb-4 bg-teal-900 text-teal-100">
|
|
|
|
|
<div class="container mx-auto flex justify-between py-8">
|
|
|
|
|
|
|
|
|
|
<router-link to="/" class="flex items-center text-lg text-teal-100 mr-8 hover:text-teal-200">Accueil</router-link>
|
2019-04-08 20:06:22 +00:00
|
|
|
|
|
|
|
|
<SearchForm @formSubmit="redirect"/>
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
|
v-if="summonerFound"
|
|
|
|
|
id="refresh"
|
2019-04-10 20:05:52 +00:00
|
|
|
class="input btn w-20 rounded-lg ml-2 relative"
|
2019-04-08 20:06:22 +00:00
|
|
|
:disabled="loading"
|
|
|
|
|
@click="apiCall"
|
|
|
|
|
>
|
2019-04-10 20:05:52 +00:00
|
|
|
<v-icon name="sync" class="absolute vertical-center horizontal-center"/>
|
2019-04-08 20:06:22 +00:00
|
|
|
</button>
|
|
|
|
|
|
2019-04-10 20:05:52 +00:00
|
|
|
|
|
|
|
|
|
2019-03-30 22:55:48 +00:00
|
|
|
</div>
|
2019-04-10 20:05:52 +00:00
|
|
|
</header>
|
2019-04-04 20:29:37 +00:00
|
|
|
|
|
|
|
|
<template v-if="summonerFound && !loading">
|
2019-03-31 18:56:48 +00:00
|
|
|
<div class="container mx-auto pb-16">
|
2019-04-07 17:44:01 +00:00
|
|
|
<div class="player bg-blue-100">
|
2019-05-17 20:58:36 +00:00
|
|
|
<div class="player__pp" :style="{background: `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${localInfos.profileIconId}.png) center/cover`}"></div>
|
2019-03-31 18:56:48 +00:00
|
|
|
<h1 class="player__name">{{ localInfos.name }}</h1>
|
|
|
|
|
<h3 class="player__level">{{ localInfos.level }}</h3>
|
|
|
|
|
<h3 class="player__rank">{{ localInfos.rank }}</h3>
|
|
|
|
|
<div class="player__rank-img" :style="{background: `url(${localInfos.rankImgLink}) center/cover`}"></div>
|
|
|
|
|
<h3 class="player__ratio">{{ localInfos.rankedWins ? localInfos.rankedWins + ' wins / ' + localInfos.rankedLosses + ' losses' : "Joueur non classé" }}</h3>
|
2019-03-30 22:55:48 +00:00
|
|
|
|
2019-03-31 18:56:48 +00:00
|
|
|
<ul class="list-matches--debug">
|
|
|
|
|
<Match
|
|
|
|
|
v-for="(match, index) in localInfos.matches" :key="index"
|
|
|
|
|
:data="localInfos.matches[index]"
|
|
|
|
|
/>
|
|
|
|
|
</ul>
|
2019-03-30 22:55:48 +00:00
|
|
|
|
2019-03-31 18:56:48 +00:00
|
|
|
</div>
|
2019-03-30 22:55:48 +00:00
|
|
|
</div>
|
2019-03-31 18:56:48 +00:00
|
|
|
</template>
|
2019-04-04 20:29:37 +00:00
|
|
|
<template v-else-if="loading">
|
|
|
|
|
<div class="flex items-center justify-center bg-white max-w-xs mx-auto p-5 rounded-lg shadow-xl">
|
|
|
|
|
<dot-loader :loading="loading"></dot-loader>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2019-03-31 18:56:48 +00:00
|
|
|
<template v-else>
|
|
|
|
|
<p>Le joueur est introuvable.</p>
|
|
|
|
|
</template>
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2019-05-17 20:58:36 +00:00
|
|
|
// import itemsJSON from '@/data/item.json'
|
2019-04-04 20:29:37 +00:00
|
|
|
import summonersJSON from '@/data/summoner.json'
|
2019-03-30 22:55:48 +00:00
|
|
|
import Match from '@/components/Match.vue';
|
2019-04-08 20:06:22 +00:00
|
|
|
import SearchForm from '@/components/SearchForm.vue';
|
2019-03-30 22:55:48 +00:00
|
|
|
import { championsId, maps, gameModes } from "@/data/data.js";
|
2019-03-31 18:56:48 +00:00
|
|
|
import { timeDifference, secToTime, getRankImg } from "@/helpers/functions.js";
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
2019-04-08 20:06:22 +00:00
|
|
|
Match,
|
|
|
|
|
SearchForm
|
2019-03-30 22:55:48 +00:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-05-17 20:58:36 +00:00
|
|
|
championsInfos: [],
|
2019-03-30 22:55:48 +00:00
|
|
|
localInfos: {},
|
2019-04-04 20:29:37 +00:00
|
|
|
summonerFound: true,
|
2019-04-08 20:06:22 +00:00
|
|
|
loading: false,
|
|
|
|
|
regionsList: {
|
|
|
|
|
'br': 'br1',
|
|
|
|
|
'eune': 'eun1',
|
|
|
|
|
'euw': 'euw1',
|
|
|
|
|
'jp': 'jp1',
|
|
|
|
|
'kr': 'kr',
|
|
|
|
|
'lan': 'la1',
|
|
|
|
|
'las': 'la2',
|
|
|
|
|
'na': 'na1',
|
|
|
|
|
'oce': 'oc1',
|
|
|
|
|
'tr': 'tr1',
|
|
|
|
|
'ru': 'ru'
|
|
|
|
|
}
|
2019-03-30 22:55:48 +00:00
|
|
|
};
|
|
|
|
|
},
|
2019-04-07 17:44:01 +00:00
|
|
|
computed: {
|
|
|
|
|
summoner() {
|
|
|
|
|
return this.$route.params.name
|
2019-04-08 20:06:22 +00:00
|
|
|
},
|
|
|
|
|
region() {
|
|
|
|
|
return this.$route.params.region
|
2019-04-07 17:44:01 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-03-30 22:55:48 +00:00
|
|
|
methods: {
|
2019-03-31 18:56:48 +00:00
|
|
|
apiCall() {
|
2019-05-17 20:58:36 +00:00
|
|
|
console.log(this.$patch)
|
2019-04-07 17:44:01 +00:00
|
|
|
const summoner = this.summoner;
|
2019-04-08 20:06:22 +00:00
|
|
|
const region = this.regionsList[this.region];
|
2019-04-04 20:29:37 +00:00
|
|
|
this.loading = true;
|
2019-03-31 18:56:48 +00:00
|
|
|
this.axios({
|
2019-05-17 20:58:36 +00:00
|
|
|
method: 'POST',
|
2019-04-07 17:44:01 +00:00
|
|
|
url: process.env.NODE_ENV === 'development' ? 'http://localhost:5000/api' : 'https://leaguestats.valentinkaelin.ch/api',
|
2019-03-31 18:56:48 +00:00
|
|
|
headers: {
|
2019-05-17 20:58:36 +00:00
|
|
|
'Content-Type': 'application/json'
|
2019-03-31 18:56:48 +00:00
|
|
|
},
|
|
|
|
|
data: {
|
2019-04-08 20:06:22 +00:00
|
|
|
summoner,
|
|
|
|
|
region
|
2019-03-31 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
2019-04-04 20:29:37 +00:00
|
|
|
this.loading = false;
|
2019-03-31 18:56:48 +00:00
|
|
|
return response.data;
|
|
|
|
|
})
|
|
|
|
|
.then(jsonData => {
|
|
|
|
|
if(jsonData) {
|
|
|
|
|
this.summonerFound = true
|
|
|
|
|
this.createObject(jsonData)
|
|
|
|
|
} else {
|
|
|
|
|
this.summonerFound = false
|
|
|
|
|
console.log('Summoner not found')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
2019-04-04 20:29:37 +00:00
|
|
|
this.loading = false;
|
2019-03-31 18:56:48 +00:00
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
checkLocalStorage() {
|
2019-04-08 20:06:22 +00:00
|
|
|
if (localStorage[`${this.summoner}:${this.region}`]) {
|
2019-03-31 18:56:48 +00:00
|
|
|
console.log('cached')
|
|
|
|
|
this.summonerFound = true
|
2019-04-08 20:06:22 +00:00
|
|
|
this.localInfos = JSON.parse(localStorage[`${this.summoner}:${this.region}`])
|
2019-03-31 18:56:48 +00:00
|
|
|
} else {
|
|
|
|
|
this.apiCall()
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-03-30 22:55:48 +00:00
|
|
|
createObject(JSONData) {
|
2019-05-17 20:58:36 +00:00
|
|
|
console.time('frontend')
|
2019-04-04 20:29:37 +00:00
|
|
|
console.log('--- ALL INFOS ---')
|
|
|
|
|
console.log(JSONData);
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
const userStats = JSONData[0];
|
|
|
|
|
const rankedStats = JSONData[1];
|
|
|
|
|
const soloQStats = rankedStats !== null ? (rankedStats.queueType == 'RANKED_SOLO_5x5' ? rankedStats : JSONData[2]) : false;
|
|
|
|
|
const matches = JSONData[3].matches;
|
|
|
|
|
|
|
|
|
|
const matchesInfos = [];
|
|
|
|
|
// Loop on all matches
|
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
|
const currentMatch = matches[i];
|
2019-04-05 20:41:32 +00:00
|
|
|
const participantId = currentMatch.participantIdentities.find((p) => p.player.accountId === userStats.accountId).participantId
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
const teamId = currentMatch.participants[participantId - 1].teamId;
|
2019-04-05 20:41:32 +00:00
|
|
|
const win = currentMatch.teams.find((t) => t.teamId === teamId).win === 'Win'
|
2019-03-30 22:55:48 +00:00
|
|
|
|
|
|
|
|
const map = maps[currentMatch.mapId];
|
|
|
|
|
let mode = gameModes[currentMatch.queueId];
|
|
|
|
|
if (!mode)
|
|
|
|
|
mode = 'Undefined gamemode';
|
2019-05-17 20:58:36 +00:00
|
|
|
//console.log(Object.entries(this.championsInfos))
|
|
|
|
|
//console.log(this.championsInfos)
|
|
|
|
|
const champion = Object.entries(this.championsInfos).find(([, champion]) => Number(champion.key) === currentMatch.participants[participantId - 1].championId)[0]
|
|
|
|
|
//const champion = championsId[currentMatch.participants[participantId - 1].championId];
|
2019-03-30 22:55:48 +00:00
|
|
|
const role = currentMatch.participants[participantId - 1].timeline.lane;
|
2019-03-31 18:56:48 +00:00
|
|
|
const timeAgo = timeDifference(currentMatch.gameCreation);
|
|
|
|
|
const time = secToTime(currentMatch.gameDuration);
|
2019-03-30 22:55:48 +00:00
|
|
|
const kills = currentMatch.participants[participantId - 1].stats.kills;
|
|
|
|
|
const deaths = currentMatch.participants[participantId - 1].stats.deaths;
|
|
|
|
|
const assists = currentMatch.participants[participantId - 1].stats.assists;
|
|
|
|
|
const level = currentMatch.participants[participantId - 1].stats.champLevel;
|
|
|
|
|
|
|
|
|
|
const items = [];
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
const currentItem = 'item' + i;
|
2019-04-04 20:29:37 +00:00
|
|
|
items.push(this.getItemLink(currentMatch.participants[participantId - 1].stats[currentItem]));
|
2019-03-30 22:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gold = (currentMatch.participants[participantId - 1].stats.goldEarned / 1000).toFixed(1) + 'k';
|
|
|
|
|
const minions = currentMatch.participants[participantId - 1].stats.totalMinionsKilled + currentMatch.participants[participantId - 1].stats.neutralMinionsKilled;
|
|
|
|
|
|
2019-04-04 20:29:37 +00:00
|
|
|
const firstSum = currentMatch.participants[participantId - 1].spell1Id;
|
|
|
|
|
const secondSum = currentMatch.participants[participantId - 1].spell2Id;
|
|
|
|
|
|
2019-03-30 22:55:48 +00:00
|
|
|
matchesInfos.push({
|
|
|
|
|
result: win,
|
|
|
|
|
map: map,
|
|
|
|
|
gamemode: mode,
|
|
|
|
|
champ: champion,
|
|
|
|
|
role: role,
|
|
|
|
|
date: timeAgo,
|
|
|
|
|
time: time,
|
|
|
|
|
kills: kills,
|
|
|
|
|
deaths: deaths,
|
|
|
|
|
assists: assists,
|
|
|
|
|
level: level,
|
|
|
|
|
items: items,
|
|
|
|
|
gold: gold,
|
2019-04-04 20:29:37 +00:00
|
|
|
minions: minions,
|
|
|
|
|
firstSum: this.getSummonerLink(firstSum),
|
|
|
|
|
secondSum: this.getSummonerLink(secondSum)
|
2019-03-30 22:55:48 +00:00
|
|
|
});
|
2019-04-05 20:41:32 +00:00
|
|
|
} // end loop matches
|
2019-03-30 22:55:48 +00:00
|
|
|
console.log(matchesInfos);
|
|
|
|
|
|
|
|
|
|
this.localInfos = {
|
|
|
|
|
accountId: userStats.accountId,
|
|
|
|
|
matches: matchesInfos,
|
|
|
|
|
profileIconId: userStats.profileIconId,
|
|
|
|
|
name: userStats.name,
|
|
|
|
|
level: userStats.summonerLevel,
|
|
|
|
|
rank: soloQStats ? soloQStats.tier + ' ' + soloQStats.rank : 'Joueur non classé',
|
2019-03-31 18:56:48 +00:00
|
|
|
rankImgLink: getRankImg(soloQStats),
|
2019-03-30 22:55:48 +00:00
|
|
|
rankedWins: soloQStats ? soloQStats.wins : undefined,
|
|
|
|
|
rankedLosses: soloQStats ? soloQStats.losses : undefined
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('====== Saved infos ======');
|
|
|
|
|
console.log(this.localInfos);
|
|
|
|
|
|
2019-04-08 20:06:22 +00:00
|
|
|
localStorage[`${this.summoner}:${this.region}`] = JSON.stringify(this.localInfos);
|
2019-05-17 20:58:36 +00:00
|
|
|
console.timeEnd('frontend')
|
|
|
|
|
},
|
|
|
|
|
getData() {
|
|
|
|
|
console.log('API CALL FOR CHAMPIONS')
|
|
|
|
|
this.axios({
|
|
|
|
|
method: 'GET',
|
|
|
|
|
url: `http://ddragon.leagueoflegends.com/cdn/${this.$patch}/data/en_US/champion.json`
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
return response.data
|
|
|
|
|
})
|
|
|
|
|
.then(jsonData => {
|
|
|
|
|
console.log('here')
|
|
|
|
|
this.championsInfos = jsonData.data
|
|
|
|
|
})
|
2019-03-30 22:55:48 +00:00
|
|
|
},
|
2019-04-04 20:29:37 +00:00
|
|
|
getItemLink(id) {
|
2019-05-17 20:58:36 +00:00
|
|
|
return `url('https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/item/${id === 0 ? 3637 : id}.png') no-repeat center center / contain`;
|
2019-04-04 20:29:37 +00:00
|
|
|
},
|
|
|
|
|
getSummonerLink(id) {
|
2019-04-05 20:41:32 +00:00
|
|
|
const spellName = Object.entries(summonersJSON.data).find(([, spell]) => Number(spell.key) === id)[0]
|
2019-05-17 20:58:36 +00:00
|
|
|
return `https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/spell/${spellName}.png`;
|
2019-04-04 20:29:37 +00:00
|
|
|
},
|
2019-04-08 20:06:22 +00:00
|
|
|
redirect(summoner, region) {
|
|
|
|
|
// this.$router.push("/summoner/euw/" + this.search)
|
|
|
|
|
this.$router.push(`/summoner/${region}/${summoner}`)
|
2019-03-30 22:55:48 +00:00
|
|
|
},
|
2019-03-31 18:56:48 +00:00
|
|
|
resetLocalStorage() {
|
|
|
|
|
console.log('CLEAR LOCALSTORAGE')
|
|
|
|
|
localStorage.clear()
|
2019-03-30 22:55:48 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-05-17 20:58:36 +00:00
|
|
|
created: function() {
|
|
|
|
|
this.getData()
|
|
|
|
|
},
|
2019-03-30 22:55:48 +00:00
|
|
|
mounted: function () {
|
2019-03-31 18:56:48 +00:00
|
|
|
this.checkLocalStorage()
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
$route() {
|
|
|
|
|
console.log('route changed')
|
|
|
|
|
this.checkLocalStorage()
|
|
|
|
|
}
|
2019-03-30 22:55:48 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
.debug {
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
width: 40px;
|
|
|
|
|
height: 40px;
|
|
|
|
|
border: none;
|
|
|
|
|
z-index: 9999999999;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.debug:hover {
|
|
|
|
|
background: #ef5753;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.player {
|
|
|
|
|
text-align: center;
|
|
|
|
|
margin: 16px auto 0;
|
|
|
|
|
border: 1px solid #ebebeb;
|
|
|
|
|
padding: 16px;
|
2019-04-04 20:29:37 +00:00
|
|
|
/* background: #fff; */
|
2019-03-30 22:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.player__pp {
|
|
|
|
|
width: 75px;
|
|
|
|
|
height: 75px;
|
|
|
|
|
background: #ebebeb;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.player__rank-img {
|
|
|
|
|
width: 75px;
|
|
|
|
|
height: 75px;
|
|
|
|
|
background: #ebebeb;
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.list-matches {
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
</style>
|