mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-08 08:25:05 +08:00
refactor: move pb crown aria-label text update to a function
This commit is contained in:
parent
f0441e2b66
commit
cbd6725ad6
1 changed files with 19 additions and 12 deletions
|
|
@ -370,6 +370,14 @@ export function showCrown(type: PbCrown.CrownType): void {
|
|||
PbCrown.update(type);
|
||||
}
|
||||
|
||||
export function updateCrownText(text: string, wide = false): void {
|
||||
$("#result .stats .wpm .crown").attr("aria-label", text);
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"data-balloon-length",
|
||||
wide ? "medium" : ""
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateCrown(dontSave: boolean): Promise<void> {
|
||||
if (Config.mode === "quote" || dontSave) {
|
||||
hideCrown();
|
||||
|
|
@ -396,8 +404,7 @@ export async function updateCrown(dontSave: boolean): Promise<void> {
|
|||
} else {
|
||||
//show half crown as the pb is not confirmed by the server
|
||||
showCrown("pending");
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"aria-label",
|
||||
updateCrownText(
|
||||
"+" + Format.typingSpeed(pbDiff, { showDecimalPlaces: true })
|
||||
);
|
||||
}
|
||||
|
|
@ -416,17 +423,17 @@ export async function updateCrown(dontSave: boolean): Promise<void> {
|
|||
if (pbDiff <= 0) {
|
||||
// hideCrown();
|
||||
showCrown("warning");
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"aria-label",
|
||||
`This result is not eligible for a new PB (${canGetPb.reason})`
|
||||
updateCrownText(
|
||||
`This result is not eligible for a new PB (${canGetPb.reason})`,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
showCrown("ineligible");
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"aria-label",
|
||||
updateCrownText(
|
||||
`You could've gotten a new PB (+${Format.typingSpeed(pbDiff, {
|
||||
showDecimalPlaces: true,
|
||||
})}), but your config does not allow it (${canGetPb.reason})`
|
||||
})}), but your config does not allow it (${canGetPb.reason})`,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -434,16 +441,16 @@ export async function updateCrown(dontSave: boolean): Promise<void> {
|
|||
|
||||
export function hideCrown(): void {
|
||||
PbCrown.hide();
|
||||
$("#result .stats .wpm .crown").attr("aria-label", "");
|
||||
updateCrownText("");
|
||||
}
|
||||
|
||||
export function showErrorCrownIfNeeded(): void {
|
||||
if (PbCrown.getCurrentType() !== "pending") return;
|
||||
PbCrown.show();
|
||||
PbCrown.update("error");
|
||||
$("#result .stats .wpm .crown").attr(
|
||||
"aria-label",
|
||||
`Local PB data is out of sync with the server - please refresh (pb mismatch)`
|
||||
updateCrownText(
|
||||
`Local PB data is out of sync with the server - please refresh (pb mismatch)`,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue