From dd4e642b381f1af8f235a1eff4eb886b12be31ad Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 27 Nov 2022 01:04:37 -0400 Subject: integrate "latest first" into sortChronologically --- src/listing-spec.js | 19 +++---------------- src/util/wiki-data.js | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/listing-spec.js b/src/listing-spec.js index 2e129ff..1bdc4db 100644 --- a/src/listing-spec.js +++ b/src/listing-spec.js @@ -300,7 +300,7 @@ const listingSpec = [ break; } - return sortChronologically(artistEntries).reverse(); + return sortChronologically(artistEntries, {latestFirst: true}); }; // Tracks are super easy to sort because they only have one pertinent @@ -555,21 +555,8 @@ const listingSpec = [ date: albums[albums.length - 1].date, }; }) - .filter(Boolean) - // So this is kinda tough to explain, 8ut 8asically, when we - // reverse the list after sorting it 8y d8te (so that the latest - // d8tes come first), it also flips the order of groups which - // share the same d8te. This happens mostly when a single al8um - // is the l8test in two groups. So, say one such al8um is in the - // groups "Fandom" and "UMSPAF". Per category order, Fandom is - // meant to show up 8efore UMSPAF, 8ut when we do the reverse - // l8ter, that flips them, and UMSPAF ends up displaying 8efore - // Fandom. So we do an extra reverse here, which will fix that - // and only affect groups that share the same d8te (8ecause - // groups that don't will 8e moved 8y the sortChronologically - // call surrounding this). - .reverse() - ).reverse(), + .filter(Boolean), + {latestFirst: true}), row: ({group, date}, {language, link}) => language.$('listingPage.listGroups.byLatest.item', { diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 8fb62db..f0812a0 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -287,12 +287,23 @@ export function sortAlphabetically(data, { // * name (or override getName) // * date (or override getDate) export function sortChronologically(data, { + latestFirst = false, getDirectory, getName, getDate, } = {}) { - sortAlphabetically(data, {getDirectory, getName}); - sortByDate(data, {getDate}); + if (latestFirst) { + // Double reverse: Since we reverse after sorting by date, also reverse + // after sorting A-Z, so the second reverse restores A-Z relative + // positioning (for entries with the same date). + sortAlphabetically(data, {getDirectory, getName}); + data.reverse(); + sortByDate(data, {getDate}); + data.reverse(); + } else { + sortAlphabetically(data, {getDirectory, getName}); + sortByDate(data, {getDate}); + } return data; } -- cgit 1.3.0-6-gf8a5