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
This commit is contained in:
Aayush Shukla 2024-07-19 13:26:16 +05:30 • committed by GitHub
parent 4672f2d285
commit c48eee9e0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 1 deletions

View file

@ -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.\

View file

@ -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) {

View file

@ -76,6 +76,16 @@ export class TrophyList {
ranks.includes(trophy.rank)
);
}
filterByExclusionTitles(titles: Array<string>) {
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)