Skip to content

Commit 581b3aa

Browse files
authored
Merge pull request #667 from Adez017/Experiment
Updated the PR Modal as per changes in Leaderboard
2 parents 8aee584 + d96ff1c commit 581b3aa

File tree

2 files changed

+61
-29
lines changed

2 files changed

+61
-29
lines changed

src/components/dashboard/LeaderBoard/PRListModal.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface PRDetails {
1111
mergedAt: string;
1212
repoName: string;
1313
number: number;
14+
points: number; // Now includes the points field
1415
}
1516

1617
interface Contributor {
@@ -40,6 +41,9 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
4041
// Get filtered PRs instead of using contributor.prDetails
4142
const filteredPRs = getFilteredPRsForContributor(contributor.username);
4243

44+
// Calculate total points from filtered PRs
45+
const totalPoints = filteredPRs.reduce((sum, pr) => sum + pr.points, 0);
46+
4347
const formatDate = (dateString: string) => {
4448
const date = new Date(dateString);
4549
return date.toLocaleDateString('en-US', {
@@ -72,6 +76,14 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
7276
}
7377
};
7478

79+
// Helper function to get badge color based on points
80+
const getPointsBadgeColor = (points: number) => {
81+
if (points >= 50) return '#10b981'; // Green for Level 3
82+
if (points >= 30) return '#f59e0b'; // Orange for Level 2
83+
if (points >= 10) return '#3b82f6'; // Blue for Level 1
84+
return '#6b7280'; // Gray for no points
85+
};
86+
7587
return (
7688
<AnimatePresence>
7789
{isOpen && (
@@ -107,8 +119,8 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
107119
{contributor.username}'s Pull Requests
108120
</h2>
109121
<p className={`pr-modal-subtitle ${isDark ? "dark" : "light"}`}>
110-
{/*Show filtered count and add filter info */}
111-
{filteredPRs.length} merged PR{filteredPRs.length !== 1 ? 's' : ''}{filteredPRs.length * 10} points
122+
{/* Show filtered count with actual total points */}
123+
{filteredPRs.length} merged PR{filteredPRs.length !== 1 ? 's' : ''}{totalPoints} point{totalPoints !== 1 ? 's' : ''}
112124
{currentTimeFilter !== 'all' && (
113125
<span style={{ marginLeft: '8px', opacity: 0.7 }}>
114126
({getFilterDisplayText(currentTimeFilter)})
@@ -128,7 +140,7 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
128140

129141
{/* Modal Body */}
130142
<div className={`pr-modal-body ${isDark ? "dark" : "light"}`}>
131-
{/*Use filteredPRs instead of contributor.prDetails */}
143+
{/* Use filteredPRs instead of contributor.prDetails */}
132144
{filteredPRs && filteredPRs.length > 0 ? (
133145
<div className="pr-list">
134146
{filteredPRs.map((pr, index) => (
@@ -144,6 +156,23 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
144156
{pr.title}
145157
</h3>
146158
<div className="pr-item-actions">
159+
{/* Points badge */}
160+
{pr.points > 0 && (
161+
<span
162+
className="pr-points-badge"
163+
style={{
164+
backgroundColor: getPointsBadgeColor(pr.points),
165+
color: 'white',
166+
padding: '4px 8px',
167+
borderRadius: '12px',
168+
fontSize: '12px',
169+
fontWeight: '600',
170+
marginRight: '8px',
171+
}}
172+
>
173+
+{pr.points} pts
174+
</span>
175+
)}
147176
<a
148177
href={pr.url}
149178
target="_blank"

src/lib/statsProvider.tsx

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps
306306
return mergedPRs;
307307
}, []);
308308

309-
// Enhanced processing function that stores all PR data without filtering
309+
// Enhanced processing function that stores only valid PRs with points
310310
const processBatch = useCallback(async (
311311
repos: any[],
312312
headers: Record<string, string>
@@ -335,35 +335,38 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps
335335

336336
// Process results from this batch
337337
results.forEach(({ mergedPRs, repoName }) => {
338-
totalMergedPRs += mergedPRs.length;
339-
340338
mergedPRs.forEach((pr) => {
341-
const username = pr.user.login;
342-
if (!contributorMap.has(username)) {
343-
contributorMap.set(username, {
344-
username,
345-
avatar: pr.user.avatar_url,
346-
profile: pr.user.html_url,
347-
points: 0, // Will be calculated later based on filter
348-
prs: 0, // Will be calculated later based on filter
349-
allPRDetails: [], // Store all PRs here
350-
});
351-
}
352-
const contributor = contributorMap.get(username)!;
353-
354339
// Calculate points for this PR based on labels
355340
const prPoints = calculatePointsForPR(pr.labels);
356341

357-
// Add detailed PR information to the full list
358-
if (pr.title && pr.html_url && pr.merged_at && pr.number) {
359-
contributor.allPRDetails.push({
360-
title: pr.title,
361-
url: pr.html_url,
362-
mergedAt: pr.merged_at,
363-
repoName,
364-
number: pr.number,
365-
points: prPoints,
366-
});
342+
// ONLY store PRs that have points (i.e., have "recode" label and a level label)
343+
if (prPoints > 0) {
344+
totalMergedPRs++;
345+
346+
const username = pr.user.login;
347+
if (!contributorMap.has(username)) {
348+
contributorMap.set(username, {
349+
username,
350+
avatar: pr.user.avatar_url,
351+
profile: pr.user.html_url,
352+
points: 0, // Will be calculated later based on filter
353+
prs: 0, // Will be calculated later based on filter
354+
allPRDetails: [], // Store only valid PRs here
355+
});
356+
}
357+
const contributor = contributorMap.get(username)!;
358+
359+
// Add detailed PR information only if it has all required fields
360+
if (pr.title && pr.html_url && pr.merged_at && pr.number) {
361+
contributor.allPRDetails.push({
362+
title: pr.title,
363+
url: pr.html_url,
364+
mergedAt: pr.merged_at,
365+
repoName,
366+
number: pr.number,
367+
points: prPoints,
368+
});
369+
}
367370
}
368371
});
369372
});

0 commit comments

Comments
 (0)