From 846d70583eadd370c6374c0bc39571a29b1c3139 Mon Sep 17 00:00:00 2001 From: Aman Varshney Date: Fri, 20 Jun 2025 07:24:40 +0530 Subject: [PATCH] sort sponsors --- .../(home)/_components/sponsors-section.tsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/web/src/app/(home)/_components/sponsors-section.tsx b/apps/web/src/app/(home)/_components/sponsors-section.tsx index 1837007..833c2cc 100644 --- a/apps/web/src/app/(home)/_components/sponsors-section.tsx +++ b/apps/web/src/app/(home)/_components/sponsors-section.tsx @@ -15,7 +15,32 @@ export default function SponsorsSection() { return res.json(); }) .then((data) => { - setSponsors(Array.isArray(data) ? data : []); + const sponsorsData = Array.isArray(data) ? data : []; + + const sortedSponsors = sponsorsData.sort((a, b) => { + const getAmount = (sponsor: Sponsor) => { + if (!sponsor.isOneTime && sponsor.monthlyDollars > 0) { + return sponsor.monthlyDollars; + } + + if (sponsor.tierName) { + const match = sponsor.tierName.match(/\$(\d+(?:\.\d+)?)/); + return match ? Number.parseFloat(match[1]) : 0; + } + + return 0; + }; + + const aIsMonthly = !a.isOneTime; + const bIsMonthly = !b.isOneTime; + + if (aIsMonthly && !bIsMonthly) return -1; + if (!aIsMonthly && bIsMonthly) return 1; + + return getAmount(b) - getAmount(a); + }); + + setSponsors(sortedSponsors); setLoadingSponsors(false); }) .catch(() => {