Skip to content

Commit 0e055d5

Browse files
sokraEugeneHlushko
authored andcommitted
Limit number of display sponsors and backers (#2681)
1 parent d5f9b86 commit 0e055d5

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/components/Support/Support.jsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ SUPPORTERS.sort((a, b) => b.totalDonations - a.totalDonations);
2121

2222
const ranks = {
2323
backer: {
24-
maximum: 200
24+
maximum: 200,
25+
random: 100
2526
},
2627
latest: {
27-
maxAge: 14 * 24 * 60 * 60 * 1000
28+
maxAge: 14 * 24 * 60 * 60 * 1000,
29+
limit: 10
2830
},
2931
bronze: {
3032
minimum: 200,
@@ -56,12 +58,14 @@ export default class Support extends React.Component {
5658
let { rank } = this.props;
5759

5860
let supporters = SUPPORTERS;
59-
let minimum, maximum, maxAge;
61+
let minimum, maximum, maxAge, limit, random;
6062

6163
if (rank && ranks[rank]) {
6264
minimum = ranks[rank].minimum;
6365
maximum = ranks[rank].maximum;
6466
maxAge = ranks[rank].maxAge;
67+
limit = ranks[rank].limit;
68+
random = ranks[rank].random;
6569
}
6670

6771
if (typeof minimum === 'number') {
@@ -77,15 +81,33 @@ export default class Support extends React.Component {
7781
supporters = supporters.filter(item => item.firstDonation && (now - new Date(item.firstDonation).getTime() < maxAge));
7882
}
7983

84+
if (typeof limit === 'number') {
85+
supporters = supporters.slice(0, limit);
86+
}
87+
88+
if (typeof random === 'number') {
89+
// Pick n random items
90+
for (let i = 0; i < random; i++) {
91+
const other = Math.floor(Math.random() * (supporters.length - i));
92+
const temp = supporters[other];
93+
supporters[other] = supporters[i];
94+
supporters[i] = temp;
95+
}
96+
supporters = supporters.slice(0, random);
97+
98+
// resort to keep order
99+
supporters.sort((a, b) => b.totalDonations - a.totalDonations);
100+
}
101+
80102
return (
81103
<div className="support">
82104
<div className="support__description">
83105
{ rank === 'backer' ? (
84106
<p>
85-
The following <b>Backers</b> are individuals who have contributed various amounts of money in order to help support webpack. Every little bit helps, and we appreciate even the smallest contributions.
107+
The following <b>Backers</b> are individuals who have contributed various amounts of money in order to help support webpack. Every little bit helps, and we appreciate even the smallest contributions. This list shows {random} randomly chosen backers:
86108
</p>
87109
) : rank === 'latest' ? (
88-
<p>The following persons/organizations made their first donation in the last {Math.round(maxAge / (1000 * 60 * 60 * 24))} days.</p>
110+
<p>The following persons/organizations made their first donation in the last {Math.round(maxAge / (1000 * 60 * 60 * 24))} days (limited to the top {limit}).</p>
89111
) : (
90112
<p>
91113
<b className="support__rank">{ rank } sponsors</b>

0 commit comments

Comments
 (0)