Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impr(profile/account page): show leaderboard rank percentage (fehmer) #5212

Merged
merged 7 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 17 additions & 6 deletions backend/src/api/controllers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,18 +928,29 @@ async function getAllTimeLbs(uid: string): Promise<SharedTypes.AllTimeLbs> {
uid
);

const allTime15EnglishRank =
allTime15English === false ? null : allTime15English.rank;
const allTime60EnglishRank =
allTime60English === false ? null : allTime60English.rank;
const english15 =
allTime15English === false
? undefined
: ({
rank: allTime15English.rank,
count: allTime15English.count,
} as SharedTypes.RankAndCount);

const english60 =
allTime60English === false
? undefined
: ({
rank: allTime60English.rank,
count: allTime60English.count,
} as SharedTypes.RankAndCount);

return {
time: {
"15": {
english: allTime15EnglishRank,
english: english15,
},
"60": {
english: allTime60EnglishRank,
english: english60,
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/html/pages/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@
<div class="group t15">
<div class="testType">15 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
<div class="group t60">
<div class="testType">60 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
</div>
<div class="pbsTime">
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/html/pages/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@
<div class="group t15">
<div class="testType">15 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
<div class="group t60">
<div class="testType">60 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
</div>
<div class="pbsWords">
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/styles/profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,24 @@
}
.group {
display: grid;
gap: 1rem;
column-gap: 1rem;
grid-template-columns: auto 1fr;
grid-template-areas: "testType pos" "topPercentage pos";
align-items: center;
.testType {
grid-area: testType;
color: var(--sub-color);
}
.pos {
grid-area: pos;
font-size: 2rem;
}
.topPercentage {
color: var(--sub-color);
grid-area: topPercentage;
font-size: 0.75rem;
text-align: right;
}
&.t15 {
grid-area: t15;
}
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/ts/constants/default-snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@ export const defaultSnap: MonkeyTypes.Snapshot = {
streak: 0,
maxStreak: 0,
streakHourOffset: undefined,
allTimeLbs: { time: { 15: { english: 0 }, 60: { english: 0 } } },
allTimeLbs: {
time: {
15: { english: { count: 0, rank: 0 } },
60: { english: { count: 0, rank: 0 } },
},
},
};
29 changes: 23 additions & 6 deletions frontend/src/ts/elements/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,24 @@ export async function update(
if (t15 === null && t60 === null) {
profileElement.find(".leaderboardsPositions").addClass("hidden");
} else {
profileElement
.find(".leaderboardsPositions .group.t15 .pos")
.text(Format.rank(t15));
if (t15 !== null) {
profileElement
.find(".leaderboardsPositions .group.t15 .pos")
.text(Format.rank(t15?.rank));
profileElement
.find(".leaderboardsPositions .group.t15 .topPercentage")
.text(formatTopPercentage(t15));
}

profileElement
.find(".leaderboardsPositions .group.t60 .pos")
.text(Format.rank(t60));
if (t60 !== null) {
profileElement
.find(".leaderboardsPositions .group.t60 .pos")
.text(Format.rank(t60?.rank));

profileElement
.find(".leaderboardsPositions .group.t60 .topPercentage")
.text(formatTopPercentage(t60));
}
}
}

Expand Down Expand Up @@ -418,3 +429,9 @@ const throttledEvent = throttle(1000, () => {
$(window).on("resize", () => {
throttledEvent();
});

function formatTopPercentage(lbRank: SharedTypes.RankAndCount): string {
if (lbRank.rank === undefined) return "-";
if (lbRank.rank === 1) return "GOAT";
return "Top " + Format.percentage((lbRank.rank / lbRank.count) * 100);
}
2 changes: 2 additions & 0 deletions frontend/src/ts/pages/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ function reset(): void {
<div class="group t15">
<div class="testType">15 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
<div class="group t60">
<div class="testType">60 seconds</div>
<div class="pos">-</div>
<div class="topPercentage">-</div>
</div>
</div>
<div class="pbsWords">
Expand Down
7 changes: 6 additions & 1 deletion shared-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ declare namespace SharedTypes {
};

type AllTimeLbs = {
time: Record<string, Record<string, number | null>>;
time: Record<string, Record<string, RankAndCount | undefined>>;
};

type RankAndCount = {
rank?: number;
count: number;
};
}