2019-09-08 20:08:49 +00:00
|
|
|
import { axios } from '@/plugins/axios'
|
2019-10-25 21:09:33 +00:00
|
|
|
import { createMatchData, createMatesData, createSummonerData } from '@/helpers/summoner'
|
2019-09-08 20:08:49 +00:00
|
|
|
|
|
|
|
|
export const namespaced = true
|
|
|
|
|
|
|
|
|
|
export const state = {
|
2019-10-05 22:01:58 +00:00
|
|
|
infos: {
|
|
|
|
|
account: {},
|
|
|
|
|
matchIndex: 0,
|
|
|
|
|
matchList: [],
|
|
|
|
|
matches: [],
|
2019-10-25 21:09:33 +00:00
|
|
|
mates: [],
|
2019-10-22 20:59:22 +00:00
|
|
|
ranked: {},
|
|
|
|
|
playing: false
|
2019-10-05 22:01:58 +00:00
|
|
|
},
|
2019-10-06 13:08:24 +00:00
|
|
|
matchesLoading: false,
|
2019-09-11 20:02:05 +00:00
|
|
|
status: '',
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const mutations = {
|
2019-10-06 13:08:24 +00:00
|
|
|
MATCHES_LOADING(state) {
|
|
|
|
|
state.matchesLoading = true
|
|
|
|
|
},
|
2019-10-25 21:09:33 +00:00
|
|
|
MATCHES_FOUND(state, { newMatches, mates }) {
|
2019-10-06 13:08:24 +00:00
|
|
|
state.matchesLoading = false
|
|
|
|
|
|
2019-10-05 22:01:58 +00:00
|
|
|
state.infos.matches = [...state.infos.matches, ...newMatches]
|
|
|
|
|
|
|
|
|
|
state.infos.matchIndex += newMatches.length
|
2019-10-25 21:09:33 +00:00
|
|
|
|
|
|
|
|
state.infos.mates = mates
|
2019-10-05 22:01:58 +00:00
|
|
|
},
|
2019-09-08 20:08:49 +00:00
|
|
|
SUMMONER_REQUEST(state) {
|
2019-09-11 20:02:05 +00:00
|
|
|
state.status = 'loading'
|
2019-09-08 20:08:49 +00:00
|
|
|
},
|
|
|
|
|
SUMMONER_FOUND(state, infos) {
|
2019-10-05 22:01:58 +00:00
|
|
|
state.infos.account = infos.account
|
|
|
|
|
state.infos.matchList = infos.matchList
|
|
|
|
|
state.infos.matches = infos.matches
|
2019-10-08 19:54:32 +00:00
|
|
|
state.infos.ranked = infos.ranked
|
2019-10-05 22:01:58 +00:00
|
|
|
state.infos.matchIndex = infos.matches.length
|
2019-10-22 20:59:22 +00:00
|
|
|
state.infos.playing = infos.playing
|
2019-11-08 14:39:56 +00:00
|
|
|
state.infos.stats = infos.stats
|
2019-09-11 20:02:05 +00:00
|
|
|
state.status = 'found'
|
2019-09-08 20:08:49 +00:00
|
|
|
},
|
|
|
|
|
SUMMONER_NOT_FOUND(state) {
|
2019-09-11 20:02:05 +00:00
|
|
|
state.status = 'error'
|
2019-09-08 20:08:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const actions = {
|
2019-10-05 22:01:58 +00:00
|
|
|
async moreMatches({ commit }) {
|
2019-10-06 13:08:24 +00:00
|
|
|
commit('MATCHES_LOADING')
|
|
|
|
|
|
2019-10-05 22:01:58 +00:00
|
|
|
const account = state.infos.account
|
|
|
|
|
const gameIds = state.infos.matchList.slice(state.infos.matchIndex, state.infos.matchIndex + 10).map(({ gameId }) => gameId)
|
|
|
|
|
|
|
|
|
|
const resp = await axios(({ url: 'match', data: { account, gameIds }, method: 'POST' })).catch(() => { })
|
2019-10-25 21:09:33 +00:00
|
|
|
console.log('--- MATCHES INFOS ---')
|
|
|
|
|
console.log(resp.data)
|
|
|
|
|
const newMatches = createMatchData(resp.data.matches)
|
|
|
|
|
const mates = createMatesData(resp.data.mates)
|
|
|
|
|
commit('MATCHES_FOUND', { newMatches, mates })
|
2019-10-05 22:01:58 +00:00
|
|
|
},
|
2019-09-08 20:08:49 +00:00
|
|
|
async summonerRequest({ commit, dispatch, rootState }, { summoner, region }) {
|
2019-09-09 16:14:15 +00:00
|
|
|
region = rootState.regionsList[region]
|
2019-09-08 20:08:49 +00:00
|
|
|
commit('SUMMONER_REQUEST')
|
|
|
|
|
try {
|
|
|
|
|
const resp = await axios(({ url: 'api', data: { summoner, region }, method: 'POST' }))
|
|
|
|
|
if (resp.data) {
|
2019-10-25 21:09:33 +00:00
|
|
|
console.log('--- SUMMONER INFOS ---')
|
|
|
|
|
console.log(resp.data)
|
2019-10-21 13:30:48 +00:00
|
|
|
dispatch('ddragon/getVersion', resp.data.version, { root: true })
|
2019-09-29 16:06:54 +00:00
|
|
|
const infos = createSummonerData(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) {
|
|
|
|
|
commit('SUMMONER_NOT_FOUND')
|
|
|
|
|
console.log(error)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 20:02:05 +00:00
|
|
|
|
|
|
|
|
export const getters = {
|
2019-10-06 13:08:24 +00:00
|
|
|
matchesLoading: state => state.matchesLoading,
|
2019-10-05 22:01:58 +00:00
|
|
|
moreMatchesToFetch: state => state.infos.matchIndex < state.infos.matchList.length,
|
2019-10-22 20:59:22 +00:00
|
|
|
playing: state => state.infos.playing,
|
2019-09-11 20:02:05 +00:00
|
|
|
summonerFound: state => state.status === 'found',
|
|
|
|
|
summonerNotFound: state => state.status === 'error',
|
|
|
|
|
summonerLoading: state => state.status === 'loading',
|
|
|
|
|
}
|