From c9c69214dcb16a581525eee319ced6e7d9c98bf3 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 17 Apr 2020 23:19:49 +0200 Subject: viewer: fixed tag categories proposed again in "other filters" github: resolves #186 --- viewer/src/@types/tag.d.ts | 1 + viewer/src/services/indexfactory.ts | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'viewer') diff --git a/viewer/src/@types/tag.d.ts b/viewer/src/@types/tag.d.ts index 229c418..8f7e6a9 100644 --- a/viewer/src/@types/tag.d.ts +++ b/viewer/src/@types/tag.d.ts @@ -22,6 +22,7 @@ declare namespace Tag { tag: Gallery.RawTag; tagfiltered: Gallery.RawTag; rootPart: boolean; + childPart: boolean; items: Gallery.Item[]; children: Index; } 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 { } lastPart = part; } + if (lastPart) tagsIndex[lastPart].childPart = true; } } private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item, rootPart: boolean): Tag.Node { - if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, items: [], children: {} }; + if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), rootPart, childPart: !rootPart, items: [], children: {} }; else if (rootPart) index.rootPart = true; + else index.childPart = true; + if (!index.items.includes(item)) index.items.push(item); return index; } @@ -116,22 +119,25 @@ export default class IndexFactory { // --- - public static generateCategories(tagsIndex: Tag.Index, tags?: Gallery.RawTag[]): Tag.Category[] { - if (!tags?.length) return [{ tag: "", index: tagsIndex }]; + public static generateCategories(tagsIndex: Tag.Index, categoryTags?: Gallery.RawTag[]): Tag.Category[] { + if (!categoryTags?.length) return [{ tag: "", index: tagsIndex }]; const tagsCategories: Tag.Category[] = []; const tagsRemaining = new Map(Object.entries(tagsIndex)); - tags + categoryTags .map(tag => ({ tag, index: tagsIndex[tag]?.children })) .filter(category => category.index && Object.keys(category.index).length) .forEach(category => { tagsCategories.push(category); - [category.tag, ...Object.values(category.index).map(node => node.tag)] - .filter(tag => !tagsIndex[tag].rootPart) + .filter(tag => IndexFactory.isDiscriminantTagOnly(categoryTags, tagsIndex[tag])) .forEach(tag => tagsRemaining.delete(tag)); }); tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); return tagsCategories; } + + private static isDiscriminantTagOnly(tags: Gallery.RawTag[], node: Tag.Node): boolean { + return !tags.includes(node.tag) || !node.childPart; + } } -- cgit v1.2.3