From 572b0461c9c5906a67def30741526111afb3c837 Mon Sep 17 00:00:00 2001 From: bakaneko Date: Wed, 25 Dec 2024 08:02:38 +0900 Subject: [PATCH] show user tags per beatmap --- resources/js/beatmapsets-show/controller.ts | 27 +++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/resources/js/beatmapsets-show/controller.ts b/resources/js/beatmapsets-show/controller.ts index 15f9acc725d..a48de73ff41 100644 --- a/resources/js/beatmapsets-show/controller.ts +++ b/resources/js/beatmapsets-show/controller.ts @@ -83,27 +83,34 @@ export default class Controller { } @computed - get tags() { - const tagMap = new Map(); + get relatedTags() { + const map = new Map(); for (const tag of this.beatmapset.related_tags) { - tagMap.set(tag.id, asTagJsonWithCount(tag)); + map.set(tag.id, tag); } - for (const beatmap of this.beatmapset.beatmaps) { - if (beatmap.top_tag_ids == null) continue; + return map; + } + + @computed + get tags() { + const userTags: TagJsonWithCount[] = []; - for (const tagId of beatmap.top_tag_ids) { - const tag = tagMap.get(tagId.tag_id); - if (tag == null) continue; + if (this.currentBeatmap.top_tag_ids != null) { + for (const tagId of this.currentBeatmap.top_tag_ids) { + const maybeTag = this.relatedTags.get(tagId.tag_id); + if (maybeTag == null) continue; - tag.count += tagId.count; + const tag = asTagJsonWithCount(maybeTag); + tag.count = tagId.count; + userTags.push(asTagJsonWithCount(tag)); } } return { mapperTags: this.beatmapset.tags.split(' ').filter(present), - userTags: [...tagMap.values()].sort((a, b) => { + userTags: userTags.sort((a, b) => { const diff = b.count - a.count; return diff !== 0 ? diff : a.name.localeCompare(b.name); }),