Skip to content

Commit ba58a0d

Browse files
committed
feat(leaderboard): fix ranking logic and remove banned entries
Refactor entries-table component to filter out banned entries before sorting surrounding and top leaderboard entries, ensuring accurate rank calculations. Move userEntryIndexInSurroundingEntries getter below sorted entries to fix the reference order. Also update the post handler in mirage server to remove unused request parameter for clarity and update ranking date and static rank assignment.
1 parent 5d8976c commit ba58a0d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

app/components/leaderboard-page/entries-table.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Harder stages have higher scores assigned to them.
5252
return !this.userIsInTopLeaderboardEntries && this.surroundingEntries.length > 0;
5353
}
5454

55-
get userEntryIndexInSurroundingEntries() {
56-
return this.sortedSurroundingEntries.findIndex((entry) => entry.user.id === this.authenticator.currentUserId);
55+
get sortedSurroundingEntries() {
56+
return this.surroundingEntries.filter((entry) => !entry.isBanned).sort((a, b) => b.score - a.score);
5757
}
5858

5959
get sortedSurroundingEntriesWithRanks() {
@@ -63,14 +63,14 @@ Harder stages have higher scores assigned to them.
6363
}));
6464
}
6565

66-
get sortedSurroundingEntries() {
67-
return this.surroundingEntries.filter((entry) => !entry.isBanned).sort((a, b) => b.score - a.score);
68-
}
69-
7066
get sortedTopEntries() {
7167
return this.args.topEntries.filter((entry) => !entry.isBanned).sort((a, b) => b.score - a.score);
7268
}
7369

70+
get userEntryIndexInSurroundingEntries() {
71+
return this.sortedSurroundingEntries.findIndex((entry) => entry.user.id === this.authenticator.currentUserId);
72+
}
73+
7474
get userIsInTopLeaderboardEntries(): boolean {
7575
if (!this.authenticator.isAuthenticated) {
7676
return false;

mirage/handlers/leaderboard-rank-calculations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default function (server) {
77
return schema.leaderboardRankCalculations.all().filter((calculation) => calculation.leaderboard.id === request.queryParams.leaderboard_id);
88
});
99

10-
server.post('/leaderboard-rank-calculations', function (schema, request) {
10+
server.post('/leaderboard-rank-calculations', function (schema) {
1111
const attrs = this.normalizedRequestAttrs();
1212
attrs.calculatedAt = new Date();
1313
attrs.rank = 37812;

0 commit comments

Comments
 (0)