From 464c67eb46b098eb1b89a3391b9dd23bb58664bd Mon Sep 17 00:00:00 2001 From: ayana Date: Wed, 11 Jun 2025 18:27:13 -0700 Subject: [PATCH] use different notation --- .../admin/Evaluations/Leaderboard.svelte | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/lib/components/admin/Evaluations/Leaderboard.svelte b/src/lib/components/admin/Evaluations/Leaderboard.svelte index d8407a574..de99a6752 100644 --- a/src/lib/components/admin/Evaluations/Leaderboard.svelte +++ b/src/lib/components/admin/Evaluations/Leaderboard.svelte @@ -281,6 +281,28 @@ onMount(async () => { rankHandler(); }); + + $: sortedModels = [...rankedModels].sort((a, b) => { + let aVal, bVal; + if (orderBy === 'name') { + aVal = a.name; + bVal = b.name; + return direction === 'asc' ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal); + } else if (orderBy === 'rating') { + aVal = a.rating === '-' ? -Infinity : a.rating; + bVal = b.rating === '-' ? -Infinity : b.rating; + return direction === 'asc' ? aVal - bVal : bVal - aVal; + } else if (orderBy === 'won') { + aVal = a.stats.won === '-' ? -Infinity : Number(a.stats.won); + bVal = b.stats.won === '-' ? -Infinity : Number(b.stats.won); + return direction === 'asc' ? aVal - bVal : bVal - aVal; + } else if (orderBy === 'lost') { + aVal = a.stats.lost === '-' ? -Infinity : Number(a.stats.lost); + bVal = b.stats.lost === '-' ? -Infinity : Number(b.stats.lost); + return direction === 'asc' ? aVal - bVal : bVal - aVal; + } + return 0; + });
@@ -452,27 +474,7 @@ - {#each [...rankedModels].sort((a, b) => { - let aVal, bVal; - if (orderBy === 'name') { - aVal = a.name; - bVal = b.name; - return direction === 'asc' ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal); - } else if (orderBy === 'rating') { - aVal = a.rating === '-' ? -Infinity : a.rating; - bVal = b.rating === '-' ? -Infinity : b.rating; - return direction === 'asc' ? aVal - bVal : bVal - aVal; - } else if (orderBy === 'won') { - aVal = a.stats.won === '-' ? -Infinity : Number(a.stats.won); - bVal = b.stats.won === '-' ? -Infinity : Number(b.stats.won); - return direction === 'asc' ? aVal - bVal : bVal - aVal; - } else if (orderBy === 'lost') { - aVal = a.stats.lost === '-' ? -Infinity : Number(a.stats.lost); - bVal = b.stats.lost === '-' ? -Infinity : Number(b.stats.lost); - return direction === 'asc' ? aVal - bVal : bVal - aVal; - } - return 0; - }) as model, modelIdx (model.id)} + {#each sortedModels as model, modelIdx (model.id)}