From c48eee9e0af7b4a036dac4fd09a29edcfabc3ff8 Mon Sep 17 00:00:00 2001 From: Aayush Shukla Date: Fri, 19 Jul 2024 13:26:16 +0530 Subject: [PATCH] Include a query where the user can exclude trophies based on title (#276) * First step to developing a feature to exclude speicifc trophies by title * Added support for exclusion by title * Ran deno lint, deno format and deno test found in CONTRIBUTING * Documented the latest addition in the README * Updated README --- README.md | 6 ++++++ src/card.ts | 8 +++++++- src/trophy_list.ts | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f5dae51..f2c1c0b 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,12 @@ If you want to specify multiple titles. https://github-profile-trophy.vercel.app/?username=ryo-ma&title=Stars,Followers ``` +You can also exclude the trophies you don't want to display. + +``` +https://github-profile-trophy.vercel.app/?username=ryo-ma&title=-Stars,-Followers +``` + ## Filter by ranks You can filter the display by specifying the ranks.\ diff --git a/src/card.ts b/src/card.ts index 5087a5e..b2762b4 100644 --- a/src/card.ts +++ b/src/card.ts @@ -29,7 +29,13 @@ export class Card { trophyList.filterByHidden(); if (this.titles.length != 0) { - trophyList.filterByTitles(this.titles); + const includeTitles = this.titles.filter((title) => + !title.startsWith("-") + ); + if (includeTitles.length > 0) { + trophyList.filterByTitles(includeTitles); + } + trophyList.filterByExclusionTitles(this.titles); } if (this.ranks.length != 0) { diff --git a/src/trophy_list.ts b/src/trophy_list.ts index 7c0b083..b85fae7 100644 --- a/src/trophy_list.ts +++ b/src/trophy_list.ts @@ -76,6 +76,16 @@ export class TrophyList { ranks.includes(trophy.rank) ); } + filterByExclusionTitles(titles: Array) { + const excludeTitles = titles.filter((title) => title.startsWith("-")).map( + (title) => title.substring(1), + ); + if (excludeTitles.length > 0) { + this.trophies = this.trophies.filter((trophy) => + !excludeTitles.includes(trophy.title) + ); + } + } sortByRank() { this.trophies = this.trophies.toSorted((a: Trophy, b: Trophy) => RANK_ORDER.indexOf(a.rank) - RANK_ORDER.indexOf(b.rank)