diff --git a/src/card.ts b/src/card.ts index eeb2f6b..1da203b 100644 --- a/src/card.ts +++ b/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( + let trophyList = new Array( 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;