From acb99a8c756ff7f1a13ec3ccb96c3dc938b20632 Mon Sep 17 00:00:00 2001 From: aditya singh rathore Date: Thu, 2 Oct 2025 14:35:58 +0530 Subject: [PATCH] Fix PR Modal --- .../dashboard/LeaderBoard/PRListModal.tsx | 35 +++++++++++- src/lib/statsProvider.tsx | 55 ++++++++++--------- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/components/dashboard/LeaderBoard/PRListModal.tsx b/src/components/dashboard/LeaderBoard/PRListModal.tsx index 04e1ca10..9ee724ee 100644 --- a/src/components/dashboard/LeaderBoard/PRListModal.tsx +++ b/src/components/dashboard/LeaderBoard/PRListModal.tsx @@ -11,6 +11,7 @@ interface PRDetails { mergedAt: string; repoName: string; number: number; + points: number; // Now includes the points field } interface Contributor { @@ -40,6 +41,9 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa // Get filtered PRs instead of using contributor.prDetails const filteredPRs = getFilteredPRsForContributor(contributor.username); + // Calculate total points from filtered PRs + const totalPoints = filteredPRs.reduce((sum, pr) => sum + pr.points, 0); + const formatDate = (dateString: string) => { const date = new Date(dateString); return date.toLocaleDateString('en-US', { @@ -72,6 +76,14 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa } }; + // Helper function to get badge color based on points + const getPointsBadgeColor = (points: number) => { + if (points >= 50) return '#10b981'; // Green for Level 3 + if (points >= 30) return '#f59e0b'; // Orange for Level 2 + if (points >= 10) return '#3b82f6'; // Blue for Level 1 + return '#6b7280'; // Gray for no points + }; + return ( {isOpen && ( @@ -107,8 +119,8 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa {contributor.username}'s Pull Requests

- {/*Show filtered count and add filter info */} - {filteredPRs.length} merged PR{filteredPRs.length !== 1 ? 's' : ''} • {filteredPRs.length * 10} points + {/* Show filtered count with actual total points */} + {filteredPRs.length} merged PR{filteredPRs.length !== 1 ? 's' : ''} • {totalPoints} point{totalPoints !== 1 ? 's' : ''} {currentTimeFilter !== 'all' && ( ({getFilterDisplayText(currentTimeFilter)}) @@ -128,7 +140,7 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa {/* Modal Body */}

- {/*Use filteredPRs instead of contributor.prDetails */} + {/* Use filteredPRs instead of contributor.prDetails */} {filteredPRs && filteredPRs.length > 0 ? (
{filteredPRs.map((pr, index) => ( @@ -144,6 +156,23 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa {pr.title}
+ {/* Points badge */} + {pr.points > 0 && ( + + +{pr.points} pts + + )} @@ -335,35 +335,38 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps // Process results from this batch results.forEach(({ mergedPRs, repoName }) => { - totalMergedPRs += mergedPRs.length; - mergedPRs.forEach((pr) => { - const username = pr.user.login; - if (!contributorMap.has(username)) { - contributorMap.set(username, { - username, - avatar: pr.user.avatar_url, - profile: pr.user.html_url, - points: 0, // Will be calculated later based on filter - prs: 0, // Will be calculated later based on filter - allPRDetails: [], // Store all PRs here - }); - } - const contributor = contributorMap.get(username)!; - // Calculate points for this PR based on labels const prPoints = calculatePointsForPR(pr.labels); - // Add detailed PR information to the full list - if (pr.title && pr.html_url && pr.merged_at && pr.number) { - contributor.allPRDetails.push({ - title: pr.title, - url: pr.html_url, - mergedAt: pr.merged_at, - repoName, - number: pr.number, - points: prPoints, - }); + // ONLY store PRs that have points (i.e., have "recode" label and a level label) + if (prPoints > 0) { + totalMergedPRs++; + + const username = pr.user.login; + if (!contributorMap.has(username)) { + contributorMap.set(username, { + username, + avatar: pr.user.avatar_url, + profile: pr.user.html_url, + points: 0, // Will be calculated later based on filter + prs: 0, // Will be calculated later based on filter + allPRDetails: [], // Store only valid PRs here + }); + } + const contributor = contributorMap.get(username)!; + + // Add detailed PR information only if it has all required fields + if (pr.title && pr.html_url && pr.merged_at && pr.number) { + contributor.allPRDetails.push({ + title: pr.title, + url: pr.html_url, + mergedAt: pr.merged_at, + repoName, + number: pr.number, + points: prPoints, + }); + } } }); });