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