From ec6319ec3b5a5696193e913f78093119b61ca232 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Sat, 8 Jan 2022 02:09:39 +0100 Subject: [PATCH] fix(champions): remove strange bahviors after sorting multiple times --- .../Summoner/Champions/ChampionsTable.vue | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/client/src/components/Summoner/Champions/ChampionsTable.vue b/client/src/components/Summoner/Champions/ChampionsTable.vue index 7ce06ea..fea7307 100644 --- a/client/src/components/Summoner/Champions/ChampionsTable.vue +++ b/client/src/components/Summoner/Champions/ChampionsTable.vue @@ -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,