mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
sort sponsors
This commit is contained in:
@@ -15,7 +15,32 @@ export default function SponsorsSection() {
|
|||||||
return res.json();
|
return res.json();
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.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);
|
setLoadingSponsors(false);
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user