From 27ce0b5eb707a8e1ccdd700f1d869e1be142bdf4 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:18:50 +0300 Subject: [PATCH] Stabilize WI sorting order --- public/scripts/world-info.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/public/scripts/world-info.js b/public/scripts/world-info.js index c187c3c45..13081c02f 100644 --- a/public/scripts/world-info.js +++ b/public/scripts/world-info.js @@ -256,7 +256,7 @@ function sortEntries(data) { return (aValue - bValue || b.order - a.order); }); } else { - data.sort((a, b) => { + const primarySort = (a, b) => { const aValue = a[sortField]; const bValue = b[sortField]; @@ -273,6 +273,24 @@ function sortEntries(data) { // Sort numbers return orderSign * (Number(aValue) - Number(bValue)); + }; + const secondarySort = (a, b) => b.order - a.order; + const tertiarySort = (a, b) => a.uid - b.uid; + + data.sort((a, b) => { + const primary = primarySort(a, b); + + if (primary !== 0) { + return primary; + } + + const secondary = secondarySort(a, b); + + if (secondary !== 0) { + return secondary; + } + + return tertiarySort(a, b); }); }