LeagueStats/client/src/views/Summoner.vue

112 lines
3.1 KiB
Vue
Raw Normal View History

2019-03-30 22:55:48 +00:00
<template>
<div>
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">
2019-08-19 22:08:13 +00:00
<router-link
to="/"
class="flex items-center text-lg text-teal-100 mr-8 hover:text-teal-200"
2019-09-11 20:02:05 +00:00
>Home</router-link>
2019-04-10 20:05:52 +00:00
2019-08-19 22:08:13 +00:00
<SearchForm @formSubmit="redirect" />
2019-03-30 22:55:48 +00:00
</div>
2019-04-10 20:05:52 +00:00
</header>
2019-08-19 22:08:13 +00:00
2019-09-11 20:02:05 +00:00
<template v-if="summonerFound">
<div class="container mx-auto pb-16">
2019-09-09 18:42:10 +00:00
<div class="mt-4 mx-auto p-4 text-center bg-blue-100 border border-gray-300 rounded-lg">
2019-08-19 22:08:13 +00:00
<div
2019-09-09 18:42:10 +00:00
class="mx-auto w-16 h-16 bg-gray-300"
2019-09-14 14:10:49 +00:00
:style="{background: `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${summonerInfos.profileIconId}.png) center/cover`}"
2019-08-19 22:08:13 +00:00
></div>
2019-09-14 14:10:49 +00:00
<h1>{{ summonerInfos.name }}</h1>
<h3>{{ summonerInfos.level }}</h3>
<div v-if="summonerInfos.soloQ">
<h3>{{ summonerInfos.rank }}</h3>
<div
class="mx-auto w-16 h-16 bg-gray-300"
:style="{background: `url(${summonerInfos.soloQ.rankImgLink}) center/cover`}"
></div>
<h3>{{ `${summonerInfos.soloQ.wins} wins / ${summonerInfos.soloQ.losses} losses` }}</h3>
<span>Winrate: {{ summonerInfos.soloQ.winrate }}</span>
</div>
2019-08-19 22:08:13 +00:00
2019-09-14 14:10:49 +00:00
<RecentActivity :matches="summonerInfos.allMatches" />
2019-03-30 22:55:48 +00:00
2019-09-09 18:42:10 +00:00
<ul>
<Match
2019-09-14 14:10:49 +00:00
v-for="(match, index) in summonerInfos.matches"
2019-08-19 22:08:13 +00:00
:key="index"
2019-09-14 14:10:49 +00:00
:data="summonerInfos.matches[index]"
/>
</ul>
</div>
2019-03-30 22:55:48 +00:00
</div>
</template>
2019-09-11 20:02:05 +00:00
<template v-else-if="summonerLoading">
2019-08-19 22:08:13 +00:00
<div
class="flex items-center justify-center bg-white max-w-xs mx-auto p-5 rounded-lg shadow-xl"
>
2019-09-11 20:02:05 +00:00
<dot-loader :loading="summonerLoading" />
</div>
</template>
2019-09-11 20:02:05 +00:00
<template v-else-if="summonerNotFound">
2019-09-09 18:42:10 +00:00
<p>Player can't be found.</p>
</template>
2019-03-30 22:55:48 +00:00
</div>
</template>
<script>
2019-09-11 20:02:05 +00:00
import { mapState, mapActions, mapGetters } from 'vuex'
2019-08-23 14:48:16 +00:00
import RecentActivity from '@/components/RecentActivity.vue'
import Match from '@/components/Match.vue'
import SearchForm from '@/components/SearchForm.vue'
2019-03-30 22:55:48 +00:00
export default {
components: {
2019-04-08 20:06:22 +00:00
Match,
2019-08-19 22:08:13 +00:00
RecentActivity,
2019-04-08 20:06:22 +00:00
SearchForm
2019-03-30 22:55:48 +00:00
},
2019-08-23 14:48:16 +00:00
2019-04-07 17:44:01 +00:00
computed: {
2019-08-23 14:48:16 +00:00
summoner() {
2019-04-07 17:44:01 +00:00
return this.$route.params.name
2019-04-08 20:06:22 +00:00
},
2019-08-23 14:48:16 +00:00
region() {
2019-04-08 20:06:22 +00:00
return this.$route.params.region
2019-09-08 20:08:49 +00:00
},
...mapState({
2019-09-14 14:10:49 +00:00
summonerInfos: state => state.summoner.infos
2019-09-11 20:02:05 +00:00
}),
...mapGetters('ddragon', ['areChampionsLoaded']),
...mapGetters('summoner', ['summonerFound', 'summonerNotFound', 'summonerLoading'])
2019-04-07 17:44:01 +00:00
},
2019-08-23 14:48:16 +00:00
watch: {
$route() {
console.log('route changed')
2019-09-08 20:08:49 +00:00
this.apiCall()
2019-08-23 14:48:16 +00:00
}
},
2019-09-08 20:08:49 +00:00
mounted() {
this.apiCall()
2019-08-23 14:48:16 +00:00
},
2019-03-30 22:55:48 +00:00
methods: {
2019-08-31 17:19:48 +00:00
async apiCall() {
2019-09-11 20:02:05 +00:00
if (!this.areChampionsLoaded)
await this.getChampions()
2019-09-09 18:42:10 +00:00
this.summonerRequest({ summoner: this.summoner, region: this.region })
},
2019-08-23 14:48:16 +00:00
redirect(summoner, region) {
2019-04-08 20:06:22 +00:00
this.$router.push(`/summoner/${region}/${summoner}`)
2019-03-30 22:55:48 +00:00
},
2019-09-11 20:02:05 +00:00
...mapActions('ddragon', ['getChampions']),
...mapActions('summoner', ['summonerRequest'])
2019-03-30 22:55:48 +00:00
}
2019-08-23 14:48:16 +00:00
}
2019-03-30 22:55:48 +00:00
</script>