From 5c79f045632c70937afc8668245ee16642936074 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 8 Jan 2022 00:55:50 +0100 Subject: [PATCH] feat(champions): add filter by gamemode back --- .../components/Summoner/Champions/FilterQueue.vue | 4 ++-- client/src/store/modules/summoner.js | 2 ++ client/src/views/SummonerChampions.vue | 8 ++++---- server/app/Controllers/Http/SummonersController.ts | 4 +++- server/app/Repositories/MatchRepository.ts | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/client/src/components/Summoner/Champions/FilterQueue.vue b/client/src/components/Summoner/Champions/FilterQueue.vue index bff3e0a..3285f38 100644 --- a/client/src/components/Summoner/Champions/FilterQueue.vue +++ b/client/src/components/Summoner/Champions/FilterQueue.vue @@ -36,12 +36,12 @@ export default { created() { // Show all queues when loading the page - this.queue = -1 + this.queue = 0 }, destroyed() { // Reload all champions stats for next user visit of the champions tab - if (this.queue !== -1) + if (this.queue !== 0) this.championsNotLoaded() }, diff --git a/client/src/store/modules/summoner.js b/client/src/store/modules/summoner.js index 931dc90..2a4241e 100644 --- a/client/src/store/modules/summoner.js +++ b/client/src/store/modules/summoner.js @@ -11,6 +11,7 @@ export const state = { ranked: {}, recentActivity: [], seasons: [], + gamemodes: [], status: '', }, overview: { @@ -93,6 +94,7 @@ export const mutations = { state.basic.ranked = infos.ranked state.basic.recentActivity = infos.recentActivity state.basic.seasons = infos.seasons.sort((a, b) => b - a) + state.basic.gamemodes = infos.gamemodes state.basic.status = 'found' state.live.match = infos.current state.live.playing = infos.playing diff --git a/client/src/views/SummonerChampions.vue b/client/src/views/SummonerChampions.vue index e5eee67..00889f3 100644 --- a/client/src/views/SummonerChampions.vue +++ b/client/src/views/SummonerChampions.vue @@ -44,7 +44,7 @@ export default { const queues = Object.keys(gameModes) .filter(gameMode => gameModes[gameMode].type !== 'Bot' && - this.matchList.find(match => match.queue === Number(gameMode)) + this.gamemodes.includes(Number(gameMode)) ) .reduce((obj, key) => { return { @@ -52,13 +52,13 @@ export default { [key]: gameModes[key] } }, {}) - return { '-1': { type: 'Normal', name: 'All queues' }, ...queues } + return { '0': { type: 'Normal', name: 'All queues' }, ...queues } }, ...mapGetters('summoner', ['summonerFound']), ...mapState({ champions: state => state.summoner.champions.list, championsLoaded: state => state.summoner.champions.championsLoaded, - matchList: state => state.summoner.basic.matchList + gamemodes: state => state.summoner.basic.gamemodes }) }, @@ -83,7 +83,7 @@ export default { }, filterByQueue(queue) { queue = Number(queue) - this.queue = queue === -1 ? null : queue + this.queue = queue === 0 ? null : queue this.championsRequest(this.queue) }, updateSearch(search) { diff --git a/server/app/Controllers/Http/SummonersController.ts b/server/app/Controllers/Http/SummonersController.ts index fd585d9..7d803e0 100644 --- a/server/app/Controllers/Http/SummonersController.ts +++ b/server/app/Controllers/Http/SummonersController.ts @@ -51,9 +51,11 @@ export default class SummonersController { finalJSON.matchList = await MatchService.updateMatchList(account, region, summonerDB) // All seasons the summoner has played - // TODO: check if there is a way to do that with V5... finalJSON.seasons = await this.getSeasons(account.puuid) + // All gamemodes the summoner has played + finalJSON.gamemodes = (await MatchRepository.gamemodes(account.puuid)).map((g) => g.gamemode) + // CURRENT GAME console.time('playing') const currentGame = await Jax.Spectator.summonerID(account.id, region) diff --git a/server/app/Repositories/MatchRepository.ts b/server/app/Repositories/MatchRepository.ts index 2995c2e..7d5391f 100644 --- a/server/app/Repositories/MatchRepository.ts +++ b/server/app/Repositories/MatchRepository.ts @@ -26,6 +26,20 @@ class MatchRepository { return query } + public async gamemodes(puuid: string) { + const query = ` + SELECT DISTINCT + matches.gamemode + FROM + match_players + ${this.JOIN_MATCHES} + WHERE + match_players.summoner_puuid = :puuid + ` + const { rows } = await Database.rawQuery(query, { puuid }) + return rows + } + public async seasons(puuid: string) { const query = ` SELECT DISTINCT