From d839eed7ad42bb545d03baca4fa9755d58e3f191 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 1 Feb 2020 20:17:14 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20filter=20by=20season=20now=20works=20?= =?UTF-8?q?=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Summoner/FilterSeason.vue | 7 +- client/src/plugins/axios.js | 14 +- client/src/router.js | 15 +- client/src/store/modules/summoner.js | 15 +- client/src/views/Summoner.vue | 3 + client/src/views/SummonerChampions.vue | 10 +- client/src/views/SummonerRecords.vue | 285 +++++++++--------- .../Controllers/Http/SummonerController.js | 15 +- server/app/Repositories/MatchRepository.js | 20 +- server/app/Services/StatsService.js | 3 +- 10 files changed, 223 insertions(+), 164 deletions(-) diff --git a/client/src/components/Summoner/FilterSeason.vue b/client/src/components/Summoner/FilterSeason.vue index 108665d..0a2172e 100644 --- a/client/src/components/Summoner/FilterSeason.vue +++ b/client/src/components/Summoner/FilterSeason.vue @@ -6,6 +6,7 @@ dir="rtl" class="block appearance-none bg-transparent w-full px-4 pr-8 rounded-md cursor-pointer focus:outline-none group-hover:text-white" > +
diff --git a/client/src/plugins/axios.js b/client/src/plugins/axios.js index 1cae95a..193460c 100644 --- a/client/src/plugins/axios.js +++ b/client/src/plugins/axios.js @@ -1,4 +1,6 @@ import axiosHttp from 'axios' +import router from '../router' +import store from '../store' export const axios = axiosHttp @@ -11,8 +13,16 @@ const axiosSource = CancelToken.source() axios.defaults.axiosSource = axiosSource axios.defaults.cancelToken = axiosSource.token +// Add season number to data if the route need it +axios.interceptors.request.use(function (config) { + if (config.url !== 'summoner-basic' && router.currentRoute.meta.season) { + config.data.season = store.state.summoner.basic.currentSeason + } + return config +}) + export default { - install (Vue) { + install(Vue) { Vue.prototype.$axios = axiosHttp } -} \ No newline at end of file +} diff --git a/client/src/router.js b/client/src/router.js index 7b78ea4..9af6fda 100644 --- a/client/src/router.js +++ b/client/src/router.js @@ -25,17 +25,26 @@ const router = new Router({ { path: '/summoner/:region/:name', name: 'summoner', - component: Summoner + component: Summoner, + meta: { + season: true + } }, { path: '/summoner/:region/:name/champions', name: 'summonerChampions', - component: SummonerChampions + component: SummonerChampions, + meta: { + season: true + } }, { path: '/summoner/:region/:name/records', name: 'summonerRecords', - component: SummonerRecords + component: SummonerRecords, + meta: { + season: true + } }, { path: '/summoner/:region/:name/live', diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index f89b52e..3c03357 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -6,7 +6,7 @@ export const namespaced = true export const state = { basic: { account: {}, - currentSeason: 10, + currentSeason: null, matchList: [], ranked: {}, seasons: [], @@ -37,6 +37,7 @@ export const state = { export const mutations = { BASIC_REQUEST(state) { state.basic.status = 'loading' + state.basic.currentSeason = null state.champions.championsLoaded = false state.records.recordsLoaded = false state.overview.loaded = false @@ -93,7 +94,14 @@ export const mutations = { state.live.match = {} state.live.playing = false state.live.liveLoaded = false - } + }, + UPDATE_SEASON(state, { season }) { + state.basic.currentSeason = season + + state.overview.loaded = false + state.champions.championsLoaded = false + state.records.recordsLoaded = false + }, } export const actions = { @@ -171,6 +179,9 @@ export const actions = { const records = resp.data ? createRecordsData(resp.data) : {} commit('RECORDS_FOUND', { records }) + }, + updateSeason({ commit }, season) { + commit('UPDATE_SEASON', { season }) } } diff --git a/client/src/views/Summoner.vue b/client/src/views/Summoner.vue index 1fd1494..f3539b5 100644 --- a/client/src/views/Summoner.vue +++ b/client/src/views/Summoner.vue @@ -63,6 +63,9 @@ export default { }, watch: { + overviewLoaded() { + this.fetchData() + }, summonerFound() { this.fetchData() } diff --git a/client/src/views/SummonerChampions.vue b/client/src/views/SummonerChampions.vue index 997717e..314d92a 100644 --- a/client/src/views/SummonerChampions.vue +++ b/client/src/views/SummonerChampions.vue @@ -24,6 +24,7 @@ export default { data() { return { + queue: null, searchChampions: '' } }, @@ -53,6 +54,9 @@ export default { }, watch: { + championsLoaded() { + this.fetchData() + }, summonerFound() { this.fetchData() } @@ -65,13 +69,13 @@ export default { methods: { fetchData() { if (!this.championsLoaded && this.summonerFound) { - this.championsRequest() + this.championsRequest(this.queue) } }, filterByQueue(queue) { queue = Number(queue) - queue = queue === -1 ? null : queue - this.championsRequest(queue) + this.queue = queue === -1 ? null : queue + this.championsRequest(this.queue) }, updateSearch(search) { this.searchChampions = search diff --git a/client/src/views/SummonerRecords.vue b/client/src/views/SummonerRecords.vue index 9ec4c2f..0e28077 100644 --- a/client/src/views/SummonerRecords.vue +++ b/client/src/views/SummonerRecords.vue @@ -1,150 +1,148 @@