File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
apps/web/src/app/(home)/_components Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,32 @@ export default function SponsorsSection() {
15
15
return res . json ( ) ;
16
16
} )
17
17
. 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 ) ;
19
44
setLoadingSponsors ( false ) ;
20
45
} )
21
46
. catch ( ( ) => {
You can’t perform that action at this time.
0 commit comments