mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: add button to load 10 more matches
This commit is contained in:
parent
02e4cb87dd
commit
e09c7d59b5
8 changed files with 102 additions and 49 deletions
|
|
@ -41,11 +41,11 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-1 flex flex-row sm:flex-col sm:justify-around">
|
<div class="ml-1 flex flex-row sm:flex-col sm:justify-around">
|
||||||
<div
|
<div
|
||||||
:style="{background: `url(${data.primaryRune}) center/cover`}"
|
:style="[data.primaryRune ? {background: `url(${data.primaryRune}) center/cover`} : '']"
|
||||||
class="w-6 h-6 bg-blue-1000 rounded-md"
|
class="w-6 h-6 bg-blue-1000 rounded-md"
|
||||||
></div>
|
></div>
|
||||||
<div
|
<div
|
||||||
:style="{background: `url(${data.secondaryRune}) center/cover`}"
|
:style="[data.secondaryRune ? {background: `url(${data.secondaryRune}) center/cover`} : '']"
|
||||||
class="w-6 h-6 bg-blue-1000 rounded-md"
|
class="w-6 h-6 bg-blue-1000 rounded-md"
|
||||||
></div>
|
></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="third w-1/3 py-1 flex items-center">
|
<div class="third w-1/3 py-1 flex items-center">
|
||||||
<div>
|
<div v-if="data.allyTeam.length > 1">
|
||||||
<div
|
<div
|
||||||
v-for="(ally, index) in data.allyTeam"
|
v-for="(ally, index) in data.allyTeam"
|
||||||
:key="'player-' + index"
|
:key="'player-' + index"
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,10 @@ import { maps, gameModes } from '@/data/data.js'
|
||||||
import summonersJSON from '@/data/summoner.json'
|
import summonersJSON from '@/data/summoner.json'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return all the infos about a summoner built with the Riot API data
|
* Return all the infos about a list of matches built with the Riot API data
|
||||||
* @param {Object} RiotData : all data from the Riot API
|
* @param {Object} RiotData : all data from the Riot API
|
||||||
* @param {Object} championsInfos : champions data from the Riot API
|
|
||||||
*/
|
*/
|
||||||
export function createSummonerData(RiotData) {
|
export function createMatchData(matches) {
|
||||||
console.log('--- ALL INFOS ---')
|
|
||||||
console.log(RiotData)
|
|
||||||
|
|
||||||
const userStats = RiotData.account
|
|
||||||
const soloQStats = RiotData.soloQ
|
|
||||||
const matches = RiotData.matchesDetails
|
|
||||||
|
|
||||||
const soloQ = soloQStats ? {} : null
|
|
||||||
if (soloQ) {
|
|
||||||
soloQ.rank = `${soloQStats.tier} ${soloQStats.rank}`
|
|
||||||
soloQ.rankImgLink = getRankImg(soloQStats)
|
|
||||||
soloQ.wins = soloQStats.wins
|
|
||||||
soloQ.losses = soloQStats.losses
|
|
||||||
soloQ.winrate = +(soloQ.wins * 100 / (soloQ.wins + soloQ.losses)).toFixed(1) + '%'
|
|
||||||
soloQ.lp = soloQStats.leaguePoints
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const match of matches) {
|
for (const match of matches) {
|
||||||
for (let i = 0; i < match.items.length; i++) {
|
for (let i = 0; i < match.items.length; i++) {
|
||||||
match.items[i] = getItemLink(match.items[i])
|
match.items[i] = getItemLink(match.items[i])
|
||||||
|
|
@ -40,14 +22,34 @@ export function createSummonerData(RiotData) {
|
||||||
if (!match.gamemode) match.gamemode = 'Undefined gamemode'
|
if (!match.gamemode) match.gamemode = 'Undefined gamemode'
|
||||||
} // end loop matches
|
} // end loop matches
|
||||||
|
|
||||||
|
return matches
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all the infos about a summoner built with the Riot API data
|
||||||
|
* @param {Object} RiotData : all data from the Riot API
|
||||||
|
*/
|
||||||
|
export function createSummonerData(RiotData) {
|
||||||
|
console.log('--- ALL INFOS ---')
|
||||||
|
console.log(RiotData)
|
||||||
|
|
||||||
|
// Ranked Stats
|
||||||
|
const soloQStats = RiotData.soloQ
|
||||||
|
const soloQ = soloQStats ? {} : null
|
||||||
|
if (soloQ) {
|
||||||
|
soloQ.rank = `${soloQStats.tier} ${soloQStats.rank}`
|
||||||
|
soloQ.rankImgLink = getRankImg(soloQStats)
|
||||||
|
soloQ.wins = soloQStats.wins
|
||||||
|
soloQ.losses = soloQStats.losses
|
||||||
|
soloQ.winrate = +(soloQ.wins * 100 / (soloQ.wins + soloQ.losses)).toFixed(1) + '%'
|
||||||
|
soloQ.lp = soloQStats.leaguePoints
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
accountId: userStats.accountId,
|
account: RiotData.account,
|
||||||
allMatches: RiotData.allMatches,
|
|
||||||
matches: RiotData.matchesDetails,
|
|
||||||
profileIconId: userStats.profileIconId,
|
|
||||||
name: userStats.name,
|
|
||||||
level: userStats.summonerLevel,
|
|
||||||
soloQ,
|
soloQ,
|
||||||
|
matchList: RiotData.allMatches,
|
||||||
|
matches: createMatchData(RiotData.matchesDetails)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,34 @@
|
||||||
import { axios } from '@/plugins/axios'
|
import { axios } from '@/plugins/axios'
|
||||||
import { createSummonerData } from '@/helpers/summoner'
|
import { createMatchData, createSummonerData } from '@/helpers/summoner'
|
||||||
|
|
||||||
export const namespaced = true
|
export const namespaced = true
|
||||||
|
|
||||||
export const state = {
|
export const state = {
|
||||||
infos: [],
|
infos: {
|
||||||
|
account: {},
|
||||||
|
matchIndex: 0,
|
||||||
|
matchList: [],
|
||||||
|
matches: [],
|
||||||
|
soloQ: {}
|
||||||
|
},
|
||||||
status: '',
|
status: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mutations = {
|
export const mutations = {
|
||||||
|
MATCHES_FOUND(state, newMatches) {
|
||||||
|
state.infos.matches = [...state.infos.matches, ...newMatches]
|
||||||
|
|
||||||
|
state.infos.matchIndex += newMatches.length
|
||||||
|
},
|
||||||
SUMMONER_REQUEST(state) {
|
SUMMONER_REQUEST(state) {
|
||||||
state.status = 'loading'
|
state.status = 'loading'
|
||||||
},
|
},
|
||||||
SUMMONER_FOUND(state, infos) {
|
SUMMONER_FOUND(state, infos) {
|
||||||
state.infos = infos
|
state.infos.account = infos.account
|
||||||
|
state.infos.matchList = infos.matchList
|
||||||
|
state.infos.matches = infos.matches
|
||||||
|
state.infos.soloQ = infos.soloQ
|
||||||
|
state.infos.matchIndex = infos.matches.length
|
||||||
state.status = 'found'
|
state.status = 'found'
|
||||||
},
|
},
|
||||||
SUMMONER_NOT_FOUND(state) {
|
SUMMONER_NOT_FOUND(state) {
|
||||||
|
|
@ -22,6 +37,13 @@ export const mutations = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
|
async moreMatches({ commit }) {
|
||||||
|
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(() => { })
|
||||||
|
commit('MATCHES_FOUND', createMatchData(resp.data))
|
||||||
|
},
|
||||||
async summonerRequest({ commit, dispatch, rootState }, { summoner, region }) {
|
async summonerRequest({ commit, dispatch, rootState }, { summoner, region }) {
|
||||||
region = rootState.regionsList[region]
|
region = rootState.regionsList[region]
|
||||||
commit('SUMMONER_REQUEST')
|
commit('SUMMONER_REQUEST')
|
||||||
|
|
@ -47,6 +69,7 @@ export const actions = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
|
moreMatchesToFetch: state => state.infos.matchIndex < state.infos.matchList.length,
|
||||||
summonerFound: state => state.status === 'found',
|
summonerFound: state => state.status === 'found',
|
||||||
summonerNotFound: state => state.status === 'error',
|
summonerNotFound: state => state.status === 'error',
|
||||||
summonerLoading: state => state.status === 'loading',
|
summonerLoading: state => state.status === 'loading',
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
<div class="flex justify-between xl:px-12">
|
<div class="flex justify-between xl:px-12">
|
||||||
<div>
|
<div>
|
||||||
<h1 class="text-4xl font-extrabold uppercase">
|
<h1 class="text-4xl font-extrabold uppercase">
|
||||||
<span class="text-5xl">{{ summonerInfos.name[0] }}</span>
|
<span class="text-5xl">{{ summonerInfos.account.name[0] }}</span>
|
||||||
<span>{{ summonerInfos.name.substring(1) }}</span>
|
<span>{{ summonerInfos.account.name.substring(1) }}</span>
|
||||||
</h1>
|
</h1>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -34,7 +34,7 @@
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="absolute left-0 bottom-0 w-8 h-8 flex items-center justify-center bg-blue-900 rounded-full text-xs text-teal-500 font-extrabold border-2 border-teal-400"
|
class="absolute left-0 bottom-0 w-8 h-8 flex items-center justify-center bg-blue-900 rounded-full text-xs text-teal-500 font-extrabold border-2 border-teal-400"
|
||||||
>{{ summonerInfos.level }}</div>
|
>{{ summonerInfos.account.summonerLevel }}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="summonerInfos.soloQ" class="ml-6 leading-none">
|
<div v-if="summonerInfos.soloQ" class="ml-6 leading-none">
|
||||||
|
|
@ -73,7 +73,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<RecentActivity :matches="summonerInfos.allMatches" />
|
<RecentActivity :matches="summonerInfos.matchList" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -86,6 +86,12 @@
|
||||||
/>
|
/>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
v-if="moreMatchesToFetch"
|
||||||
|
@click="moreMatches"
|
||||||
|
class="mt-4 block mx-auto bg-blue-800 px-4 py-2 rounded-md font-semibold hover:bg-blue-1000 shadow-lg"
|
||||||
|
>More matches</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -121,7 +127,7 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
getSummonerIcon() {
|
getSummonerIcon() {
|
||||||
return `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${this.summonerInfos.profileIconId}.png) center/cover`
|
return `url(https://ddragon.leagueoflegends.com/cdn/${this.$patch}/img/profileicon/${this.summonerInfos.account.profileIconId}.png) center/cover`
|
||||||
},
|
},
|
||||||
summoner() {
|
summoner() {
|
||||||
return this.$route.params.name
|
return this.$route.params.name
|
||||||
|
|
@ -132,7 +138,7 @@ export default {
|
||||||
...mapState({
|
...mapState({
|
||||||
summonerInfos: state => state.summoner.infos
|
summonerInfos: state => state.summoner.infos
|
||||||
}),
|
}),
|
||||||
...mapGetters('summoner', ['summonerFound', 'summonerNotFound', 'summonerLoading'])
|
...mapGetters('summoner', ['moreMatchesToFetch', 'summonerFound', 'summonerNotFound', 'summonerLoading'])
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
|
@ -153,7 +159,7 @@ export default {
|
||||||
redirect(summoner, region) {
|
redirect(summoner, region) {
|
||||||
this.$router.push(`/summoner/${region}/${summoner}`)
|
this.$router.push(`/summoner/${region}/${summoner}`)
|
||||||
},
|
},
|
||||||
...mapActions('summoner', ['summonerRequest'])
|
...mapActions('summoner', ['summonerRequest', 'moreMatches']),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
19
server/app/Controllers/Http/MatchController.js
Normal file
19
server/app/Controllers/Http/MatchController.js
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const MatchHelper = use('App/Helpers/MatchHelper')
|
||||||
|
|
||||||
|
class MatchController {
|
||||||
|
/**
|
||||||
|
* POST - Return data from matches searched by gameIds
|
||||||
|
*/
|
||||||
|
async index({ request, response }) {
|
||||||
|
console.log('More Matches Request')
|
||||||
|
const account = request.input('account')
|
||||||
|
const gameIds = request.input('gameIds')
|
||||||
|
|
||||||
|
const result = await MatchHelper.getMatches(account, gameIds)
|
||||||
|
return response.json(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = MatchController
|
||||||
|
|
@ -4,7 +4,6 @@ const Jax = use('Jax')
|
||||||
const MatchHelper = use('App/Helpers/MatchHelper')
|
const MatchHelper = use('App/Helpers/MatchHelper')
|
||||||
|
|
||||||
class SummonerController {
|
class SummonerController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST Endpoint : get summoner data
|
* POST Endpoint : get summoner data
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -55,17 +55,20 @@ class MatchTransformer extends BumblebeeTransformer {
|
||||||
}, 0)
|
}, 0)
|
||||||
const kp = +((kills + assists) * 100 / totalKills).toFixed(1) + '%'
|
const kp = +((kills + assists) * 100 / totalKills).toFixed(1) + '%'
|
||||||
|
|
||||||
const primaryRuneCategory = runes.find(r => r.id === player.stats.perkPrimaryStyle)
|
let primaryRune = null
|
||||||
let primaryRune
|
let secondaryRune = null
|
||||||
for (const subCat of primaryRuneCategory.slots) {
|
if(player.stats.perkPrimaryStyle) {
|
||||||
primaryRune = subCat.runes.find(r => r.id === player.stats.perk0)
|
const primaryRuneCategory = runes.find(r => r.id === player.stats.perkPrimaryStyle)
|
||||||
if (primaryRune) {
|
for (const subCat of primaryRuneCategory.slots) {
|
||||||
break
|
primaryRune = subCat.runes.find(r => r.id === player.stats.perk0)
|
||||||
|
if (primaryRune) {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
primaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${primaryRune.icon}`
|
||||||
|
secondaryRune = runes.find(r => r.id === player.stats.perkSubStyle)
|
||||||
|
secondaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${secondaryRune.icon}`
|
||||||
}
|
}
|
||||||
primaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${primaryRune.icon}`
|
|
||||||
let secondaryRune = runes.find(r => r.id === player.stats.perkSubStyle)
|
|
||||||
secondaryRune = `https://ddragon.leagueoflegends.com/cdn/img/${secondaryRune.icon}`
|
|
||||||
|
|
||||||
const items = []
|
const items = []
|
||||||
for (let i = 0; i < 6; i++) {
|
for (let i = 0; i < 6; i++) {
|
||||||
|
|
|
||||||
|
|
@ -27,3 +27,4 @@ Route.get('/', async () => {
|
||||||
|
|
||||||
Route.post('/api', 'SummonerController.api')
|
Route.post('/api', 'SummonerController.api')
|
||||||
Route.post('/ddragon', 'DDragonController.index')
|
Route.post('/ddragon', 'DDragonController.index')
|
||||||
|
Route.post('/match', 'MatchController.index')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue