« get me outta code hell

sort: sortContributionsChronologically - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-07 12:22:29 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-12 17:26:42 -0300
commit0514493b06978ddcede0a3582b25e5c93d3f7477 (patch)
tree3067110b93e02c686d4d2443c846bd44b4326a38
parente98ddceb95d89e5e6541f15543fa4ffa6f04c29f (diff)
sort: sortContributionsChronologically
-rw-r--r--src/util/sort.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util/sort.js b/src/util/sort.js
index 9e9de641..8a096dc1 100644
--- a/src/util/sort.js
+++ b/src/util/sort.js
@@ -404,3 +404,30 @@ export function sortFlashesChronologically(data, {
 
   return data;
 }
+
+export function sortContributionsChronologically(data, sortThings, {
+  latestFirst = false,
+} = {}) {
+  // Contributions only have one date property (which is provided when
+  // the contribution is created). They're sorted by this most primarily,
+  // but otherwise use the same sort as is provided.
+
+  const entries =
+    data.map(contrib => ({
+      entry: contrib,
+      thing: contrib.thing,
+    }));
+
+  sortEntryThingPairs(
+    entries,
+    things =>
+      sortThings(things, {latestFirst}));
+
+  const contribs =
+    entries
+      .map(({entry: contrib}) => contrib);
+
+  sortByDate(contribs, {latestFirst});
+
+  return contribs;
+}