LeagueStats/client/src/views/Summoner.vue

108 lines
3 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"
>Accueil</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
<template v-if="summonerFound && !loading">
<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-08-19 22:08:13 +00:00
:style="{background: `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${localInfos.profileIconId}.png) center/cover`}"
></div>
<h1 class="player__name">{{ localInfos.name }}</h1>
<h3 class="player__level">{{ localInfos.level }}</h3>
<h3 class="player__rank">{{ localInfos.rank }}</h3>
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-08-19 22:08:13 +00:00
:style="{background: `url(${localInfos.rankImgLink}) center/cover`}"
></div>
<h3
class="player__ratio"
2019-09-09 18:42:10 +00:00
>{{ localInfos.rankedWins ? localInfos.rankedWins + ' wins / ' + localInfos.rankedLosses + ' losses' : localInfos.rank }}</h3>
2019-08-19 22:08:13 +00:00
2019-09-08 20:08:49 +00:00
<RecentActivity :matches="localInfos.allMatches" />
2019-03-30 22:55:48 +00:00
2019-09-09 18:42:10 +00:00
<ul>
<Match
2019-08-19 22:08:13 +00:00
v-for="(match, index) in localInfos.matches"
:key="index"
:data="localInfos.matches[index]"
/>
</ul>
</div>
2019-03-30 22:55:48 +00:00
</div>
</template>
<template v-else-if="loading">
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-08-23 14:48:16 +00:00
<dot-loader :loading="loading" />
</div>
</template>
<template v-else>
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-08 20:08:49 +00:00
import { mapState, mapActions } 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({
localInfos: state => state.summoner.infos,
summonerFound: state => state.summoner.summonerFound,
loading: state => state.summoner.loading
})
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-09 18:42:10 +00:00
await this.getChampions()
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-09 18:42:10 +00:00
...mapActions('summoner', ['summonerRequest']),
...mapActions('ddragon', ['getChampions'])
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>