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-01-03 21:50:09 +00:00
|
|
|
current: {},
|
2019-10-05 22:01:58 +00:00
|
|
|
matchList: [],
|
2019-10-22 20:59:22 +00:00
|
|
|
ranked: {},
|
2019-12-27 17:38:43 +00:00
|
|
|
playing: false,
|
|
|
|
|
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: {},
|
|
|
|
|
liveLoaded: false
|
|
|
|
|
},
|
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'
|
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
|
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-01-14 21:04:45 +00:00
|
|
|
LIVE_FOUND(state, { live }) {
|
|
|
|
|
state.live.match = live
|
|
|
|
|
state.live.liveLoaded = true
|
|
|
|
|
},
|
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
|
2020-01-03 21:50:09 +00:00
|
|
|
state.basic.current = infos.current
|
2019-12-27 17:38:43 +00:00
|
|
|
state.basic.matchList = infos.matchList
|
|
|
|
|
state.basic.ranked = infos.ranked
|
|
|
|
|
state.basic.playing = infos.playing
|
|
|
|
|
state.basic.status = 'found'
|
2019-09-08 20:08:49 +00:00
|
|
|
},
|
|
|
|
|
SUMMONER_NOT_FOUND(state) {
|
2019-12-27 17:38:43 +00:00
|
|
|
state.basic.status = 'error'
|
|
|
|
|
},
|
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 }) {
|
2019-09-09 16:14:15 +00:00
|
|
|
region = rootState.regionsList[region]
|
2019-12-27 17:38:43 +00:00
|
|
|
commit('BASIC_REQUEST')
|
2019-09-08 20:08:49 +00:00
|
|
|
try {
|
2019-12-27 17:38:43 +00:00
|
|
|
const resp = await axios(({ url: 'summoner-basic', data: { summoner, region }, method: 'POST' }))
|
2019-09-08 20:08:49 +00:00
|
|
|
if (resp.data) {
|
2020-01-02 12:18:43 +00:00
|
|
|
console.log(`---SUMMONER INFOS ${resp.data.account.name}---`)
|
2019-10-25 21:09:33 +00:00
|
|
|
console.log(resp.data)
|
2019-12-27 17:38:43 +00:00
|
|
|
const infos = createBasicSummonerData(resp.data)
|
2019-09-08 20:08:49 +00:00
|
|
|
commit('SUMMONER_FOUND', infos)
|
|
|
|
|
} else {
|
|
|
|
|
commit('SUMMONER_NOT_FOUND')
|
|
|
|
|
|
|
|
|
|
dispatch('notification/add', {
|
|
|
|
|
type: 'error',
|
|
|
|
|
message: 'Summoner not found.'
|
|
|
|
|
}, { root: true })
|
|
|
|
|
console.log('Summoner not found - store')
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
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
|
|
|
console.log(error)
|
|
|
|
|
}
|
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) {
|
2019-12-27 17:38:43 +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 }) {
|
|
|
|
|
const resp = await axios(({ url: 'summoner-live', data: { account: state.basic.account, region: rootState.currentRegion }, method: 'POST' })).catch(() => { })
|
|
|
|
|
console.log('---LIVE---')
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
|
|
|
|
|
commit('LIVE_FOUND', { live: resp.data })
|
|
|
|
|
},
|
2019-12-27 17:38:43 +00:00
|
|
|
async moreMatches({ commit }) {
|
|
|
|
|
commit('MATCHES_LOADING')
|
|
|
|
|
|
|
|
|
|
const account = state.basic.account
|
|
|
|
|
const gameIds = state.basic.matchList.slice(state.overview.matchIndex, state.overview.matchIndex + 10).map(({ gameId }) => gameId)
|
|
|
|
|
|
|
|
|
|
const resp = await axios(({ url: 'match', data: { account, 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 })
|
|
|
|
|
},
|
|
|
|
|
async overviewRequest({ commit }) {
|
|
|
|
|
const resp = await axios(({ url: 'summoner-overview', data: { account: state.basic.account }, 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 }) {
|
|
|
|
|
const resp = await axios(({ url: 'summoner-records', data: { puuid: state.basic.account.puuid }, method: 'POST' })).catch(() => { })
|
|
|
|
|
console.log('---RECORDS---')
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
const records = resp.data ? createRecordsData(resp.data) : {}
|
|
|
|
|
|
|
|
|
|
commit('RECORDS_FOUND', { records })
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 20:02:05 +00:00
|
|
|
|
|
|
|
|
export const getters = {
|
2019-12-27 17:38:43 +00:00
|
|
|
matchesLoading: state => state.overview.matchesLoading,
|
|
|
|
|
moreMatchesToFetch: state => state.overview.matchIndex < state.basic.matchList.length,
|
|
|
|
|
overviewLoaded: state => state.overview.loaded,
|
|
|
|
|
playing: state => state.basic.playing,
|
|
|
|
|
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
|
|
|
}
|