diff --git a/frontend/src/ts/db.ts b/frontend/src/ts/db.ts index 1f22d01c2..d125972cf 100644 --- a/frontend/src/ts/db.ts +++ b/frontend/src/ts/db.ts @@ -1136,6 +1136,17 @@ function convertConnections( ); } +export function isFriend(uid: string | undefined): boolean { + if (uid === undefined || uid === getAuthenticatedUser()?.uid) return false; + + const snapshot = getSnapshot(); + if (!snapshot) return false; + + return Object.entries(snapshot.connections).some( + ([receiverUid, status]) => receiverUid === uid && status === "accepted" + ); +} + // export async function DB.getLocalTagPB(tagId) { // function cont() { // let ret = 0; diff --git a/frontend/src/ts/elements/profile.ts b/frontend/src/ts/elements/profile.ts index 940bf8e5d..e8401ec12 100644 --- a/frontend/src/ts/elements/profile.ts +++ b/frontend/src/ts/elements/profile.ts @@ -73,7 +73,9 @@ export async function update( details.find(".name").text(profile.name); details .find(".userFlags") - .html(getHtmlByUserFlags({ ...profile, isFriend: isFriend(profile.uid) })); + .html( + getHtmlByUserFlags({ ...profile, isFriend: DB.isFriend(profile.uid) }) + ); if (profile.lbOptOut === true) { if (where === "profile") { @@ -433,14 +435,6 @@ export function updateNameFontSize(where: ProfileViewPaths): void { nameField.style.fontSize = `${finalFontSize}px`; } -function isFriend(uid: string | undefined): boolean { - if (uid === undefined || uid === getAuthenticatedUser()?.uid) return false; - - return Object.entries(DB.getSnapshot()?.connections ?? []).some( - ([receiverUid, status]) => receiverUid === uid && status === "accepted" - ); -} - export function updateFriendRequestButton(): void { const myUid = getAuthenticatedUser()?.uid; const profileUid = document @@ -452,7 +446,9 @@ export function updateFriendRequestButton(): void { const hasRequest = DB.getSnapshot()?.connections[profileUid] !== undefined; const featureEnabled = getServerConfiguration()?.connections.enabled; - if (!featureEnabled || myUid === undefined || myProfile || hasRequest) { + if (!featureEnabled || myUid === undefined || myProfile) { + button?.classList.add("hidden"); + } else if (hasRequest) { button?.classList.add("disabled"); } else { button?.classList.remove("disabled"); diff --git a/frontend/src/ts/pages/friends.ts b/frontend/src/ts/pages/friends.ts index f7a845c97..75b79efdd 100644 --- a/frontend/src/ts/pages/friends.ts +++ b/frontend/src/ts/pages/friends.ts @@ -370,8 +370,8 @@ function formatPb(entry?: PersonalBest): result.details = [ `${getLanguageDisplayString(entry.language)}`, `${result.wpm} wpm`, - `${result.raw} raw`, `${result.acc} acc`, + `${result.raw} raw`, `${result.con} con`, `${dateFormat(entry.timestamp, "dd MMM yyyy")}`, ].join("\n"); diff --git a/frontend/src/ts/pages/leaderboards.ts b/frontend/src/ts/pages/leaderboards.ts index f3210e21d..0eaf8d437 100644 --- a/frontend/src/ts/pages/leaderboards.ts +++ b/frontend/src/ts/pages/leaderboards.ts @@ -434,7 +434,10 @@ function buildTableRow(entry: LeaderboardEntry, me = false): HTMLElement { entry.uid }?isUid" class="entryName" uid=${entry.uid} router-link>${entry.name}