-
Notifications
You must be signed in to change notification settings - Fork 118
fixed the filters PR Modal #605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
// src/pages/dashboard/LeaderBoard/leaderboard.tsx | ||||||
// src/components/dashboard/LeaderBoard/leaderboard.tsx | ||||||
import React, { JSX, useState } from "react"; | ||||||
import { motion } from "framer-motion"; | ||||||
import { | ||||||
|
@@ -129,18 +129,25 @@ function TopPerformerCard({ | |||||
); | ||||||
} | ||||||
|
||||||
// Define the time period type | ||||||
type TimePeriod = "all" | "weekly" | "monthly" | "yearly"; | ||||||
|
||||||
export default function LeaderBoard(): JSX.Element { | ||||||
const { contributors, stats, loading, error } = useCommunityStatsContext(); | ||||||
// Get time filter functions from context | ||||||
const { | ||||||
contributors, | ||||||
stats, | ||||||
loading, | ||||||
error, | ||||||
currentTimeFilter, | ||||||
setTimeFilter | ||||||
} = useCommunityStatsContext(); | ||||||
|
||||||
const { colorMode } = useColorMode(); | ||||||
const isDark = colorMode === "dark"; | ||||||
|
||||||
const [searchQuery, setSearchQuery] = useState(""); | ||||||
const [currentPage, setCurrentPage] = useState(1); | ||||||
const [selectedContributor, setSelectedContributor] = useState<Contributor | null>(null); | ||||||
const [isModalOpen, setIsModalOpen] = useState(false); | ||||||
const [isSelectChanged, setIsSelectChanged] = useState(false); | ||||||
const itemsPerPage = 10; | ||||||
|
||||||
// Modal handlers | ||||||
|
@@ -162,82 +169,17 @@ export default function LeaderBoard(): JSX.Element { | |||||
: []) | ||||||
: contributors; | ||||||
|
||||||
|
||||||
const [timePeriod, setTimePeriod] = useState<TimePeriod>("all"); | ||||||
const [isSelectChanged, setIsSelectChanged] = useState(false); | ||||||
|
||||||
|
||||||
// Get contributions within the selected time period | ||||||
const getContributionsWithinTimePeriod = (contributors: Contributor[]) => { | ||||||
if (timePeriod === "all") return contributors; | ||||||
|
||||||
// Get date threshold based on selected time period | ||||||
const now = new Date(); | ||||||
let threshold = new Date(); | ||||||
|
||||||
switch (timePeriod) { | ||||||
case "weekly": | ||||||
threshold.setDate(now.getDate() - 7); // Past 7 days | ||||||
break; | ||||||
case "monthly": | ||||||
threshold.setMonth(now.getMonth() - 1); // Past month | ||||||
break; | ||||||
case "yearly": | ||||||
threshold.setFullYear(now.getFullYear() - 1); // Past year | ||||||
break; | ||||||
} | ||||||
|
||||||
// Since we don't have the actual PR dates in the component, | ||||||
// we'll simulate filtering by reducing the PR counts by a factor | ||||||
// In a real implementation, you would filter based on actual PR dates | ||||||
return contributors.map(contributor => { | ||||||
// Apply a random factor based on time period to simulate date filtering | ||||||
// This is just for demonstration - in a real app you'd use actual date data | ||||||
let factor = 1; | ||||||
switch (timePeriod) { | ||||||
case "weekly": | ||||||
factor = 0.1 + Math.random() * 0.1; // Keep 10-20% for weekly | ||||||
break; | ||||||
case "monthly": | ||||||
factor = 0.3 + Math.random() * 0.2; // Keep 30-50% for monthly | ||||||
break; | ||||||
case "yearly": | ||||||
factor = 0.7 + Math.random() * 0.2; // Keep 70-90% for yearly | ||||||
break; | ||||||
} | ||||||
|
||||||
const filteredPrs = Math.floor(contributor.prs * factor); | ||||||
return { | ||||||
...contributor, | ||||||
prs: filteredPrs, | ||||||
points: filteredPrs * 10, // Assuming each PR is worth 10 points | ||||||
}; | ||||||
}).filter(contributor => contributor.prs > 0); // Remove contributors with 0 PRs | ||||||
}; | ||||||
|
||||||
// Filter out excluded users, apply time period filter, and then apply search filter | ||||||
const filteredContributors = getContributionsWithinTimePeriod(contributors) | ||||||
// Filter out excluded users and apply search filter | ||||||
const filteredContributors = contributors | ||||||
.filter((contributor) => | ||||||
!EXCLUDED_USERS.some(excludedUser => | ||||||
contributor.username.toLowerCase() === excludedUser.toLowerCase() | ||||||
) | ||||||
) | ||||||
.filter((contributor) => | ||||||
contributor.username.toLowerCase().includes(searchQuery.toLowerCase()) | ||||||
) | ||||||
// Re-sort contributors after filtering to ensure proper ranking | ||||||
.sort((a, b) => { | ||||||
// First sort by points (descending) | ||||||
if (b.points !== a.points) { | ||||||
return b.points - a.points; | ||||||
} | ||||||
// If points are equal, sort by PRs (descending) | ||||||
if (b.prs !== a.prs) { | ||||||
return b.prs - a.prs; | ||||||
} | ||||||
// If both points and PRs are equal, sort alphabetically by username (ascending) | ||||||
return a.username.localeCompare(b.username); | ||||||
}); | ||||||
); | ||||||
|
||||||
const totalPages = Math.ceil(filteredContributors.length / itemsPerPage); | ||||||
const indexOfLast = currentPage * itemsPerPage; | ||||||
|
@@ -343,6 +285,17 @@ export default function LeaderBoard(): JSX.Element { | |||||
return "regular"; | ||||||
}; | ||||||
|
||||||
// Helper function for time filter display | ||||||
const getTimeFilterLabel = (filter: string) => { | ||||||
switch (filter) { | ||||||
case 'week': return '📊 This Week'; | ||||||
case 'month': return '📆 This Month'; | ||||||
case 'year': return '📅 This Year'; | ||||||
case 'all': return '🏆 All Time'; | ||||||
default: return '🏆 All Time'; | ||||||
} | ||||||
}; | ||||||
|
||||||
return ( | ||||||
<div className={`leaderboard-container ${isDark ? "dark" : "light"}`}> | ||||||
<div className="leaderboard-content"> | ||||||
|
@@ -368,24 +321,24 @@ export default function LeaderBoard(): JSX.Element { | |||||
<label htmlFor="time-period-filter" className="filter-label">Time Period:</label> | ||||||
<select | ||||||
id="time-period-filter" | ||||||
value={timePeriod} | ||||||
value={currentTimeFilter} | ||||||
onChange={(e) => { | ||||||
setTimePeriod(e.target.value as TimePeriod); | ||||||
// Use setTimeFilter from context | ||||||
setTimeFilter(e.target.value as any); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
setCurrentPage(1); | ||||||
setIsSelectChanged(true); | ||||||
setTimeout(() => setIsSelectChanged(false), 1200); | ||||||
}} | ||||||
className={`time-filter-select ${isDark ? "dark" : "light"} ${isSelectChanged ? 'highlight-change' : ''}`} | ||||||
> | ||||||
<option value="all">🏆 All Time</option> | ||||||
<option value="yearly">📅 Past Year</option> | ||||||
<option value="monthly">📆 Past Month</option> | ||||||
<option value="weekly">📊 Past Week</option> | ||||||
<option value="year">📅 This Year</option> | ||||||
<option value="month">📆 This Month</option> | ||||||
<option value="week">📊 This Week</option> | ||||||
</select> | ||||||
</div> | ||||||
</div> | ||||||
<div className="top-performers-grid"> | ||||||
|
||||||
<TopPerformerCard contributor={filteredContributors[1]} rank={2} onPRClick={handlePRClick} /> | ||||||
<TopPerformerCard contributor={filteredContributors[0]} rank={1} onPRClick={handlePRClick} /> | ||||||
<TopPerformerCard contributor={filteredContributors[2]} rank={3} onPRClick={handlePRClick} /> | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The points calculation uses a magic number (10). Consider importing POINTS_PER_PR constant from statsProvider or defining it as a shared constant to maintain consistency.
Copilot uses AI. Check for mistakes.