Skip to content

Commit

Permalink
show user tags per beatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko committed Dec 24, 2024
1 parent cde18d0 commit 572b046
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions resources/js/beatmapsets-show/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,34 @@ export default class Controller {
}

@computed
get tags() {
const tagMap = new Map<number, TagJsonWithCount>();
get relatedTags() {
const map = new Map<number, TagJson>();

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);
}),
Expand Down

0 comments on commit 572b046

Please sign in to comment.