fix(account page): xp bar not updating when claiming rewards (@fehmer) (#5607)

This commit is contained in:
Christian Fehmer 2024-07-11 15:35:52 +02:00 committed by GitHub
parent 1462d5193b
commit cecfb83b53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 21 deletions

View file

@ -9,6 +9,7 @@ import * as Notifications from "../elements/notifications";
import * as ConnectionState from "../states/connection";
import { escapeHTML } from "../utils/misc";
import AnimatedModal from "../utils/animated-modal";
import { updateXp as accountPageUpdateProfile } from "./profile";
let accountAlerts: MonkeyTypes.MonkeyMail[] = [];
let maxMail = 0;
@ -88,6 +89,7 @@ function hide(): void {
if (totalXpClaimed > 0) {
const snapxp = DB.getSnapshot()?.xp ?? 0;
void AccountButton.updateXpBar(snapxp, totalXpClaimed);
accountPageUpdateProfile(snapxp + totalXpClaimed);
DB.addXp(totalXpClaimed);
}
},

View file

@ -293,27 +293,7 @@ export async function update(
}
}
const xp = profile.xp ?? 0;
const xpDetails = Levels.getXpDetails(xp);
const xpForLevel = xpDetails.levelMaxXp;
const xpToDisplay = xpDetails.levelCurrentXp;
details
.find(".level")
.text(xpDetails.level)
.attr("aria-label", `${formatXp(xp)} total xp`);
details
.find(".xp")
.text(`${formatXp(xpToDisplay)}/${formatXp(xpForLevel)}`)
.attr(
"aria-label",
`${formatXp(xpForLevel - xpToDisplay)} xp until next level`
);
details
.find(".xpBar .bar")
.css("width", `${(xpToDisplay / xpForLevel) * 100}%`);
details
.find(".xpBar")
.attr("aria-label", `${((xpToDisplay / xpForLevel) * 100).toFixed(2)}%`);
updateXp(profile.xp ?? 0);
//lbs
if (banned) {
@ -395,6 +375,31 @@ export async function update(
}
}
export function updateXp(xp: number): void {
const details = $(" .profile .details .levelAndBar");
if (details === undefined || details === null) return;
const xpDetails = Levels.getXpDetails(xp);
const xpForLevel = xpDetails.levelMaxXp;
const xpToDisplay = xpDetails.levelCurrentXp;
details
.find(".level")
.text(xpDetails.level)
.attr("aria-label", `${formatXp(xp)} total xp`);
details
.find(".xp")
.text(`${formatXp(xpToDisplay)}/${formatXp(xpForLevel)}`)
.attr(
"aria-label",
`${formatXp(xpForLevel - xpToDisplay)} xp until next level`
);
details
.find(".xpBar .bar")
.css("width", `${(xpToDisplay / xpForLevel) * 100}%`);
details
.find(".xpBar")
.attr("aria-label", `${((xpToDisplay / xpForLevel) * 100).toFixed(2)}%`);
}
export function updateNameFontSize(where: ProfileViewPaths): void {
//dont run this function in safari because OH MY GOD IT IS SO SLOW
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);