2019-09-08 20:08:49 +00:00
|
|
|
import { axios } from '@/plugins/axios'
|
2019-09-09 18:42:10 +00:00
|
|
|
import { createSummonerData } from '@/helpers/summoner'
|
2019-09-08 20:08:49 +00:00
|
|
|
|
|
|
|
|
export const namespaced = true
|
|
|
|
|
|
|
|
|
|
export const state = {
|
|
|
|
|
infos: [],
|
|
|
|
|
loading: false,
|
|
|
|
|
summonerFound: false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
|
SUMMONER_REQUEST(state) {
|
|
|
|
|
state.loading = true
|
|
|
|
|
},
|
|
|
|
|
SUMMONER_FOUND(state, infos) {
|
|
|
|
|
state.summonerFound = true
|
|
|
|
|
state.loading = false
|
|
|
|
|
state.infos = infos
|
|
|
|
|
},
|
|
|
|
|
SUMMONER_NOT_FOUND(state) {
|
|
|
|
|
state.summonerFound = false
|
|
|
|
|
state.loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
|
async summonerRequest({ commit, dispatch, rootState }, { summoner, region }) {
|
|
|
|
|
console.log(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-09-09 18:42:10 +00:00
|
|
|
const infos = createSummonerData(resp.data, rootState.ddragon.champions)
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|