« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common-util/wiki-data.js5
-rw-r--r--src/data/things/track.js43
-rw-r--r--src/search-select.js22
3 files changed, 37 insertions, 33 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js
index 04857cfb..42bbc939 100644
--- a/src/common-util/wiki-data.js
+++ b/src/common-util/wiki-data.js
@@ -59,6 +59,11 @@ export function getKebabCase(name) {
   return getCaseSensitiveKebabCase(name).toLowerCase();
 }
 
+export function compareKebabCase(name1, name2) {
+  if (!name1 || !name2) return false;
+  return getKebabCase(name1) === getKebabCase(name2);
+}
+
 // Specific data utilities
 
 // Matches heading details from commentary data in roughly the format:
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 298cd6cf..f77cfa41 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -6,7 +6,7 @@ import {input, V} from '#composite';
 import {onlyItem} from '#sugar';
 import {sortByDate} from '#sort';
 import Thing from '#thing';
-import {getKebabCase} from '#wiki-data';
+import {compareKebabCase} from '#wiki-data';
 
 import {
   isBoolean,
@@ -169,8 +169,7 @@ export class Track extends Thing {
           ['name']: name,
           ['#mainReleaseTrack.name']: mainReleaseName,
         }) =>
-          getKebabCase(name) ===
-          getKebabCase(mainReleaseName),
+          compareKebabCase(name, mainReleaseName),
       },
     ],
 
@@ -675,27 +674,23 @@ export class Track extends Thing {
         compute: (continuation, {
           ['name']: ownName,
           ['_directory']: ownDirectory,
-        }) => {
-          const ownNameKebabed = getKebabCase(ownName);
-
-          return continuation({
-            ['#mapItsNameLikeName']:
-              name => getKebabCase(name) === ownNameKebabed,
-
-            ['#mapItsDirectoryLikeDirectory']:
-              (ownDirectory
-                ? directory => directory === ownDirectory
-                : () => false),
-
-            ['#mapItsNameLikeDirectory']:
-              (ownDirectory
-                ? name => getKebabCase(name) === ownDirectory
-                : () => false),
-
-            ['#mapItsDirectoryLikeName']:
-              directory => directory === ownNameKebabed,
-          });
-        },
+        }) => continuation({
+          ['#mapItsNameLikeName']:
+            itsName => compareKebabCase(itsName, ownName),
+
+          ['#mapItsDirectoryLikeDirectory']:
+            (ownDirectory
+              ? itsDirectory => itsDirectory === ownDirectory
+              : () => false),
+
+          ['#mapItsNameLikeDirectory']:
+            (ownDirectory
+              ? itsName => compareKebabCase(itsName, ownDirectory)
+              : () => false),
+
+          ['#mapItsDirectoryLikeName']:
+            itsDirectory => compareKebabCase(itsDirectory, ownName),
+        }),
       },
 
       withPropertyFromObject('mainRelease', V('tracks')),
diff --git a/src/search-select.js b/src/search-select.js
index 36b9e98a..fcc1e7d6 100644
--- a/src/search-select.js
+++ b/src/search-select.js
@@ -4,7 +4,7 @@
 
 import baseSearchSpec from '#search-shape';
 import {unique} from '#sugar';
-import {getKebabCase} from '#wiki-data';
+import {compareKebabCase} from '#wiki-data';
 
 function prepareArtwork(artwork, thing, {
   checkIfImagePathHasCachedThumbnails,
@@ -67,14 +67,17 @@ function determineArtistGroups(artist, opts) {
     new Map(
       unique(contributionGroups).map(group => [group, 0]));
 
-  const artistNamesish =
-    unique(
-      [artist.name, ...artist.artistAliases.map(alias => alias.name)]
-        .map(name => getKebabCase(name)));
+  const artistNames =
+    [artist, ...artist.artistAliases]
+      .map(({name}) => name);
 
+  group:
   for (const group of scores.keys()) {
-    if (artistNamesish.includes(getKebabCase(group.name))) {
-      scores.delete(group);
+    for (const artistName of artistNames) {
+      if (compareKebabCase(group.name, artistName)) {
+        scores.delete(group);
+        continue group;
+      }
     }
   }
 
@@ -161,8 +164,9 @@ function genericSelect(wikiData) {
       wikiData.trackData
         .filter(track =>
           track.isMainRelease ||
-          (getKebabCase(track.name) !==
-           getKebabCase(track.mainReleaseTrack.name)))),
+          !compareKebabCase(
+            track.name,
+            track.mainReleaseTrack.name))),
   ].flat();
 }