diff --git a/frontend/src/ts/elements/alerts.ts b/frontend/src/ts/elements/alerts.ts index 8106a9821..b86458376 100644 --- a/frontend/src/ts/elements/alerts.ts +++ b/frontend/src/ts/elements/alerts.ts @@ -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); } }, diff --git a/frontend/src/ts/elements/profile.ts b/frontend/src/ts/elements/profile.ts index be859c374..b5fd6298c 100644 --- a/frontend/src/ts/elements/profile.ts +++ b/frontend/src/ts/elements/profile.ts @@ -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);