« get me outta code hell

content: listArtistsByLatestContribution: show dateless artists - 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>2023-07-05 18:52:08 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-07-05 18:52:08 -0300
commit5625d4eed0e86fa0ac4a8bbc28cdac447d87c3d3 (patch)
tree5aa3664ac8c52de3f33349d85dcfce0760e6df39
parent6d191b557acfb348d768a40cd4adb06b21e18c19 (diff)
content: listArtistsByLatestContribution: show dateless artists
-rw-r--r--src/content/dependencies/listArtistsByLatestContribution.js103
-rw-r--r--src/strings-default.json2
2 files changed, 75 insertions, 30 deletions
diff --git a/src/content/dependencies/listArtistsByLatestContribution.js b/src/content/dependencies/listArtistsByLatestContribution.js
index c0135dca..3ebb084d 100644
--- a/src/content/dependencies/listArtistsByLatestContribution.js
+++ b/src/content/dependencies/listArtistsByLatestContribution.js
@@ -1,4 +1,5 @@
-import {stitchArrays} from '../../util/sugar.js';
+import {empty, stitchArrays} from '../../util/sugar.js';
+
 import {
   compareDates,
   filterMultipleArrays,
@@ -26,8 +27,24 @@ export default {
 
     const queryContributionInfo = (artistsKey, datesKey, datelessArtistsKey, fn) => {
       const artists = sortAlphabetically(sprawl.artistData.slice());
-      const dates = artists.map(artist => fn(artist));
 
+      // Each value stored in this list, corresponding to each artist,
+      // is going to be a list of dates and nulls. Any nulls represent
+      // a contribution which isn't associated with a particular date.
+      const dateLists = artists.map(artist => fn(artist));
+
+      // Scrap artists who don't even have any relevant contributions.
+      // These artists may still have other contributions across the wiki, but
+      // they weren't returned by the callback and so aren't relevant to this
+      // list.
+      filterMultipleArrays(artists, dateLists, (artist, dates) => !empty(dates));
+
+      const dates = dateLists.map(dates => getLatestDate(dates));
+
+      // Also exclude artists whose remaining contributions are all dateless -
+      // in this case getLatestDate above will have returned null. But keep
+      // track of the artists removed here, since they'll be displayed in an
+      // additional list in the final listing page.
       const {removed: [datelessArtists]} =
         filterMultipleArrays(artists, dates, (artist, date) => date);
 
@@ -44,34 +61,31 @@ export default {
       'artistsByTrackContributions',
       'datesByTrackContributions',
       'datelessArtistsByTrackContributions',
-      artist =>
-        getLatestDate([
-          ...artist.tracksAsContributor.map(track => +track.date),
-          ...artist.tracksAsArtist.map(track => +track.date),
-        ]));
+      artist => [
+        ...artist.tracksAsContributor.map(track => +track.date),
+        ...artist.tracksAsArtist.map(track => +track.date),
+      ]);
 
     queryContributionInfo(
       'artistsByArtworkContributions',
       'datesByArtworkContributions',
       'datelessArtistsByArtworkContributions',
-      artist =>
-        getLatestDate([
-          // TODO: Per-artwork dates, see #90.
-          ...artist.tracksAsCoverArtist.map(track => +track.coverArtDate),
-          ...artist.albumsAsCoverArtist.map(album => +album.coverArtDate),
-          ...artist.albumsAsWallpaperArtist.map(album => +album.coverArtDate),
-          ...artist.albumsAsBannerArtist.map(album => +album.coverArtDate),
-        ]));
+      artist => [
+        // TODO: Per-artwork dates, see #90.
+        ...artist.tracksAsCoverArtist.map(track => +track.coverArtDate),
+        ...artist.albumsAsCoverArtist.map(album => +album.coverArtDate),
+        ...artist.albumsAsWallpaperArtist.map(album => +album.coverArtDate),
+        ...artist.albumsAsBannerArtist.map(album => +album.coverArtDate),
+      ]);
 
     if (sprawl.enableFlashesAndGames) {
       queryContributionInfo(
         'artistsByFlashContributions',
         'datesByFlashContributions',
         'datelessArtistsByFlashContributions',
-        artist =>
-          getLatestDate([
-            ...artist.flashesAsContributor.map(flash => +flash.date),
-          ]));
+        artist => [
+          ...artist.flashesAsContributor.map(flash => +flash.date),
+        ]);
     }
 
     return query;
