Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion frontend/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2861,7 +2861,8 @@ body::-webkit-scrollbar-thumb {
.rank-change[data-tooltip]::before {
content: attr(data-tooltip);
position: absolute;
bottom: 140%;
bottom: 140%; /* Default position */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this file contains changes from one of your previous, unrelated PRs.

Could you cherry-pick only the commit related to this issue and force-push the branch so this PR contains just the intended changes?

top: auto;
left: 50%;
transform: translateX(-50%);
background: var(--bg-raised);
Expand All @@ -2879,6 +2880,11 @@ body::-webkit-scrollbar-thumb {
transition: opacity 0.15s ease-in-out;
box-shadow: 0 0 15px rgba(0, 255, 65, 0.2);
}
/* Prevent tooltip from overlapping the sticky header */
.leaderboard-row:nth-child(-n + 3) .rank-change[data-tooltip]::before {
top: 140%;
bottom: auto;
}

.rank-change[data-tooltip]:hover::before {
opacity: 1;
Expand Down
47 changes: 36 additions & 11 deletions scripts/fetch-user-info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
async function fetchUserInfo(username) {
let liveSolved = null;
const usernameRegex = /^[a-zA-Z0-9_-]+$/;
if (!username || !usernameRegex.test(username)) {
throw new Error("Invalid username format");
Expand Down Expand Up @@ -50,23 +51,47 @@ async function fetchUserInfo(username) {
}

// 2. Fetch live profile ranking from the wrapper API
const livePromise = fetch(liveApiUrl).then(async (res) => {
if (res.ok) {
const apiData = await res.json();
ranking = apiData.ranking || 0;
contest = apiData.contest || null;
} else {
throw new Error(`LeetCode API wrapper returned status ${res.status}`);
}
});
const res = await fetch(liveApiUrl);

if (!res.ok) {
throw new Error(`LeetCode API wrapper returned status ${res.status}`);
}

const apiData = await res.json();

liveSolved = {
easy: apiData.easySolved,
medium: apiData.mediumSolved,
hard: apiData.hardSolved,
};

// Wait for the live API task to complete
await livePromise;
ranking = apiData.ranking || 0;
contest = apiData.contest || null;

// Ensure history is sorted chronologically
// Guard against a corrupted history file (e.g. non-array `history` field)
history = Array.isArray(history) ? history : [];
history.sort((a, b) => new Date(a.date) - new Date(b.date));
const today = new Date().toISOString().split("T")[0];
let latestEntry = null;

for (let i = history.length - 1; i >= 0; i--) {
const entry = history[i];

if (
typeof entry.date === "string" &&
entry.date.startsWith(today)
) {
latestEntry = entry;
break;
}
}

if (latestEntry && liveSolved) {
latestEntry.easy = liveSolved.easy;
latestEntry.medium = liveSolved.medium;
latestEntry.hard = liveSolved.hard;
}
Comment on lines +90 to +94

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (latestEntry && liveSolved) {
latestEntry.easy = liveSolved.easy;
latestEntry.medium = liveSolved.medium;
latestEntry.hard = liveSolved.hard;
}
if (latestEntry && liveSolved) {
latestEntry.easy = liveSolved.easy;
latestEntry.medium = liveSolved.medium;
latestEntry.hard = liveSolved.hard;
} else if (liveSolved) {
history.push({
date: today,
easy: liveSolved.easy,
medium: liveSolved.medium,
hard: liveSolved.hard,
});
}

This takes care of an edge case where a user visits after midnight but before the next sync runs. Since the date has changed, latestEntry will be null, causing the latest values to be ignored. In that case, we should instead create a new history entry for the current date.


return {
username,
Expand Down
Loading