aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/source-merge.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/source-merge.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/source-merge.js37
1 files changed, 27 insertions, 10 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/source-merge.js b/packages/meshbay-hub/src/meshbay_hub/static/source-merge.js
index ccc4cfd..2c08e06 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/source-merge.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/source-merge.js
@@ -136,24 +136,41 @@ function mergeUnitEntries(units, opts) {
}
/**
- * What the group badge should say for one entry.
+ * What the group badge should say — for one entry, or for a whole unit.
+ *
+ * Takes a list, because a card stands for a unit while the entry it is drawn
+ * from is one file. A show's poster entry is picked for its *thumbnail*
+ * (`episodes.find((e) => e.thumb_hash)`), so reading the badge off it would
+ * report that one episode's sources: a show in two groups whose cover episode
+ * sits in only one of them would claim a single source. The union over the
+ * unit is the number the reader is actually being told.
*
* Returns `{ count, name, groupId }` rather than a rendered string: this module
* is executed standalone under node by its test, so it holds no reference to
* `i18n.js`. A caller renders `name` (a link to `groupId`) when `count` is 1,
- * and a plural of `count` otherwise — which group was picked is deliberately
+ * and a plural of `count` above that — which group was picked is deliberately
* never shown.
*
- * An entry with no `_sources` at all is the single-group Group page, where
- * there is one source by construction and no badge is drawn.
+ * `count: 0` is an entry with no group at all, which is the single-group Group
+ * page: there is one source by construction and no badge is drawn there.
*/
-function sourceLabel(entry) {
- const sources = (entry && entry._sources) || [];
- if (sources.length > 1) return { count: sources.length, name: '', groupId: null };
+function sourceLabel(entries) {
+ const list = Array.isArray(entries) ? entries : [entries];
+ const groups = new Map();
+ for (const e of list) {
+ if (!e) continue;
+ // An un-merged entry carries no `_sources`; it is its own single source.
+ const sources = (e._sources && e._sources.length)
+ ? e._sources
+ : (e.groupId ? [_source(e)] : []);
+ for (const s of sources) if (!groups.has(s.groupId)) groups.set(s.groupId, s);
+ }
+ if (groups.size > 1) return { count: groups.size, name: '', groupId: null };
+ const only = groups.values().next().value;
return {
- count: 1,
- name: (entry && entry.groupName) || '',
- groupId: (entry && entry.groupId) || null,
+ count: groups.size,
+ name: (only && only.groupName) || '',
+ groupId: (only && only.groupId) || null,
};
}