mirror of
https://github.com/reiyua/github-profile-trophy-reiyua-mirror.git
synced 2026-11-17 06:02:09 +11:00
Support to sort by rank
This commit is contained in:
parent
a5ea46790b
commit
3f51f2681d
1 changed files with 8 additions and 2 deletions
10
src/card.ts
10
src/card.ts
|
|
@ -8,7 +8,7 @@ import {
|
|||
TotalRepositoryTrophy,
|
||||
} from "./trophies.ts";
|
||||
import { UserInfo } from "./github_api_client.ts";
|
||||
import { CONSTANTS } from "./utils.ts";
|
||||
import { CONSTANTS, RANK } from "./utils.ts";
|
||||
|
||||
export class Card {
|
||||
private width = 0;
|
||||
|
|
@ -21,7 +21,7 @@ export class Card {
|
|||
this.width = panelSize * this.maxColumn;
|
||||
}
|
||||
render(userInfo: UserInfo): string {
|
||||
const trophyList = new Array<Trophy>(
|
||||
let trophyList = new Array<Trophy>(
|
||||
new TotalStarTrophy(userInfo.totalStargazers),
|
||||
new TotalCommitTrophy(userInfo.totalCommits),
|
||||
new TotalFollowerTrophy(userInfo.totalFollowers),
|
||||
|
|
@ -30,6 +30,12 @@ export class Card {
|
|||
new TotalRepositoryTrophy(userInfo.totalRepositories),
|
||||
);
|
||||
|
||||
// Sort by rank
|
||||
const rankOrder = Object.values(RANK);
|
||||
trophyList = trophyList.sort((a: Trophy, b: Trophy) =>
|
||||
rankOrder.indexOf(a.rank) - rankOrder.indexOf(b.rank)
|
||||
);
|
||||
|
||||
let row = Math.floor((trophyList.length - 1) / this.maxColumn) + 1;
|
||||
if (row > this.maxRow) {
|
||||
row = this.maxRow;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue