mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
fix: load more matches when season is selected now works again
This commit is contained in:
parent
4811f95aa0
commit
9af2dd90c3
5 changed files with 51 additions and 27 deletions
|
|
@ -15,11 +15,13 @@ export const state = {
|
||||||
status: '',
|
status: '',
|
||||||
},
|
},
|
||||||
overview: {
|
overview: {
|
||||||
matchIndex: 0,
|
NB_LOAD_GAMES: 10,
|
||||||
matches: [],
|
matches: [],
|
||||||
|
lastMatchId: null,
|
||||||
stats: {},
|
stats: {},
|
||||||
loaded: false,
|
loaded: false,
|
||||||
matchesLoading: false,
|
matchesLoading: false,
|
||||||
|
moreMatchesToFetch: true
|
||||||
},
|
},
|
||||||
champions: {
|
champions: {
|
||||||
list: [],
|
list: [],
|
||||||
|
|
@ -43,6 +45,7 @@ export const mutations = {
|
||||||
state.champions.championsLoaded = false
|
state.champions.championsLoaded = false
|
||||||
state.records.recordsLoaded = false
|
state.records.recordsLoaded = false
|
||||||
state.overview.loaded = false
|
state.overview.loaded = false
|
||||||
|
state.overview.moreMatchesToFetch = true
|
||||||
state.live.liveLoaded = false
|
state.live.liveLoaded = false
|
||||||
},
|
},
|
||||||
CHAMPIONS_NOT_FOUND(state) {
|
CHAMPIONS_NOT_FOUND(state) {
|
||||||
|
|
@ -53,8 +56,8 @@ export const mutations = {
|
||||||
state.champions.championsLoaded = true
|
state.champions.championsLoaded = true
|
||||||
},
|
},
|
||||||
KEEP_LAST_X_MATCHES(state, number) {
|
KEEP_LAST_X_MATCHES(state, number) {
|
||||||
state.overview.matchIndex = number
|
|
||||||
state.overview.matches = state.overview.matches.slice(0, number)
|
state.overview.matches = state.overview.matches.slice(0, number)
|
||||||
|
state.overview.lastMatchId = state.overview.matches[state.overview.matches.length - 1].matchId
|
||||||
},
|
},
|
||||||
LIVE_FOUND(state, { live }) {
|
LIVE_FOUND(state, { live }) {
|
||||||
state.live.match = live
|
state.live.match = live
|
||||||
|
|
@ -68,21 +71,27 @@ export const mutations = {
|
||||||
state.overview.matchesLoading = true
|
state.overview.matchesLoading = true
|
||||||
},
|
},
|
||||||
MATCHES_FOUND(state, { newMatches, stats }) {
|
MATCHES_FOUND(state, { newMatches, stats }) {
|
||||||
state.basic.recentActivity = stats.recentActivity
|
|
||||||
state.overview.matchesLoading = false
|
state.overview.matchesLoading = false
|
||||||
|
|
||||||
|
if (newMatches.length > 0) {
|
||||||
|
state.basic.recentActivity = stats.recentActivity
|
||||||
state.overview.matches = [...state.overview.matches, ...newMatches]
|
state.overview.matches = [...state.overview.matches, ...newMatches]
|
||||||
state.overview.matchIndex += 10
|
state.overview.lastMatchId = newMatches[newMatches.length - 1].matchId
|
||||||
state.overview.stats = stats
|
state.overview.stats = stats
|
||||||
state.champions.championsLoaded = false
|
state.champions.championsLoaded = false
|
||||||
state.records.recordsLoaded = false
|
state.records.recordsLoaded = false
|
||||||
|
}
|
||||||
|
|
||||||
|
state.overview.moreMatchesToFetch = newMatches.length >= state.overview.NB_LOAD_GAMES - 1
|
||||||
},
|
},
|
||||||
OVERVIEW_FOUND(state, infos) {
|
OVERVIEW_FOUND(state, infos) {
|
||||||
state.basic.recentActivity = infos.stats.recentActivity
|
state.basic.recentActivity = infos.stats.recentActivity
|
||||||
state.overview.matches = infos.matches
|
state.overview.matches = infos.matches
|
||||||
state.overview.matchIndex = infos.matches.length
|
state.overview.lastMatchId = infos.matches[infos.matches.length - 1].matchId
|
||||||
state.overview.stats = infos.stats
|
state.overview.stats = infos.stats
|
||||||
state.overview.loaded = true
|
state.overview.loaded = true
|
||||||
state.records.recordsLoaded = false
|
state.records.recordsLoaded = false
|
||||||
|
state.overview.moreMatchesToFetch = infos.matches.length >= state.overview.NB_LOAD_GAMES - 1
|
||||||
},
|
},
|
||||||
RECORDS_FOUND(state, { records }) {
|
RECORDS_FOUND(state, { records }) {
|
||||||
state.records.list = records
|
state.records.list = records
|
||||||
|
|
@ -182,18 +191,14 @@ export const actions = {
|
||||||
commit('SUMMONER_NOT_PLAYING')
|
commit('SUMMONER_NOT_PLAYING')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async moreMatches({ commit, getters, rootState }) {
|
async moreMatches({ commit, rootState }) {
|
||||||
commit('MATCHES_LOADING')
|
commit('MATCHES_LOADING')
|
||||||
|
|
||||||
const matchIds = getters.filteredMatchList
|
|
||||||
.slice(state.overview.matchIndex, state.overview.matchIndex + 10)
|
|
||||||
|
|
||||||
const resp = await axios(({
|
const resp = await axios(({
|
||||||
url: 'match',
|
url: 'match',
|
||||||
data: {
|
data: {
|
||||||
puuid: state.basic.account.puuid,
|
puuid: state.basic.account.puuid,
|
||||||
region: rootState.regionsList[rootState.settings.region],
|
region: rootState.regionsList[rootState.settings.region],
|
||||||
matchIds
|
lastMatchId: state.overview.lastMatchId
|
||||||
},
|
},
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
})).catch(() => { })
|
})).catch(() => { })
|
||||||
|
|
@ -234,14 +239,7 @@ export const actions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
filteredMatchList: (state, getters) => {
|
|
||||||
return state.basic.matchList
|
|
||||||
.filter(match => !getters.regionFilterApplied || match.seasonMatch === state.basic.currentSeason)
|
|
||||||
},
|
|
||||||
matchesLoading: state => state.overview.matchesLoading,
|
matchesLoading: state => state.overview.matchesLoading,
|
||||||
moreMatchesToFetch: (state, getters) => {
|
|
||||||
return state.overview.matchIndex < getters.filteredMatchList.length
|
|
||||||
},
|
|
||||||
overviewLoaded: state => state.overview.loaded,
|
overviewLoaded: state => state.overview.loaded,
|
||||||
playing: state => state.live.playing,
|
playing: state => state.live.playing,
|
||||||
regionFilterApplied: state => !!state.basic.currentSeason,
|
regionFilterApplied: state => !!state.basic.currentSeason,
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
/>
|
/>
|
||||||
</ul>
|
</ul>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
v-if="moreMatchesToFetch"
|
v-if="overview.moreMatchesToFetch"
|
||||||
@clicked="moreMatches"
|
@clicked="moreMatches"
|
||||||
:loading="matchesLoading"
|
:loading="matchesLoading"
|
||||||
btn-class="block px-4 py-2 mx-auto mt-4 font-semibold bg-blue-800 rounded-md shadow-lg hover:bg-blue-1000"
|
btn-class="block px-4 py-2 mx-auto mt-4 font-semibold bg-blue-800 rounded-md shadow-lg hover:bg-blue-1000"
|
||||||
|
|
@ -78,7 +78,7 @@ export default {
|
||||||
current: state => state.summoner.live.match,
|
current: state => state.summoner.live.match,
|
||||||
overview: state => state.summoner.overview,
|
overview: state => state.summoner.overview,
|
||||||
}),
|
}),
|
||||||
...mapGetters('summoner', ['matchesLoading', 'moreMatchesToFetch', 'overviewLoaded', 'summonerFound'])
|
...mapGetters('summoner', ['matchesLoading', 'overviewLoaded', 'summonerFound'])
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import Match from 'App/Models/Match'
|
||||||
import MatchPlayerRankParser from 'App/Parsers/MatchPlayerRankParser'
|
import MatchPlayerRankParser from 'App/Parsers/MatchPlayerRankParser'
|
||||||
import DetailedMatchSerializer from 'App/Serializers/DetailedMatchSerializer'
|
import DetailedMatchSerializer from 'App/Serializers/DetailedMatchSerializer'
|
||||||
import MatchPlayerRankSerializer from 'App/Serializers/MatchPlayerRankSerializer'
|
import MatchPlayerRankSerializer from 'App/Serializers/MatchPlayerRankSerializer'
|
||||||
|
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
||||||
import MatchService from 'App/Services/MatchService'
|
import MatchService from 'App/Services/MatchService'
|
||||||
import StatsService from 'App/Services/StatsService'
|
import StatsService from 'App/Services/StatsService'
|
||||||
import DetailedMatchValidator from 'App/Validators/DetailedMatchValidator'
|
import DetailedMatchValidator from 'App/Validators/DetailedMatchValidator'
|
||||||
|
|
@ -14,8 +15,13 @@ export default class MatchesController {
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public async index({ request, response }: HttpContextContract) {
|
public async index({ request, response }: HttpContextContract) {
|
||||||
const { puuid, region, matchIds, season } = await request.validate(MatchesIndexValidator)
|
const { puuid, region, lastMatchId, season } = await request.validate(MatchesIndexValidator)
|
||||||
const matches = await MatchService.getMatches(region, matchIds, puuid)
|
const matchIds = await MatchService.getMatchIdsToFetch(lastMatchId, puuid, season)
|
||||||
|
let matches: SerializedMatch[] = []
|
||||||
|
|
||||||
|
if (matchIds.length > 0) {
|
||||||
|
matches = await MatchService.getMatches(region, matchIds, puuid)
|
||||||
|
}
|
||||||
|
|
||||||
const stats = await StatsService.getSummonerStats(puuid, season)
|
const stats = await StatsService.getSummonerStats(puuid, season)
|
||||||
return response.json({
|
return response.json({
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
||||||
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
||||||
import Match from 'App/Models/Match'
|
import Match from 'App/Models/Match'
|
||||||
import { notEmpty, tutorialQueues } from 'App/helpers'
|
import { notEmpty, tutorialQueues } from 'App/helpers'
|
||||||
|
import SummonerMatchlist from 'App/Models/SummonerMatchlist'
|
||||||
|
|
||||||
class MatchService {
|
class MatchService {
|
||||||
/**
|
/**
|
||||||
|
|
@ -82,6 +83,25 @@ class MatchService {
|
||||||
return currentMatchListIds.reverse()
|
return currentMatchListIds.reverse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of matchIds from the next matches to fetch for a specific Summoner
|
||||||
|
*/
|
||||||
|
public async getMatchIdsToFetch(lastMatchId: string, puuid: string, season?: number) {
|
||||||
|
const matchListQuery = SummonerMatchlist.query()
|
||||||
|
.select('matchId')
|
||||||
|
.where('summoner_puuid', puuid)
|
||||||
|
.andWhere('match_id', '<', lastMatchId)
|
||||||
|
|
||||||
|
if (season) {
|
||||||
|
matchListQuery
|
||||||
|
.join('matches', 'summoner_matchlist.match_id', 'matches.id')
|
||||||
|
.where('matches.season', season)
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchlist = await matchListQuery.orderBy('matchId', 'desc').limit(10)
|
||||||
|
return matchlist.map((m) => m.matchId)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch list of matches for a specific Summoner
|
* Fetch list of matches for a specific Summoner
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export default class MatchesIndexValidator {
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
puuid: schema.string(),
|
puuid: schema.string(),
|
||||||
region: schema.string(),
|
region: schema.string(),
|
||||||
matchIds: schema.array().members(schema.string()),
|
lastMatchId: schema.string(),
|
||||||
season: schema.number.optional(),
|
season: schema.number.optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue