From ce04802f300ba627a3b9e9612d938b825045e63f Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 4 Apr 2020 01:36:34 +0200 Subject: viewer: tag categories implementation fixed single tags not appearing in the "Other filters" special category, following code review GitHub: Resolves #29 --- viewer/src/services/indexfactory.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 466b509..0a84951 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -38,18 +38,19 @@ export default class IndexFactory { const parts = tag.split(':'); let lastPart: string | null = null; for (const part of parts) { - tagsIndex[part] = IndexFactory.pushPartToIndex(tagsIndex[part], part, item); + tagsIndex[part] = IndexFactory.pushPartToIndex(tagsIndex[part], part, item, !Boolean(lastPart)); if (lastPart) { const children = tagsIndex[lastPart].children; - children[part] = IndexFactory.pushPartToIndex(children[part], part, item); + children[part] = IndexFactory.pushPartToIndex(children[part], part, item, false); } lastPart = part; } } } - private static pushPartToIndex(index: Tag.Node, part: string, item: Gallery.Item): Tag.Node { - if (!index) index = { tag: part, tagfiltered: Navigation.normalize(part), items: [], children: {} }; + 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: {} }; + else if (rootPart) index.rootPart = true; if (!index.items.includes(item)) index.items.push(item); return index; } @@ -125,8 +126,14 @@ export default class IndexFactory { .filter(category => category.index && Object.keys(category.index).length) .forEach(category => { tagsCategories.push(category); - tagsRemaining.delete(category.tag); - Object.values(category.index).map(node => node.tag).forEach(tag => tagsRemaining.delete(tag)); + + if (!tagsIndex[category.tag].rootPart) + tagsRemaining.delete(category.tag); + + Object.values(category.index) + .map(node => node.tag) + .filter(tag => !tagsIndex[tag].rootPart) + .forEach(tag => tagsRemaining.delete(tag)); }); tagsCategories.push({ tag: "", index: Object.fromEntries(tagsRemaining) }); return tagsCategories; -- cgit v1.2.3