diff options
Diffstat (limited to 'viewer/src/services/indexfactory.ts')
-rw-r--r-- | viewer/src/services/indexfactory.ts | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 25027f3..18a2800 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts | |||
@@ -45,12 +45,15 @@ export default class IndexFactory { | |||
45 | } | 45 | } |
46 | lastPart = part; | 46 | lastPart = part; |
47 | } | 47 | } |
48 | if (lastPart) tagsIndex[lastPart].childPart = true; | ||
48 | } | 49 | } |
49 | } | 50 | } |
50 | 51 | ||
51 | private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { | 52 | private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { |
52 | if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, items: [], children: {} }; | 53 | if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, childPart: !rootPart, items: [], children: {} }; |
53 | else if (rootPart) index.rootPart = true; | 54 | else if (rootPart) index.rootPart = true; |
55 | else index.childPart = true; | ||
56 | |||
54 | if (!index.items.includes(item)) index.items.push(item); | 57 | if (!index.items.includes(item)) index.items.push(item); |
55 | return index; | 58 | return index; |
56 | } | 59 | } |
@@ -116,22 +119,25 @@ export default class IndexFactory { | |||
116 | 119 | ||
117 | // --- | 120 | // --- |
118 | 121 | ||
119 | public static generateCategories(tagsIndex: Tag.Index, tags?: Gallery.RawTag[]): Tag.Category[] { | 122 | public static generateCategories(tagsIndex: Tag.Index, categoryTags?: Gallery.RawTag[]): Tag.Category[] { |
120 | if (!tags?.length) return [{ tag: "", index: tagsIndex }]; | 123 | if (!categoryTags?.length) return [{ tag: "", index: tagsIndex }]; |
121 | 124 | ||
122 | const tagsCategories: Tag.Category[] = []; | 125 | const tagsCategories: Tag.Category[] = []; |
123 | const tagsRemaining = new Map(Object.entries(tagsIndex)); | 126 | const tagsRemaining = new Map(Object.entries(tagsIndex)); |
124 | tags | 127 | categoryTags |
125 | .map(tag => ({ tag, index: tagsIndex[tag]?.children })) | 128 | .map(tag => ({ tag, index: tagsIndex[tag]?.children })) |
126 | .filter(category => category.index && Object.keys(category.index).length) | 129 | .filter(category => category.index && Object.keys(category.index).length) |
127 | .forEach(category => { | 130 | .forEach(category => { |
128 | tagsCategories.push(category); | 131 | tagsCategories.push(category); |
129 | |||
130 | [category.tag, ...Object.values(category.index).map(node => node.tag)] | 132 | [category.tag, ...Object.values(category.index).map(node => node.tag)] |
131 | .filter(tag => !tagsIndex[tag].rootPart) | 133 | .filter(tag => IndexFactory.isDiscriminantTagOnly(categoryTags, tagsIndex[tag])) |
132 | .forEach(tag => tagsRemaining.delete(tag)); | 134 | .forEach(tag => tagsRemaining.delete(tag)); |
133 | }); | 135 | }); |
134 | tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); | 136 | tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); |
135 | return tagsCategories; | 137 | return tagsCategories; |
136 | } | 138 | } |
139 | |||
140 | private static isDiscriminantTagOnly(tags: Gallery.RawTag[], node: Tag.Node): boolean { | ||
141 | return !tags.includes(node.tag) || !node.childPart; | ||
142 | } | ||
137 | } | 143 | } |