« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/wiki-data.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js
index 0eb86a1e..5a0e241a 100644
--- a/src/util/wiki-data.js
+++ b/src/util/wiki-data.js
@@ -316,6 +316,7 @@ export function sortChronologically(data, {
 //
 // This function also works for data lists which contain only tracks.
 export function sortAlbumsTracksChronologically(data, {
+  latestFirst = false,
   getDate,
 } = {}) {
   // Sort albums before tracks...
@@ -333,7 +334,18 @@ export function sortAlbumsTracksChronologically(data, {
   // released on the same date, they'll still be grouped together by album,
   // and tracks within an album will retain their relative positioning (i.e.
   // stay in the same order as part of the album's track listing).
-  sortByDate(data, {getDate});
+
+  if (latestFirst) {
+    // Like in sortChronologically, double reverse: Since we reverse after
+    // sorting by date, also reverse before, so that items with the same date
+    // are flipped relative to each other twice - that maintains the original
+    // relative ordering!
+    data.reverse();
+    sortByDate(data, {getDate});
+    data.reverse();
+  } else {
+    sortByDate(data, {getDate});
+  }
 
   return data;
 }