@@ -87,14 +101,26 @@ export default {
       query.artistsByTrackContributions
         .map(artist => relation('linkArtist', artist));
 
+    relations.datelessArtistLinksByTrackContributions =
+      query.datelessArtistsByTrackContributions
+        .map(artist => relation('linkArtist', artist));
+
     relations.artistLinksByArtworkContributions =
       query.artistsByArtworkContributions
         .map(artist => relation('linkArtist', artist));
 
+    relations.datelessArtistLinksByArtworkContributions =
+      query.datelessArtistsByArtworkContributions
+        .map(artist => relation('linkArtist', artist));
+
     if (query.enableFlashesAndGames) {
       relations.artistLinksByFlashContributions =
         query.artistsByFlashContributions
           .map(artist => relation('linkArtist', artist));
+
+      relations.datelessArtistLinksByFlashContributions =
+        query.datelessArtistsByFlashContributions
+          .map(artist => relation('linkArtist', artist));
     }
 
     return relations;
@@ -120,32 +146,49 @@ export default {
       ([
         ['tracks', [
           relations.artistLinksByTrackContributions,
+          relations.datelessArtistLinksByTrackContributions,
           data.datesByTrackContributions,
         ]],
 
         ['artworks', [
           relations.artistLinksByArtworkContributions,
+          relations.datelessArtistLinksByArtworkContributions,
           data.datesByArtworkContributions,
         ]],
 
         data.enableFlashesAndGames &&
           ['flashes', [
             relations.artistLinksByFlashContributions,
+            relations.datelessArtistLinksByFlashContributions,
             data.datesByFlashContributions,
           ]],
       ]).filter(Boolean)
-        .map(([key, [artistLinks, dates]]) => [
+        .map(([key, [artistLinks, datelessArtistLinks, dates]]) => [
           key,
-          html.tag('ul',
-            stitchArrays({
-              artistLink: artistLinks,
-              date: dates,
-            }).map(({artistLink, date}) =>
-                html.tag('li',
-                  language.$('listingPage.listArtists.byLatest.item', {
-                    artist: artistLink,
-                    date: language.formatDate(date),
-                  })))),
+          html.tags([
+            html.tag('ul',
+              stitchArrays({
+                artistLink: artistLinks,
+                date: dates,
+              }).map(({artistLink, date}) =>
+                  html.tag('li',
+                    language.$('listingPage.listArtists.byLatest.item', {
+                      artist: artistLink,
+                      date: language.formatDate(date),
+                    })))),
+
+            !empty(datelessArtistLinks) && [
+              html.tag('p',
+                language.$('listingPage.listArtists.byLatest.dateless.title')),
+
+              html.tag('ul',
+                datelessArtistLinks.map(artistLink =>
+                  html.tag('li',
+                    language.$('listingPage.listArtists.byLatest.dateless.item', {
+                      artist: artistLink,
+                    })))),
+            ],
+          ]),
         ]));
 
     return relations.page.slots({
diff --git a/src/strings-default.json b/src/strings-default.json
index 724bc78b..0938af85 100644
--- a/src/strings-default.json
+++ b/src/strings-default.json
@@ -376,6 +376,8 @@
   "listingPage.listArtists.byLatest.title": "Artists - by Latest Contribution",
   "listingPage.listArtists.byLatest.title.short": "...by Latest Contribution",
   "listingPage.listArtists.byLatest.item": "{ARTIST} ({DATE})",
+  "listingPage.listArtists.byLatest.dateless.title": "These artists' contributions aren't dated:",
+  "listingPage.listArtists.byLatest.dateless.item": "{ARTIST}",
   "listingPage.listGroups.byName.title": "Groups - by Name",
   "listingPage.listGroups.byName.title.short": "...by Name",
   "listingPage.listGroups.byName.item": "{GROUP} ({GALLERY})",