Skip to content
Merged
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
35 changes: 32 additions & 3 deletions src/components/dashboard/LeaderBoard/PRListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface PRDetails {
mergedAt: string;
repoName: string;
number: number;
points: number; // Now includes the points field
}

interface Contributor {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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 (
<AnimatePresence>
{isOpen && (
Expand Down Expand Up @@ -107,8 +119,8 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
{contributor.username}'s Pull Requests
</h2>
<p className={`pr-modal-subtitle ${isDark ? "dark" : "light"}`}>
{/*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' : ''}
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

[nitpick] Magic numbers in the pluralization logic make the code harder to maintain. Consider extracting this into a helper function like pluralize(count, singular, plural) for reusability.

Copilot uses AI. Check for mistakes.

{currentTimeFilter !== 'all' && (
<span style={{ marginLeft: '8px', opacity: 0.7 }}>
({getFilterDisplayText(currentTimeFilter)})
Expand All @@ -128,7 +140,7 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa

{/* Modal Body */}
<div className={`pr-modal-body ${isDark ? "dark" : "light"}`}>
{/*Use filteredPRs instead of contributor.prDetails */}
{/* Use filteredPRs instead of contributor.prDetails */}
{filteredPRs && filteredPRs.length > 0 ? (
<div className="pr-list">
{filteredPRs.map((pr, index) => (
Expand All @@ -144,6 +156,23 @@ export default function PRListModal({ contributor, isOpen, onClose }: PRListModa
{pr.title}
</h3>
<div className="pr-item-actions">
{/* Points badge */}
{pr.points > 0 && (
<span
className="pr-points-badge"
style={{
backgroundColor: getPointsBadgeColor(pr.points),
color: 'white',
padding: '4px 8px',
borderRadius: '12px',
fontSize: '12px',
fontWeight: '600',
marginRight: '8px',
}}
>
+{pr.points} pts
</span>
)}
<a
href={pr.url}
target="_blank"
Expand Down
55 changes: 29 additions & 26 deletions src/lib/statsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export function CommunityStatsProvider({ children }: CommunityStatsProviderProps
return mergedPRs;
}, []);

// Enhanced processing function that stores all PR data without filtering
// Enhanced processing function that stores only valid PRs with points
const processBatch = useCallback(async (
repos: any[],
headers: Record<string, string>
Expand Down Expand Up @@ -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
Comment on lines +352 to +353
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

The comments are now misleading since points and PRs are only stored for valid PRs with points > 0, not calculated later based on filters. These comments should be updated to reflect the current logic.

Suggested change
points: 0, // Will be calculated later based on filter
prs: 0, // Will be calculated later based on filter
points: 0, // Will be incremented only for valid PRs (points > 0)
prs: 0, // Will be incremented only for valid PRs (points > 0)

Copilot uses AI. Check for mistakes.

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,
});
}
}
});
});
Expand Down
Loading