Skip to content

Commit 846d705

Browse files
sort sponsors
1 parent 0e5803f commit 846d705

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

apps/web/src/app/(home)/_components/sponsors-section.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,32 @@ export default function SponsorsSection() {
1515
return res.json();
1616
})
1717
.then((data) => {
18-
setSponsors(Array.isArray(data) ? data : []);
18+
const sponsorsData = Array.isArray(data) ? data : [];
19+
20+
const sortedSponsors = sponsorsData.sort((a, b) => {
21+
const getAmount = (sponsor: Sponsor) => {
22+
if (!sponsor.isOneTime && sponsor.monthlyDollars > 0) {
23+
return sponsor.monthlyDollars;
24+
}
25+
26+
if (sponsor.tierName) {
27+
const match = sponsor.tierName.match(/\$(\d+(?:\.\d+)?)/);
28+
return match ? Number.parseFloat(match[1]) : 0;
29+
}
30+
31+
return 0;
32+
};
33+
34+
const aIsMonthly = !a.isOneTime;
35+
const bIsMonthly = !b.isOneTime;
36+
37+
if (aIsMonthly && !bIsMonthly) return -1;
38+
if (!aIsMonthly && bIsMonthly) return 1;
39+
40+
return getAmount(b) - getAmount(a);
41+
});
42+
43+
setSponsors(sortedSponsors);
1944
setLoadingSponsors(false);
2045
})
2146
.catch(() => {

0 commit comments

Comments
 (0)