feat: add SoloQ winrate

This commit is contained in:
Valentin Kaelin 2019-09-14 16:10:49 +02:00
parent db939459a0
commit f48bfc92ec
2 changed files with 27 additions and 19 deletions

View file

@ -15,6 +15,15 @@ export function createSummonerData(RiotData, championsInfos) {
const soloQStats = RiotData.soloQ const soloQStats = RiotData.soloQ
const matches = RiotData.matchesDetails const matches = RiotData.matchesDetails
const soloQ = soloQStats ? {} : null
if (soloQ) {
soloQ.rank = soloQStats.rank
soloQ.rankImgLink = getRankImg(soloQStats)
soloQ.wins = soloQStats.wins
soloQ.losses = soloQStats.losses
soloQ.winrate = (soloQ.wins * 100 / (soloQ.wins + soloQ.losses)).toFixed(1) + '%'
}
const matchesInfos = [] const matchesInfos = []
// Loop on all matches // Loop on all matches
for (let i = 0; i < matches.length; i++) { for (let i = 0; i < matches.length; i++) {
@ -78,10 +87,7 @@ export function createSummonerData(RiotData, championsInfos) {
profileIconId: userStats.profileIconId, profileIconId: userStats.profileIconId,
name: userStats.name, name: userStats.name,
level: userStats.summonerLevel, level: userStats.summonerLevel,
rank: soloQStats ? soloQStats.tier + ' ' + soloQStats.rank : 'Player is unranked', soloQ,
rankImgLink: getRankImg(soloQStats),
rankedWins: soloQStats ? soloQStats.wins : undefined,
rankedLosses: soloQStats ? soloQStats.losses : undefined
} }
} }

View file

@ -16,26 +16,28 @@
<div class="mt-4 mx-auto p-4 text-center bg-blue-100 border border-gray-300 rounded-lg"> <div class="mt-4 mx-auto p-4 text-center bg-blue-100 border border-gray-300 rounded-lg">
<div <div
class="mx-auto w-16 h-16 bg-gray-300" class="mx-auto w-16 h-16 bg-gray-300"
:style="{background: `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${localInfos.profileIconId}.png) center/cover`}" :style="{background: `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${summonerInfos.profileIconId}.png) center/cover`}"
></div> ></div>
<h1 class="player__name">{{ localInfos.name }}</h1> <h1>{{ summonerInfos.name }}</h1>
<h3 class="player__level">{{ localInfos.level }}</h3> <h3>{{ summonerInfos.level }}</h3>
<h3 class="player__rank">{{ localInfos.rank }}</h3>
<div v-if="summonerInfos.soloQ">
<h3>{{ summonerInfos.rank }}</h3>
<div <div
class="mx-auto w-16 h-16 bg-gray-300" class="mx-auto w-16 h-16 bg-gray-300"
:style="{background: `url(${localInfos.rankImgLink}) center/cover`}" :style="{background: `url(${summonerInfos.soloQ.rankImgLink}) center/cover`}"
></div> ></div>
<h3 <h3>{{ `${summonerInfos.soloQ.wins} wins / ${summonerInfos.soloQ.losses} losses` }}</h3>
class="player__ratio" <span>Winrate: {{ summonerInfos.soloQ.winrate }}</span>
>{{ localInfos.rankedWins ? localInfos.rankedWins + ' wins / ' + localInfos.rankedLosses + ' losses' : localInfos.rank }}</h3> </div>
<RecentActivity :matches="localInfos.allMatches" /> <RecentActivity :matches="summonerInfos.allMatches" />
<ul> <ul>
<Match <Match
v-for="(match, index) in localInfos.matches" v-for="(match, index) in summonerInfos.matches"
:key="index" :key="index"
:data="localInfos.matches[index]" :data="summonerInfos.matches[index]"
/> />
</ul> </ul>
</div> </div>
@ -75,7 +77,7 @@ export default {
return this.$route.params.region return this.$route.params.region
}, },
...mapState({ ...mapState({
localInfos: state => state.summoner.infos summonerInfos: state => state.summoner.infos
}), }),
...mapGetters('ddragon', ['areChampionsLoaded']), ...mapGetters('ddragon', ['areChampionsLoaded']),
...mapGetters('summoner', ['summonerFound', 'summonerNotFound', 'summonerLoading']) ...mapGetters('summoner', ['summonerFound', 'summonerNotFound', 'summonerLoading'])