@@ -3,67 +3,30 @@ import type { Sponsor } from "@/lib/types";
3
3
export const SPECIAL_SPONSOR_THRESHOLD = 100 ;
4
4
5
5
export const getSponsorAmount = ( sponsor : Sponsor ) : number => {
6
- // For past sponsors, return 0
7
- if ( sponsor . monthlyDollars === - 1 ) {
8
- return 0 ;
6
+ // If totalProcessedAmount exists, use it, otherwise parse from tierName
7
+ if ( sponsor . totalProcessedAmount !== undefined ) {
8
+ return sponsor . totalProcessedAmount ;
9
9
}
10
10
11
- // For one-time sponsors, parse the actual amount from tierName
12
- if ( sponsor . isOneTime && sponsor . tierName ) {
13
- const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
14
- return match ? Number . parseFloat ( match [ 1 ] ) : sponsor . monthlyDollars ;
15
- }
16
-
17
- // For monthly sponsors, use monthlyDollars
18
- return sponsor . monthlyDollars ;
11
+ // Parse amount from tierName as fallback
12
+ const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
13
+ return match ? Number . parseFloat ( match [ 1 ] ) : 0 ;
19
14
} ;
20
15
21
16
export const calculateLifetimeContribution = ( sponsor : Sponsor ) : number => {
22
- // For past sponsors, return 0
23
- if ( sponsor . monthlyDollars === - 1 ) {
24
- return 0 ;
25
- }
26
-
27
- // For one-time sponsors, return the one-time amount
28
- if ( sponsor . isOneTime && sponsor . tierName ) {
29
- const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
30
- return match ? Number . parseFloat ( match [ 1 ] ) : 0 ;
17
+ // If totalProcessedAmount exists, use it, otherwise parse from tierName
18
+ if ( sponsor . totalProcessedAmount !== undefined ) {
19
+ return sponsor . totalProcessedAmount ;
31
20
}
32
21
33
- // For monthly sponsors, calculate total contribution since they started
34
- const startDate = new Date ( sponsor . createdAt ) ;
35
- const currentDate = new Date ( ) ;
36
- const monthsSinceStart = Math . max (
37
- 1 ,
38
- Math . floor (
39
- ( currentDate . getTime ( ) - startDate . getTime ( ) ) /
40
- ( 1000 * 60 * 60 * 24 * 30.44 ) ,
41
- ) ,
42
- ) ;
43
-
44
- return sponsor . monthlyDollars * monthsSinceStart ;
22
+ // Parse amount from tierName as fallback
23
+ const match = sponsor . tierName . match ( / \$ ( \d + (?: \. \d + ) ? ) / ) ;
24
+ return match ? Number . parseFloat ( match [ 1 ] ) : 0 ;
45
25
} ;
46
26
47
27
export const shouldShowLifetimeTotal = ( sponsor : Sponsor ) : boolean => {
48
- // Don't show for past sponsors
49
- if ( sponsor . monthlyDollars === - 1 ) {
50
- return false ;
51
- }
52
-
53
- // Don't show for one-time sponsors
54
- if ( sponsor . isOneTime ) {
55
- return false ;
56
- }
57
-
58
- // Don't show for first month sponsors
59
- const startDate = new Date ( sponsor . createdAt ) ;
60
- const currentDate = new Date ( ) ;
61
- const monthsSinceStart = Math . floor (
62
- ( currentDate . getTime ( ) - startDate . getTime ( ) ) /
63
- ( 1000 * 60 * 60 * 24 * 30.44 ) ,
64
- ) ;
65
-
66
- return monthsSinceStart > 1 ;
28
+ // Only show lifetime total if totalProcessedAmount exists
29
+ return sponsor . totalProcessedAmount !== undefined ;
67
30
} ;
68
31
69
32
export const filterVisibleSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
@@ -87,69 +50,27 @@ export const sortSponsors = (sponsors: Sponsor[]): Sponsor[] => {
87
50
return sponsors . sort ( ( a , b ) => {
88
51
const aAmount = getSponsorAmount ( a ) ;
89
52
const bAmount = getSponsorAmount ( b ) ;
90
- const aLifetime = calculateLifetimeContribution ( a ) ;
91
- const bLifetime = calculateLifetimeContribution ( b ) ;
92
- const aIsPast = a . monthlyDollars === - 1 ;
93
- const bIsPast = b . monthlyDollars === - 1 ;
94
53
const aIsSpecial = isSpecialSponsor ( a ) ;
95
54
const bIsSpecial = isSpecialSponsor ( b ) ;
96
- const aIsLifetimeSpecial = isLifetimeSpecialSponsor ( a ) ;
97
- const bIsLifetimeSpecial = isLifetimeSpecialSponsor ( b ) ;
98
55
99
- // 1. Special sponsors (>=$100 current ) come first
56
+ // 1. Special sponsors (>=$100) come first
100
57
if ( aIsSpecial && ! bIsSpecial ) return - 1 ;
101
58
if ( ! aIsSpecial && bIsSpecial ) return 1 ;
102
59
if ( aIsSpecial && bIsSpecial ) {
103
60
if ( aAmount !== bAmount ) {
104
61
return bAmount - aAmount ;
105
62
}
106
- // If amounts equal, prefer monthly over one-time
107
- if ( a . isOneTime && ! b . isOneTime ) return 1 ;
108
- if ( ! a . isOneTime && b . isOneTime ) return - 1 ;
109
- // Then by creation date (oldest first)
110
- return new Date ( a . createdAt ) . getTime ( ) - new Date ( b . createdAt ) . getTime ( ) ;
111
- }
112
-
113
- // 2. Lifetime special sponsors (>=$100 total) come next
114
- if ( aIsLifetimeSpecial && ! bIsLifetimeSpecial ) return - 1 ;
115
- if ( ! aIsLifetimeSpecial && bIsLifetimeSpecial ) return 1 ;
116
- if ( aIsLifetimeSpecial && bIsLifetimeSpecial ) {
117
- if ( aLifetime !== bLifetime ) {
118
- return bLifetime - aLifetime ;
119
- }
120
- // If lifetime amounts equal, prefer monthly over one-time
121
- if ( a . isOneTime && ! b . isOneTime ) return 1 ;
122
- if ( ! a . isOneTime && b . isOneTime ) return - 1 ;
123
- // Then by creation date (oldest first)
124
- return new Date ( a . createdAt ) . getTime ( ) - new Date ( b . createdAt ) . getTime ( ) ;
63
+ // If amounts equal, sort by name
64
+ return a . name . localeCompare ( b . name ) ;
125
65
}
126
66
127
- // 3. Current sponsors come before past sponsors
128
- if ( ! aIsPast && bIsPast ) return - 1 ;
129
- if ( aIsPast && ! bIsPast ) return 1 ;
130
-
131
- // 4. For current sponsors, sort by lifetime contribution (highest first)
132
- if ( ! aIsPast && ! bIsPast ) {
133
- if ( aLifetime !== bLifetime ) {
134
- return bLifetime - aLifetime ;
135
- }
136
- // If lifetime amounts equal, prefer monthly over one-time
137
- if ( a . isOneTime && ! b . isOneTime ) return 1 ;
138
- if ( ! a . isOneTime && b . isOneTime ) return - 1 ;
139
- // Then by creation date (oldest first)
140
- return new Date ( a . createdAt ) . getTime ( ) - new Date ( b . createdAt ) . getTime ( ) ;
67
+ // 2. Regular sponsors sorted by amount (highest first)
68
+ if ( aAmount !== bAmount ) {
69
+ return bAmount - aAmount ;
141
70
}
142
71
143
- // 5. For past sponsors, sort by lifetime contribution (highest first)
144
- if ( aIsPast && bIsPast ) {
145
- if ( aLifetime !== bLifetime ) {
146
- return bLifetime - aLifetime ;
147
- }
148
- // Then by creation date (newest first)
149
- return new Date ( b . createdAt ) . getTime ( ) - new Date ( a . createdAt ) . getTime ( ) ;
150
- }
151
-
152
- return 0 ;
72
+ // 3. If amounts equal, sort by name
73
+ return a . name . localeCompare ( b . name ) ;
153
74
} ) ;
154
75
} ;
155
76
@@ -158,33 +79,24 @@ export const sortSpecialSponsors = (sponsors: Sponsor[]): Sponsor[] => {
158
79
const aLifetime = calculateLifetimeContribution ( a ) ;
159
80
const bLifetime = calculateLifetimeContribution ( b ) ;
160
81
161
- // First, prioritize current special sponsors
162
- const aIsSpecial = isSpecialSponsor ( a ) ;
163
- const bIsSpecial = isSpecialSponsor ( b ) ;
164
-
165
- if ( aIsSpecial && ! bIsSpecial ) return - 1 ;
166
- if ( ! aIsSpecial && bIsSpecial ) return 1 ;
167
-
168
- // Then sort by lifetime contribution (highest first)
82
+ // Sort by lifetime contribution (highest first)
169
83
if ( aLifetime !== bLifetime ) {
170
84
return bLifetime - aLifetime ;
171
85
}
172
86
173
- // If lifetime amounts equal, prefer monthly over one-time
174
- if ( a . isOneTime && ! b . isOneTime ) return 1 ;
175
- if ( ! a . isOneTime && b . isOneTime ) return - 1 ;
176
-
177
- // Then by creation date (oldest first)
178
- return new Date ( a . createdAt ) . getTime ( ) - new Date ( b . createdAt ) . getTime ( ) ;
87
+ // If amounts equal, sort by name
88
+ return a . name . localeCompare ( b . name ) ;
179
89
} ) ;
180
90
} ;
181
91
182
92
export const filterCurrentSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
183
- return sponsors . filter ( ( sponsor ) => sponsor . monthlyDollars !== - 1 ) ;
93
+ // In the new structure, all sponsors in the main arrays are current
94
+ return sponsors ;
184
95
} ;
185
96
186
- export const filterPastSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
187
- return sponsors . filter ( ( sponsor ) => sponsor . monthlyDollars === - 1 ) ;
97
+ export const filterPastSponsors = ( _sponsors : Sponsor [ ] ) : Sponsor [ ] => {
98
+ // Past sponsors are handled separately in the new structure
99
+ return [ ] ;
188
100
} ;
189
101
190
102
export const filterSpecialSponsors = ( sponsors : Sponsor [ ] ) : Sponsor [ ] => {
@@ -196,11 +108,7 @@ export const filterRegularSponsors = (sponsors: Sponsor[]): Sponsor[] => {
196
108
} ;
197
109
198
110
export const getSponsorUrl = ( sponsor : Sponsor ) : string => {
199
- return (
200
- sponsor . sponsor . websiteUrl ||
201
- sponsor . sponsor . linkUrl ||
202
- `https://github.com/${ sponsor . sponsor . login } `
203
- ) ;
111
+ return sponsor . websiteUrl || sponsor . githubUrl ;
204
112
} ;
205
113
206
114
export const formatSponsorUrl = ( url : string ) : string => {
0 commit comments