2019-09-08 20:08:49 +00:00
|
|
|
import { axios } from '@/plugins/axios'
|
2020-01-12 00:31:28 +00:00
|
|
|
import { createMatchData, createBasicSummonerData, createRecordsData } from '@/helpers/summoner'
|
2019-09-08 20:08:49 +00:00
|
|
|
|
|
|
|
|
export const namespaced = true
|
|
|
|
|
|
|
|
|
|
export const state = {
|
2019-12-27 17:38:43 +00:00
|
|
|
basic: {
|
2019-10-05 22:01:58 +00:00
|
|
|
account: {},
|
2020-02-01 19:17:14 +00:00
|
|
|
currentSeason: null,
|
2019-10-05 22:01:58 +00:00
|
|
|
matchList: [],
|
2019-10-22 20:59:22 +00:00
|
|
|
ranked: {},
|
2020-02-01 16:14:03 +00:00
|
|
|
seasons: [],
|
2019-12-27 17:38:43 +00:00
|
|
|
status: '',
|
|
|
|
|
},
|
|
|
|
|
overview: {
|
|
|
|
|
matchIndex: 0,
|
|
|
|
|
matches: [],
|
2019-11-11 20:51:40 +00:00
|
|
|
stats: {},
|
2019-12-27 17:38:43 +00:00
|
|
|
loaded: false,
|
|
|
|
|
matchesLoading: false,
|
|
|
|
|
},
|
|
|
|
|
champions: {
|
|
|
|
|
list: [],
|
|
|
|
|
championsLoaded: false
|
2019-10-05 22:01:58 +00:00
|
|
|
},
|
2020-01-12 00:31:28 +00:00
|
|
|
records: {
|
|
|
|
|
list: [],
|
|
|
|
|
recordsLoaded: false
|
|
|
|
|
},
|
2020-01-14 21:04:45 +00:00
|
|
|
live: {
|
|
|
|
|
match: {},
|
2020-01-19 15:18:35 +00:00
|
|
|
liveLoaded: false,
|
|
|
|
|
playing: false,
|
2020-01-14 21:04:45 +00:00
|
|
|
},
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const mutations = {
|
2019-12-27 17:38:43 +00:00
|
|
|
BASIC_REQUEST(state) {
|
|
|
|
|
state.basic.status = 'loading'
|
2020-02-01 19:17:14 +00:00
|
|
|
state.basic.currentSeason = null
|
2019-12-27 21:09:24 +00:00
|
|
|
state.champions.championsLoaded = false
|
2020-01-12 00:31:28 +00:00
|
|
|
state.records.recordsLoaded = false
|
2019-12-28 22:49:53 +00:00
|
|
|
state.overview.loaded = false
|
2020-01-15 19:06:45 +00:00
|
|
|
state.live.liveLoaded = false
|
2019-12-27 17:38:43 +00:00
|
|
|
},
|
2020-01-08 18:04:58 +00:00
|
|
|
CHAMPIONS_NOT_FOUND(state) {
|
|
|
|
|
state.champions.championsLoaded = false
|
|
|
|
|
},
|
2019-12-21 16:56:31 +00:00
|
|
|
CHAMPIONS_FOUND(state, { champions }) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.champions.list = champions
|
|
|
|
|
state.champions.championsLoaded = true
|
2019-12-21 16:56:31 +00:00
|
|
|
},
|
2020-08-12 12:27:45 +00:00
|
|
|
KEEP_LAST_X_MATCHES(state, number) {
|
|
|
|
|
state.overview.matchIndex = number
|
|
|
|
|
state.overview.matches = state.overview.matches.slice(0, number)
|
|
|
|
|
},
|
2020-01-14 21:04:45 +00:00
|
|
|
LIVE_FOUND(state, { live }) {
|
|
|
|
|
state.live.match = live
|
|
|
|
|
state.live.liveLoaded = true
|
|
|
|
|
},
|
2020-02-02 14:38:56 +00:00
|
|
|
LIVE_LOADING(state) {
|
|
|
|
|
state.live.playing = true
|
2020-01-15 20:55:22 +00:00
|
|
|
state.live.liveLoaded = false
|
|
|
|
|
},
|
2019-10-06 13:08:24 +00:00
|
|
|
MATCHES_LOADING(state) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.overview.matchesLoading = true
|
2019-10-06 13:08:24 +00:00
|
|
|
},
|
2019-11-11 20:51:40 +00:00
|
|
|
MATCHES_FOUND(state, { newMatches, stats }) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.overview.matchesLoading = false
|
2020-01-02 09:52:52 +00:00
|
|
|
state.overview.matches = [...state.overview.matches, ...newMatches]
|
2019-12-27 17:38:43 +00:00
|
|
|
state.overview.matchIndex += newMatches.length
|
|
|
|
|
state.overview.stats = stats
|
|
|
|
|
state.champions.championsLoaded = false
|
2020-01-12 00:31:28 +00:00
|
|
|
state.records.recordsLoaded = false
|
2019-10-05 22:01:58 +00:00
|
|
|
},
|
2019-12-27 17:38:43 +00:00
|
|
|
OVERVIEW_FOUND(state, infos) {
|
|
|
|
|
state.overview.matches = infos.matches
|
|
|
|
|
state.overview.matchIndex = infos.matches.length
|
|
|
|
|
state.overview.stats = infos.stats
|
|
|
|
|
state.overview.loaded = true
|
2019-09-08 20:08:49 +00:00
|
|
|
},
|
2020-01-12 00:31:28 +00:00
|
|
|
RECORDS_FOUND(state, { records }) {
|
|
|
|
|
state.records.list = records
|
|
|
|
|
state.records.recordsLoaded = true
|
|
|
|
|
},
|
2019-09-08 20:08:49 +00:00
|
|
|
SUMMONER_FOUND(state, infos) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.basic.account = infos.account
|
|
|
|
|
state.basic.matchList = infos.matchList
|
|
|
|
|
state.basic.ranked = infos.ranked
|
2020-02-04 18:28:57 +00:00
|
|
|
state.basic.seasons = infos.seasons.sort((a, b) => b - a)
|
2019-12-27 17:38:43 +00:00
|
|
|
state.basic.status = 'found'
|
2020-01-19 15:18:35 +00:00
|
|
|
state.live.match = infos.current
|
|
|
|
|
state.live.playing = infos.playing
|
2019-09-08 20:08:49 +00:00
|
|
|
},
|
|
|
|
|
SUMMONER_NOT_FOUND(state) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.basic.status = 'error'
|
|
|
|
|
},
|
2020-01-19 16:03:40 +00:00
|
|
|
SUMMONER_NOT_PLAYING(state) {
|
|
|
|
|
state.live.match = {}
|
|
|
|
|
state.live.playing = false
|
|
|
|
|
state.live.liveLoaded = false
|
2020-02-01 19:17:14 +00:00
|
|
|
},
|
|
|
|
|
UPDATE_SEASON(state, { season }) {
|
|
|
|
|
state.basic.currentSeason = season
|
|
|
|
|
|
|
|
|
|
state.overview.loaded = false
|
|
|
|
|
state.champions.championsLoaded = false
|
|
|
|
|
state.records.recordsLoaded = false
|
|
|
|
|
},
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const actions = {
|
2019-12-27 17:38:43 +00:00
|
|
|
async basicRequest({ commit, dispatch, rootState }, { summoner, region }) {
|
2020-02-10 19:53:32 +00:00
|
|
|
const regionId = rootState.regionsList[region]
|
2019-12-27 17:38:43 +00:00
|
|
|
commit('BASIC_REQUEST')
|
2019-09-08 20:08:49 +00:00
|
|
|
try {
|
2020-02-13 19:30:26 +00:00
|
|
|
const resp = await axios(({ url: 'summoner/basic', data: { summoner, region: regionId }, method: 'POST' }))
|
2020-10-11 16:32:33 +00:00
|
|
|
if (!resp.data) {
|
|
|
|
|
dispatch('notification/add', {
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: 'Summoner not found.'
|
2020-02-10 19:53:32 +00:00
|
|
|
}, { root: true })
|
2020-10-11 16:32:33 +00:00
|
|
|
return commit('SUMMONER_NOT_FOUND')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log(`---SUMMONER INFOS ${resp.data.account.name}---`)
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
const infos = createBasicSummonerData(resp.data)
|
|
|
|
|
commit('SUMMONER_FOUND', infos)
|
2019-09-08 20:08:49 +00:00
|
|
|
|
2020-10-11 16:32:33 +00:00
|
|
|
// Add summoner to recent searches
|
|
|
|
|
dispatch('settings/addRecentSearch', {
|
|
|
|
|
name: infos.account.name,
|
|
|
|
|
icon: infos.account.profileIconId,
|
|
|
|
|
region,
|
|
|
|
|
}, { root: true })
|
|
|
|
|
} catch (error) {
|
|
|
|
|
if (error.response && error.response.status === 422) {
|
2019-09-08 20:08:49 +00:00
|
|
|
dispatch('notification/add', {
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: 'Summoner not found.'
|
|
|
|
|
}, { root: true })
|
|
|
|
|
}
|
2020-01-12 00:31:28 +00:00
|
|
|
if (error.message !== 'Summoner changed') {
|
2020-01-02 12:18:43 +00:00
|
|
|
commit('SUMMONER_NOT_FOUND')
|
|
|
|
|
}
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
2019-12-27 17:38:43 +00:00
|
|
|
},
|
2020-01-08 18:04:58 +00:00
|
|
|
championsNotLoaded({ commit }) {
|
|
|
|
|
commit('CHAMPIONS_NOT_FOUND')
|
|
|
|
|
},
|
2020-01-01 15:39:54 +00:00
|
|
|
async championsRequest({ commit }, queue = null) {
|
2020-02-13 19:30:26 +00:00
|
|
|
const resp = await axios(({ url: 'summoner/champions', data: { puuid: state.basic.account.puuid, queue: queue }, method: 'POST' })).catch(() => { })
|
2020-01-01 15:39:54 +00:00
|
|
|
console.log('---CHAMPIONS---')
|
2019-12-27 17:38:43 +00:00
|
|
|
console.log(resp.data)
|
|
|
|
|
|
|
|
|
|
commit('CHAMPIONS_FOUND', { champions: resp.data })
|
|
|
|
|
},
|
2020-01-14 21:04:45 +00:00
|
|
|
async liveMatchRequest({ commit, rootState }) {
|
2020-02-02 14:38:56 +00:00
|
|
|
commit('LIVE_LOADING')
|
2020-10-10 20:41:30 +00:00
|
|
|
const resp = await axios(({
|
|
|
|
|
url: 'summoner/live',
|
|
|
|
|
data: {
|
|
|
|
|
id: state.basic.account.id,
|
|
|
|
|
region: rootState.regionsList[rootState.settings.region]
|
|
|
|
|
},
|
|
|
|
|
method: 'POST'
|
|
|
|
|
})).catch(() => { })
|
2020-01-14 21:04:45 +00:00
|
|
|
console.log('---LIVE---')
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
|
2020-01-15 20:55:22 +00:00
|
|
|
if (resp.data) {
|
|
|
|
|
commit('LIVE_FOUND', { live: resp.data })
|
2020-01-19 16:03:40 +00:00
|
|
|
} else {
|
|
|
|
|
commit('SUMMONER_NOT_PLAYING')
|
2020-01-15 20:55:22 +00:00
|
|
|
}
|
2020-01-14 21:04:45 +00:00
|
|
|
},
|
2020-11-06 21:09:18 +00:00
|
|
|
async moreMatches({ commit, getters, rootState }) {
|
2019-12-27 17:38:43 +00:00
|
|
|
commit('MATCHES_LOADING')
|
|
|
|
|
|
2020-11-14 17:40:26 +00:00
|
|
|
const gameIds = getters.filteredMatchList
|
2020-11-06 21:09:18 +00:00
|
|
|
.slice(state.overview.matchIndex, state.overview.matchIndex + 10)
|
2021-08-10 22:12:17 +00:00
|
|
|
.map((gameId) => {
|
|
|
|
|
if(typeof gameId == 'string') {
|
|
|
|
|
return gameId
|
|
|
|
|
}
|
|
|
|
|
return gameId.gameId.toString()
|
|
|
|
|
})
|
2019-12-27 17:38:43 +00:00
|
|
|
|
2020-10-11 14:35:23 +00:00
|
|
|
const resp = await axios(({
|
|
|
|
|
url: 'match',
|
|
|
|
|
data: {
|
|
|
|
|
puuid: state.basic.account.puuid,
|
|
|
|
|
accountId: state.basic.account.accountId,
|
|
|
|
|
region: rootState.regionsList[rootState.settings.region],
|
|
|
|
|
gameIds
|
|
|
|
|
},
|
|
|
|
|
method: 'POST'
|
|
|
|
|
})).catch(() => { })
|
2020-01-01 15:39:54 +00:00
|
|
|
console.log('---MATCHES INFOS---')
|
2019-12-27 17:38:43 +00:00
|
|
|
console.log(resp.data)
|
|
|
|
|
const newMatches = createMatchData(resp.data.matches)
|
|
|
|
|
commit('MATCHES_FOUND', { newMatches, stats: resp.data.stats })
|
|
|
|
|
},
|
2020-10-10 20:06:12 +00:00
|
|
|
async overviewRequest({ commit, rootState }) {
|
|
|
|
|
const resp = await axios(({
|
|
|
|
|
url: 'summoner/overview',
|
|
|
|
|
data: {
|
|
|
|
|
puuid: state.basic.account.puuid,
|
|
|
|
|
accountId: state.basic.account.accountId,
|
|
|
|
|
region: rootState.regionsList[rootState.settings.region],
|
|
|
|
|
},
|
|
|
|
|
method: 'POST'
|
|
|
|
|
})).catch(() => { })
|
2020-01-01 15:39:54 +00:00
|
|
|
console.log('---OVERVIEW---')
|
2019-12-27 17:38:43 +00:00
|
|
|
console.log(resp.data)
|
|
|
|
|
resp.data.matches = createMatchData(resp.data.matchesDetails)
|
|
|
|
|
commit('OVERVIEW_FOUND', resp.data)
|
2020-01-12 00:31:28 +00:00
|
|
|
},
|
|
|
|
|
async recordsRequest({ commit }) {
|
2020-02-13 19:30:26 +00:00
|
|
|
const resp = await axios(({ url: 'summoner/records', data: { puuid: state.basic.account.puuid }, method: 'POST' })).catch(() => { })
|
2020-01-12 00:31:28 +00:00
|
|
|
console.log('---RECORDS---')
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
const records = resp.data ? createRecordsData(resp.data) : {}
|
|
|
|
|
|
|
|
|
|
commit('RECORDS_FOUND', { records })
|
2020-02-01 19:17:14 +00:00
|
|
|
},
|
2020-08-12 12:27:45 +00:00
|
|
|
sliceOverviewMatches({ commit }, number) {
|
|
|
|
|
commit('KEEP_LAST_X_MATCHES', number)
|
|
|
|
|
},
|
2020-02-01 19:17:14 +00:00
|
|
|
updateSeason({ commit }, season) {
|
|
|
|
|
commit('UPDATE_SEASON', { season })
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 20:02:05 +00:00
|
|
|
|
|
|
|
|
export const getters = {
|
2020-11-14 17:40:26 +00:00
|
|
|
filteredMatchList: (state, getters) => {
|
|
|
|
|
return state.basic.matchList
|
|
|
|
|
.filter(match => !getters.regionFilterApplied || match.seasonMatch === state.basic.currentSeason)
|
|
|
|
|
},
|
2019-12-27 17:38:43 +00:00
|
|
|
matchesLoading: state => state.overview.matchesLoading,
|
2020-11-14 17:40:26 +00:00
|
|
|
moreMatchesToFetch: (state, getters) => {
|
|
|
|
|
return state.overview.matchIndex < getters.filteredMatchList.length
|
|
|
|
|
},
|
2019-12-27 17:38:43 +00:00
|
|
|
overviewLoaded: state => state.overview.loaded,
|
2020-01-19 15:18:35 +00:00
|
|
|
playing: state => state.live.playing,
|
2020-11-06 21:09:18 +00:00
|
|
|
regionFilterApplied: state => !!state.basic.currentSeason,
|
2019-12-27 17:38:43 +00:00
|
|
|
summonerFound: state => state.basic.status === 'found',
|
|
|
|
|
summonerNotFound: state => state.basic.status === 'error',
|
|
|
|
|
summonerLoading: state => state.basic.status === 'loading',
|
2019-09-11 20:02:05 +00:00
|
|
|
}
|