LeagueStats/client/src/views/SummonerChampions.vue

102 lines
2.5 KiB
Vue
Raw Normal View History

<template>
<div key="champions" class="mt-3">
<div class="flex items-center space-x-4">
2019-12-27 21:09:24 +00:00
<ChampionsSearch @search-champions="updateSearch" />
<FilterQueue @filter-queue="filterByQueue" :choices="queues" />
<OnlyMostPlayed v-model="onlyMostPlayed" />
</div>
<ChampionsTable
:champions="champions"
:search="searchChampions"
:only-most-played="onlyMostPlayed"
class="mt-6"
/>
</div>
</template>
2019-12-21 16:56:31 +00:00
<script>
2019-12-27 21:09:24 +00:00
import { mapActions, mapGetters, mapState } from 'vuex'
import { gameModes } from '@/data/data.js'
import ChampionsSearch from '@/components/Summoner/Champions/ChampionsSearch.vue'
2019-12-21 16:56:31 +00:00
import ChampionsTable from '@/components/Summoner/Champions/ChampionsTable.vue'
import FilterQueue from '@/components/Summoner/Champions/FilterQueue.vue'
import OnlyMostPlayed from '@/components/Summoner/Champions/OnlyMostPlayed.vue'
2019-12-21 16:56:31 +00:00
export default {
components: {
ChampionsSearch,
2019-12-21 16:56:31 +00:00
ChampionsTable,
FilterQueue,
OnlyMostPlayed,
2019-12-21 16:56:31 +00:00
},
data() {
return {
onlyMostPlayed: false,
2020-02-01 19:17:14 +00:00
queue: null,
2023-09-20 20:01:43 +00:00
searchChampions: '',
}
},
2019-12-21 16:56:31 +00:00
computed: {
queues() {
// Only keep the gameModes the summoner has played
const queues = Object.keys(gameModes)
2023-09-20 20:01:43 +00:00
.filter(
(gameMode) =>
gameModes[gameMode].type !== 'Bot' && this.gamemodes.includes(Number(gameMode))
)
.reduce((obj, key) => {
return {
...obj,
2023-09-20 20:01:43 +00:00
[key]: gameModes[key],
}
}, {})
2023-09-20 20:01:43 +00:00
return { 0: { type: 'Normal', name: 'All queues' }, ...queues }
},
2019-12-27 21:09:24 +00:00
...mapGetters('summoner', ['summonerFound']),
2019-12-21 16:56:31 +00:00
...mapState({
2023-09-20 20:01:43 +00:00
champions: (state) => state.summoner.champions.list,
championsLoaded: (state) => state.summoner.champions.championsLoaded,
gamemodes: (state) => state.summoner.basic.gamemodes,
}),
2019-12-21 16:56:31 +00:00
},
watch: {
2020-02-01 19:17:14 +00:00
championsLoaded() {
this.fetchData()
},
summonerFound() {
this.fetchData()
2023-09-20 20:01:43 +00:00
},
2019-12-21 16:56:31 +00:00
},
created() {
this.fetchData()
},
2019-12-21 16:56:31 +00:00
methods: {
fetchData() {
if (!this.championsLoaded && this.summonerFound) {
2020-02-01 19:17:14 +00:00
this.championsRequest(this.queue)
}
},
filterByQueue(queue) {
queue = Number(queue)
this.queue = queue === 0 ? null : queue
2020-02-01 19:17:14 +00:00
this.championsRequest(this.queue)
},
updateSearch(search) {
this.searchChampions = search
},
...mapActions('summoner', ['championsRequest']),
},
metaInfo() {
return {
title: 'Summoner Champions',
}
2023-09-20 20:01:43 +00:00
},
2019-12-21 16:56:31 +00:00
}
</script>