Skip to content

Commit

Permalink
order leaderboard by name and total
Browse files Browse the repository at this point in the history
  • Loading branch information
QPixel committed Apr 17, 2024
1 parent c3519dd commit eb1390a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/lib/components/get-leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,18 @@ function getLeaderboard() {
}
return entry;
});
v[current_quarter].data = newData.sort((a, b) => b.total - a.total);
v[current_quarter].data = newData.sort((a, b) => {
if (a.total > b.total) {
return -1;
}
if (a.total < b.total) {
return 1;
}
if (a.resolved_username < b.resolved_username) {
return -1;
}
return 0;
});
v[current_quarter].total = v[current_quarter].total + 1;
}
return v;
Expand Down
2 changes: 2 additions & 0 deletions src/pages/api/counter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const POST: APIRoute = async ({ cookies, locals }) => {
}

const resetAt = compareAsc(new Date(), cookies.get("resetAt")!.value);

if (resetAt >= 0) {
cookies.set("triedToIncrement", "0", {
path: "/",
Expand All @@ -118,6 +119,7 @@ export const POST: APIRoute = async ({ cookies, locals }) => {
},
);
}

if (
cookies.get("triedToIncrement")!.number() > incrementCount &&
resetAt == -1 &&
Expand Down
16 changes: 16 additions & 0 deletions src/pages/api/leaderboard/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ export async function getLeaderboard(env: ENV) {
resolved_username: username ? username : "Unknown",
});
}

for (const entry of Object.values(wompData)) {
entry.data.sort((a, b) => {
if (a.total > b.total) {
return -1;
}
if (a.total < b.total) {
return 1;
}
if (a.resolved_username < b.resolved_username) {
return -1;
}
return 0;
});
}

for (const total of quarterTotals) {
wompData[total.quarter].total = total.total;
}
Expand Down
16 changes: 14 additions & 2 deletions src/pages/api/leaderboard/quarter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ export async function getLeaderboardByQuarter(quarter: string, env: ENV) {
updated_by: womp.updated_by,
resolved_username: username ? username : "Unknown",
};
}),
})
);
return wompData;
return wompData.sort((a, b) => {
if (a.total > b.total) {
return -1;
}
if (a.total < b.total) {
return 1;
}
// follow alphabetical order if the totals are the same
if (a.resolved_username < b.resolved_username) {
return -1;
}
return 0;
});
}

export async function getQuarters(env: ENV) {
Expand Down

0 comments on commit eb1390a

Please sign in to comment.