mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-09-20 07:16:17 +08:00
fix(xp): hide decimal point if displayed xp is < 1000 (NadAlaba) (#5448)
* fix(xp): hide the decimal point if displayed xp is an integer < 1000 (NadAlaba) * fix tests to match new rounding behavior * if you failed the test change the test * revert abbreviateNumber() and test changes and move previous changes to formatXp()
This commit is contained in:
parent
05d6160b2a
commit
2c0002c919
|
@ -300,19 +300,13 @@ export async function update(
|
|||
details
|
||||
.find(".level")
|
||||
.text(xpDetails.level)
|
||||
.attr("aria-label", `${Numbers.abbreviateNumber(xp)} total xp`);
|
||||
.attr("aria-label", `${formatXp(xp)} total xp`);
|
||||
details
|
||||
.find(".xp")
|
||||
.text(
|
||||
`${Numbers.abbreviateNumber(xpToDisplay)}/${Numbers.abbreviateNumber(
|
||||
xpForLevel
|
||||
)}`
|
||||
)
|
||||
.text(`${formatXp(xpToDisplay)}/${formatXp(xpForLevel)}`)
|
||||
.attr(
|
||||
"aria-label",
|
||||
`${Numbers.abbreviateNumber(
|
||||
xpForLevel - xpToDisplay
|
||||
)} xp until next level`
|
||||
`${formatXp(xpForLevel - xpToDisplay)} xp until next level`
|
||||
);
|
||||
details
|
||||
.find(".xpBar .bar")
|
||||
|
@ -445,3 +439,11 @@ function formatTopPercentage(lbRank: SharedTypes.RankAndCount): string {
|
|||
if (lbRank.rank === 1) return "GOAT";
|
||||
return "Top " + Numbers.roundTo2((lbRank.rank / lbRank.count) * 100) + "%";
|
||||
}
|
||||
|
||||
function formatXp(xp: number): string {
|
||||
if (xp < 1000) {
|
||||
return Math.round(xp).toString();
|
||||
} else {
|
||||
return Numbers.abbreviateNumber(xp);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue