« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-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;
+}