Skip to content

Commit 4944daa

Browse files
committed
feat: add conditions
1 parent cc51811 commit 4944daa

File tree

4 files changed

+176
-55
lines changed

4 files changed

+176
-55
lines changed

src/app/contributors/components/TopContributors.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@ interface Contributor {
99
avatar_url: string;
1010
html_url: string;
1111
contributions: number;
12+
lastActiveDays: number | null;
1213
}
1314

1415
interface TopContributorsProps {
1516
contributors: Contributor[];
1617
}
1718

1819
const TopContributors = ({ contributors }: TopContributorsProps) => {
20+
const getLastActiveText = (days: number | null): string => {
21+
if (days === null) return "No recent activity";
22+
if (days === 0) return "Active today";
23+
if (days === 1) return "Active yesterday";
24+
return `Active ${days} days ago`;
25+
};
26+
1927
return (
20-
<div className='relative items-center max-w-5xl mx-auto px-4 py-8'>
28+
<div className='relative items-center max-w-5xl mx-auto px-4 py-8'>
2129
{/* Contributors scroll container */}
2230
<div className='flex gap-6 overflow-x-auto scrollbar-hide snap-x snap-mandatory scroll-px-6 px-8'>
2331
{contributors.slice(0, 6).map((contributor) => (
@@ -49,6 +57,9 @@ const TopContributors = ({ contributors }: TopContributorsProps) => {
4957
<p className='text-xs text-gray-500'>
5058
{contributor.contributions} contributions
5159
</p>
60+
<p className='text-xs text-gray-400'>
61+
{getLastActiveText(contributor.lastActiveDays)}
62+
</p>
5263
</div>
5364
</div>
5465
</Link>

src/app/contributors/page.tsx

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@ import contributorList from "../projects/assets/contributors.json";
99
import ContributorCount from "./components/ContributorCount";
1010
import TopContributors from "./components/TopContributors";
1111

12+
interface Contributor {
13+
id: number;
14+
contributions: number;
15+
html_url: string;
16+
avatar_url: string;
17+
login: string;
18+
lastActiveDays: number | null;
19+
}
20+
1221
const Contributors = () => {
13-
const contributorsArray = Object.values(contributorList);
22+
const contributorsArray = Object.values(contributorList) as Contributor[];
23+
24+
// Filter and sort contributors for top section (active in last 30 days)
25+
const activeTopContributors = [...contributorsArray]
26+
.filter(
27+
(contributor) =>
28+
contributor.lastActiveDays === null || contributor.lastActiveDays <= 30
29+
)
30+
.sort((a, b) => b.contributions - a.contributions);
1431

15-
// Sort contributors by contributions for top contributors section
16-
const sortedContributors = [...contributorsArray].sort(
32+
// Sort all contributors by contributions for the main grid
33+
const sortedAllContributors = [...contributorsArray].sort(
1734
(a, b) => b.contributions - a.contributions
1835
);
1936

@@ -31,13 +48,13 @@ const Contributors = () => {
3148
{/* Top Contributors Section */}
3249
<div className='mt-12 flex flex-col items-center justify-center'>
3350
<h2 className='text-2xl font-medium text-gray-800 mb-6'>
34-
Top Contributors
51+
Top Active Contributors
3552
</h2>
3653
<p className='text-xl text-mf-light-grey tracking-wide mb-2'>
3754
Meet our top six contributors — the people who help turn ideas
3855
into impact.
3956
</p>
40-
<TopContributors contributors={sortedContributors} />
57+
<TopContributors contributors={activeTopContributors} />
4158
</div>
4259

4360
{/* All Contributors Section */}
@@ -46,12 +63,12 @@ const Contributors = () => {
4663
All Contributors
4764
</h2>
4865
<p className='text-xl text-mf-light-grey tracking-wide mb-10'>
49-
Were a dynamic group of individuals who are passionate about what
50-
we do.
66+
We&apos;re a dynamic group of individuals who are passionate about
67+
what we do.
5168
</p>
5269
{contributorsArray ? (
5370
<div className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4'>
54-
{contributorsArray.map((contributor) => (
71+
{sortedAllContributors.map((contributor) => (
5572
<div
5673
key={contributor.id}
5774
className='bg-white border border-gray-200 rounded-lg shadow-lg transition-transform duration-300 transform hover:scale-105'

0 commit comments

Comments
 (0)