fix(champions): remove strange bahviors after sorting multiple times

This commit is contained in:
Valentin Kaelin 2022-01-08 02:09:39 +01:00
parent 3d4c969ea0
commit ec6319ec3b

View file

@ -234,11 +234,8 @@ export default {
champions() {
this.updateChampionsList()
},
onlyMostPlayed() {
// Re-apply the current sorting
this.order *= -1
this.sortBy(this.sortProps)
championsToDisplay() {
this.reApplySorts()
}
},
@ -270,18 +267,27 @@ export default {
}
this.championsToDisplay.sort((a, b) => {
const aProp = props.split('.').reduce((p, c) => p && p[c] || null, a)
const bProp = props.split('.').reduce((p, c) => p && p[c] || null, b)
let order = aProp > bProp ? this.order : this.order * -1
const aProp = props.split('.').reduce((p, c) => p && p[c], a)
const bProp = props.split('.').reduce((p, c) => p && p[c], b)
let order = typeof aProp === 'string' ? aProp.localeCompare(bProp) : aProp - bProp
if (this.order == -1)
order *= -1
// Revert order for rank and champion name
if (props === 'index' || props === 'champion.name') {
order *= -1
}
return order
// Second sort by champion name
return order || a.champion.name.localeCompare(b.champion.name)
})
this.sortProps = props
},
reApplySorts() {
this.order *= -1
this.sortBy(this.sortProps)
},
sortedClasses(props) {
return {
'sorted': this.sortProps === props,