aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/indexfactory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/services/indexfactory.ts')
-rw-r--r--viewer/src/services/indexfactory.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts
index a31f3ef..466b509 100644
--- a/viewer/src/services/indexfactory.ts
+++ b/viewer/src/services/indexfactory.ts
@@ -112,4 +112,23 @@ export default class IndexFactory {
112 if (strict) return node.tagfiltered === filter; 112 if (strict) return node.tagfiltered === filter;
113 return node.tagfiltered.includes(filter) 113 return node.tagfiltered.includes(filter)
114 } 114 }
115
116 // ---
117
118 public static generateCategories(tagsIndex: Tag.Index, tags?: Gallery.RawTag[]): Tag.Category[] {
119 if (!tags?.length) return [{ tag: "", index: tagsIndex }];
120
121 const tagsCategories: Tag.Category[] = [];
122 const tagsRemaining = new Map(Object.entries(tagsIndex));
123 tags
124 .map(tag => ({ tag, index: tagsIndex[tag]?.children }))
125 .filter(category => category.index && Object.keys(category.index).length)
126 .forEach(category => {
127 tagsCategories.push(category);
128 tagsRemaining.delete(category.tag);
129 Object.values(category.index).map(node => node.tag).forEach(tag => tagsRemaining.delete(tag));
130 });
131 tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) });
132 return tagsCategories;
133 }
115} 134}