« 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/content/dependencies/generateFlashActNavAccent.js32
-rw-r--r--src/content/dependencies/generateFlashNavAccent.js34
-rw-r--r--src/data/things/flash/Flash.js31
-rw-r--r--src/data/things/flash/FlashAct.js108
-rw-r--r--src/data/things/flash/FlashSide.js2
-rw-r--r--src/data/yaml.js2
6 files changed, 151 insertions, 58 deletions
diff --git a/src/content/dependencies/generateFlashActNavAccent.js b/src/content/dependencies/generateFlashActNavAccent.js
index 7ad46051..035f852a 100644
--- a/src/content/dependencies/generateFlashActNavAccent.js
+++ b/src/content/dependencies/generateFlashActNavAccent.js
@@ -1,27 +1,5 @@
-import {atOffset} from '#sugar';
-
 export default {
-  sprawl: ({flashActData}) =>
-    ({flashActData}),
-
-  query(sprawl, flashAct) {
-    // Like with generateFlashNavAccent, don't sort chronologically here.
-    const flashActs =
-      sprawl.flashActData;
-
-    const index =
-      flashActs.indexOf(flashAct);
-
-    const previousFlashAct =
-      atOffset(flashActs, index, -1);
-
-    const nextFlashAct =
-      atOffset(flashActs, index, +1);
-
-    return {previousFlashAct, nextFlashAct};
-  },
-
-  relations: (relation, query) => ({
+  relations: (relation, flashAct) => ({
     switcher:
       relation('generateInterpageDotSwitcher'),
 
@@ -32,13 +10,13 @@ export default {
       relation('generateNextLink'),
 
     previousFlashActLink:
-      (query.previousFlashAct
-        ? relation('linkFlashAct', query.previousFlashAct)
+      (flashAct.previousAct
+        ? relation('linkFlashAct', flashAct.previousAct)
         : null),
 
     nextFlashActLink:
-      (query.nextFlashAct
-        ? relation('linkFlashAct', query.nextFlashAct)
+      (flashAct.nextAct
+        ? relation('linkFlashAct', flashAct.nextAct)
         : null),
   }),
 
diff --git a/src/content/dependencies/generateFlashNavAccent.js b/src/content/dependencies/generateFlashNavAccent.js
index db9d3c1e..e93d763c 100644
--- a/src/content/dependencies/generateFlashNavAccent.js
+++ b/src/content/dependencies/generateFlashNavAccent.js
@@ -1,29 +1,5 @@
-import {atOffset} from '#sugar';
-
 export default {
-  sprawl: ({flashActData}) =>
-    ({flashActData}),
-
-  query(sprawl, flash) {
-    // Don't sort chronologically here. The previous/next buttons should match
-    // the order in the sidebar, by act rather than date.
-    const flashes =
-      sprawl.flashActData
-        .flatMap(act => act.flashes);
-
-    const index =
-      flashes.indexOf(flash);
-
-    const previousFlash =
-      atOffset(flashes, index, -1);
-
-    const nextFlash =
-      atOffset(flashes, index, +1);
-
-    return {previousFlash, nextFlash};
-  },
-
-  relations: (relation, query) => ({
+  relations: (relation, flash) => ({
     switcher:
       relation('generateInterpageDotSwitcher'),
 
@@ -34,13 +10,13 @@ export default {
       relation('generateNextLink'),
 
     previousFlashLink:
-      (query.previousFlash
-        ? relation('linkFlash', query.previousFlash)
+      (flash.previousFlash
+        ? relation('linkFlash', flash.previousFlash)
         : null),
 
     nextFlashLink:
-      (query.nextFlash
-        ? relation('linkFlash', query.nextFlash)
+      (flash.nextFlash
+        ? relation('linkFlash', flash.nextFlash)
         : null),
   }),
 
diff --git a/src/data/things/flash/Flash.js b/src/data/things/flash/Flash.js
index 1f290b3f..b06b0452 100644
--- a/src/data/things/flash/Flash.js
+++ b/src/data/things/flash/Flash.js
@@ -1,4 +1,5 @@
 import {input, V} from '#composite';
+import {atOffset} from '#sugar';
 import Thing from '#thing';
 import {anyOf, isColor, isDirectory, isNumber, isString}
   from '#validators';
@@ -138,6 +139,36 @@ export class Flash extends Thing {
       withPropertyFromObject('act', V('side')),
       exposeDependency('#act.side'),
     ],
+
+    previousFlash: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['this', 'act', 'side'],
+        compute: ({this: flash, act, side}) =>
+          (flash !== act.flashes.at(0)
+            ? atOffset(act.flashes, act.flashes.indexOf(flash), -1)
+         : side.isolateActs
+            ? null
+         : act.previousAct
+            ? act.previousAct.flashes.at(-1)
+            : null),
+      },
+    },
+
+    nextFlash: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['this', 'act', 'side'],
+        compute: ({this: flash, act, side}) =>
+          (flash !== act.flashes.at(-1)
+            ? atOffset(act.flashes, act.flashes.indexOf(flash), +1)
+         : side.isolateActs
+            ? null
+         : act.nextAct
+            ? act.nextAct.flashes.at(0)
+            : null),
+      },
+    },
   });
 
   static [Thing.getSerializeDescriptors] = ({
diff --git a/src/data/things/flash/FlashAct.js b/src/data/things/flash/FlashAct.js
index 19412fdc..5d243241 100644
--- a/src/data/things/flash/FlashAct.js
+++ b/src/data/things/flash/FlashAct.js
@@ -1,4 +1,5 @@
 import {input, V} from '#composite';
+import {atOffset} from '#sugar';
 import Thing from '#thing';
 import {isColor, isContentString, isString} from '#validators';
 
@@ -19,7 +20,8 @@ import {
   soupyFind,
   soupyReverse,
   thing,
-  thingList
+  thingList,
+  wikiData,
 } from '#composite/wiki-properties';
 
 export class FlashAct extends Thing {
@@ -85,9 +87,113 @@ export class FlashAct extends Thing {
     find: soupyFind(),
     reverse: soupyReverse(),
 
+    // used for nearbyActs
+    flashActData: wikiData(V(FlashAct)),
+
     // Expose only
 
     isFlashAct: exposeConstant(V(true)),
+
+    previousAct: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['this', 'side', '_flashActData'],
+        compute({
+          ['this']: thisFlashAct,
+          ['side']: ownSide,
+          ['_flashActData']: flashActData,
+        }) {
+          const indexIn = array => array.indexOf(thisFlashAct);
+          const isFirstIn = array => indexIn(array) === 0;
+          const previousIn = array => atOffset(array, indexIn(array), -1);
+
+          if (isFirstIn(flashActData)) {
+            return null;
+          }
+
+          if (isFirstIn(ownSide.acts)) {
+            if (ownSide.isolateActs) {
+              return null;
+            } else {
+              const lastInPreviousSide = previousIn(flashActData);
+              if (lastInPreviousSide.side.isolateActs) {
+                return null;
+              } else {
+                return lastInPreviousSide;
+              }
+            }
+          }
+
+          return previousIn(ownSide.acts);
+        },
+      },
+    },
+
+    nextAct: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['this', 'side', '_flashActData'],
+        compute({
+          ['this']: thisFlashAct,
+          ['side']: ownSide,
+          ['_flashActData']: flashActData,
+        }) {
+          const indexIn = array => array.indexOf(thisFlashAct);
+          const isLastIn = array => indexIn(array) === array.length - 1;
+          const nextIn = array => atOffset(array, indexIn(array), +1);
+
+          if (isLastIn(flashActData)) {
+            return null;
+          }
+
+          if (isLastIn(ownSide.acts)) {
+            if (ownSide.isolateActs) {
+              return null;
+            } else {
+              const firstInNextSide = nextIn(flashActData);
+              if (firstInNextSide.side.isolateActs) {
+                return null;
+              } else {
+                return firstInNextSide;
+              }
+            }
+          }
+
+          return nextIn(ownSide.acts);
+        },
+      },
+    },
+
+    previousActs: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['previousAct'],
+        compute: ({previousAct}) =>
+          (previousAct
+            ? [...previousAct.previousActs, previousAct]
+            : []),
+      },
+    },
+
+    nextActs: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['nextAct'],
+        compute: ({nextAct}) =>
+          (nextAct
+            ? [nextAct, ...nextAct.nextActs]
+            : []),
+      },
+    },
+
+    nearbyActs: {
+      flags: {expose: true},
+      expose: {
+        dependencies: ['previousActs', 'nextActs', 'this'],
+        compute: ({previousActs, nextActs, this: thisAct}) =>
+          [...previousActs, thisAct, ...nextActs],
+      },
+    },
   });
 
   static [Thing.findSpecs] = {
diff --git a/src/data/things/flash/FlashSide.js b/src/data/things/flash/FlashSide.js
index 391e2ae1..cbd6fc25 100644
--- a/src/data/things/flash/FlashSide.js
+++ b/src/data/things/flash/FlashSide.js
@@ -19,6 +19,7 @@ export class FlashSide extends Thing {
     listTerminology: contentString(),
 
     splitAbove: flag(V(false)),
+    isolateActs: flag(V(false)),
 
     acts: thingList(V(FlashAct)),
 
@@ -39,6 +40,7 @@ export class FlashSide extends Thing {
       'List Terminology': {property: 'listTerminology'},
 
       'Split Above': {property: 'splitAbove'},
+      'Isolate Acts': {property: 'isolateActs'},
     },
   };
 
diff --git a/src/data/yaml.js b/src/data/yaml.js
index 0519986b..e5a15d30 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1814,7 +1814,7 @@ export function linkWikiDataArrays(wikiData, {bindFind, bindReverse}) {
       'wikiInfo',
     ]],
 
-    ['flashActData', [/* find, reverse */]],
+    ['flashActData', ['flashActData']],
 
     ['flashSideData', [/* find */]],