|
1 | 1 | // Import External Dependencies |
2 | 2 | import React from 'react'; |
| 3 | +import VisibilitySensor from 'react-visibility-sensor'; |
3 | 4 |
|
4 | 5 | // Import Data |
5 | 6 | import Backers from './_supporters.json'; |
@@ -62,8 +63,22 @@ function formatMoney(number) { |
62 | 63 | } |
63 | 64 |
|
64 | 65 | export default class Support extends React.Component { |
| 66 | + constructor(props) { |
| 67 | + super(props); |
| 68 | + this.state = { |
| 69 | + isVisible: false |
| 70 | + }; |
| 71 | + } |
| 72 | + |
| 73 | + onChange = (isVisible) => { |
| 74 | + if (!this.state.isVisible && isVisible) { |
| 75 | + this.setState({ isVisible }); |
| 76 | + } |
| 77 | + } |
| 78 | + |
65 | 79 | render() { |
66 | 80 | let { rank } = this.props; |
| 81 | + let { isVisible } = this.state; |
67 | 82 |
|
68 | 83 | let supporters = SUPPORTERS; |
69 | 84 | let minimum, maximum, maxAge, limit, random; |
@@ -108,45 +123,50 @@ export default class Support extends React.Component { |
108 | 123 | } |
109 | 124 |
|
110 | 125 | return ( |
111 | | - <div className="support"> |
112 | | - <div className="support__description"> |
113 | | - { rank === 'backer' ? ( |
114 | | - <p> |
115 | | - 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: |
116 | | - </p> |
117 | | - ) : rank === 'latest' ? ( |
118 | | - <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> |
119 | | - ) : ( |
120 | | - <p> |
121 | | - <b className="support__rank">{ rank } sponsors</b> |
122 | | - <span>are those who have pledged { minimum ? `$${formatMoney(minimum)}` : 'up' } { maximum ? `to $${formatMoney(maximum)}` : 'or more' } to webpack.</span> |
123 | | - </p> |
124 | | - )} |
125 | | - </div> |
126 | | - |
127 | | - { |
128 | | - supporters.map((supporter, index) => ( |
129 | | - <a key={ supporter.id || supporter.slug || index } |
130 | | - className="support__item" |
131 | | - title={ `$${formatMoney(supporter.totalDonations / 100)} by ${supporter.name || supporter.slug}` } |
132 | | - target="_blank" |
133 | | - rel="noopener nofollow" |
134 | | - href={ supporter.website || `https://opencollective.com/${supporter.slug}` }> |
135 | | - {<img |
136 | | - className={ `support__${rank}-avatar` } |
137 | | - src={ supporter.avatar || SmallIcon } |
138 | | - alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' } |
139 | | - onError={ this._handleImgError } />} |
| 126 | + <VisibilitySensor partialVisibility |
| 127 | + intervalCheck |
| 128 | + intervalDelay={ 250 } |
| 129 | + onChange={ this.onChange }> |
| 130 | + <div className="support"> |
| 131 | + <div className="support__description"> |
| 132 | + { rank === 'backer' ? ( |
| 133 | + <p> |
| 134 | + 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: |
| 135 | + </p> |
| 136 | + ) : rank === 'latest' ? ( |
| 137 | + <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> |
| 138 | + ) : ( |
| 139 | + <p> |
| 140 | + <b className="support__rank">{ rank } sponsors</b> |
| 141 | + <span>are those who have pledged { minimum ? `$${formatMoney(minimum)}` : 'up' } { maximum ? `to $${formatMoney(maximum)}` : 'or more' } to webpack.</span> |
| 142 | + </p> |
| 143 | + )} |
| 144 | + </div> |
| 145 | + |
| 146 | + { |
| 147 | + supporters.map((supporter, index) => ( |
| 148 | + <a key={ supporter.id || supporter.slug || index } |
| 149 | + className="support__item" |
| 150 | + title={ `$${formatMoney(supporter.totalDonations / 100)} by ${supporter.name || supporter.slug}` } |
| 151 | + target="_blank" |
| 152 | + rel="noopener nofollow" |
| 153 | + href={ supporter.website || `https://opencollective.com/${supporter.slug}` }> |
| 154 | + {<img |
| 155 | + className={ `support__${rank}-avatar` } |
| 156 | + src={ (isVisible && supporter.avatar) ? supporter.avatar : SmallIcon } |
| 157 | + alt={ supporter.name || supporter.slug ? `${supporter.name || supporter.slug}'s avatar` : 'avatar' } |
| 158 | + onError={ this._handleImgError } />} |
| 159 | + </a> |
| 160 | + )) |
| 161 | + } |
| 162 | + |
| 163 | + <div className="support__bottom"> |
| 164 | + <a className="support__button" href="https://opencollective.com/webpack#support"> |
| 165 | + Become a { rank === 'backer' ? 'backer' : 'sponsor' } |
140 | 166 | </a> |
141 | | - )) |
142 | | - } |
143 | | - |
144 | | - <div className="support__bottom"> |
145 | | - <a className="support__button" href="https://opencollective.com/webpack#support"> |
146 | | - Become a { rank === 'backer' ? 'backer' : 'sponsor' } |
147 | | - </a> |
| 167 | + </div> |
148 | 168 | </div> |
149 | | - </div> |
| 169 | + </VisibilitySensor> |
150 | 170 | ); |
151 | 171 | } |
152 | 172 |
|
|
0 commit comments