Skip to content

Commit d2e5324

Browse files
committed
refactor(support): clean up support component and fetch actual json from opencollective
Fetching the actual JSON containing our supporters gives us more flexibility to tackle issues like #411. It also give a model to follow for our, now extracted, additional sponsors list (those not from open collective).
1 parent a93a55f commit d2e5324

File tree

3 files changed

+106
-65
lines changed

3 files changed

+106
-65
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"id": 20000,
4+
"name": "MoonMail",
5+
"username": "moonmail",
6+
"tier": "sponsor",
7+
"avatar": "https://static.moonmail.io/moonmail-logo.svg",
8+
"website": "https://moonmail.io/?utm_source=webpack.js.org"
9+
},
10+
{
11+
"index": 20001,
12+
"name": "MONEI",
13+
"username": "monei",
14+
"tier": "sponsor",
15+
"avatar": "https://static.monei.net/monei-logo.svg",
16+
"website": "https://monei.net/?utm_source=webpack.js.org"
17+
}
18+
]

components/support/support-style.scss

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,52 @@
44
display: flex;
55
flex-wrap: wrap;
66
justify-content: center;
7-
padding:10px 5px;
7+
padding: 1em 0.5em;
88

99
&__item {
10-
margin:0 5px;
10+
position: relative;
11+
margin: 0 5px 5px 5px;
12+
}
13+
14+
&__sponsors-avatar {
15+
height: 64px;
16+
}
17+
18+
&__backers-avatar {
19+
width: 62px;
20+
height: 62px;
21+
border-radius: 50%;
22+
border: 2px solid white;
23+
overflow: hidden;
24+
}
25+
26+
&__outline {
27+
position: absolute;
28+
top: 0;
29+
margin: -2px;
30+
width: calc(100% + 4px);
31+
height: calc(100% - 2px);
32+
border-radius: 50%;
33+
border: 2px solid rgb(112, 202, 10);
1134
}
1235

1336
&__bottom {
14-
flex:0 0 100%;
15-
margin-top:10px;
37+
flex: 0 0 100%;
38+
margin-top: 1em;
1639
}
1740

1841
&__button {
19-
display:inline-block;
20-
padding:0.4em 1em;
21-
border:2px solid getColor(denim);
22-
color:getColor(denim);
23-
border-radius:1.25em;
24-
transition:all 250ms;
42+
display: inline-block;
43+
padding: 0.4em 1em;
44+
text-transform: uppercase;
45+
color: getColor(denim);
46+
border: 1px solid getColor(denim);
47+
border-radius: 1.25em;
48+
transition: all 250ms;
2549

2650
&:hover {
27-
background:getColor(denim);
28-
color:getColor(white);
51+
background: getColor(denim);
52+
color: getColor(white);
2953
}
3054
}
31-
&__missing {
32-
display: flex;
33-
align-items: center;
34-
}
35-
}
55+
}

components/support/support.jsx

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import Additional from './support-additional.json';
4+
import 'whatwg-fetch';
25
import './support-style';
36

4-
const MISSING_SPONSORS = [
5-
{
6-
index: 33,
7-
name: 'MoonMail',
8-
title: 'Email Marketing Software',
9-
logo: 'https://static.moonmail.io/moonmail-logo.svg',
10-
url: 'https://moonmail.io/?utm_source=webpack.js.org'
11-
},
12-
{
13-
index: 34,
14-
name: 'MONEI',
15-
title: 'Best payment gateway rates',
16-
logo: 'https://static.monei.net/monei-logo.svg',
17-
url: 'https://monei.net/?utm_source=webpack.js.org'
7+
export default class Support extends React.Component {
8+
static propTypes = {
9+
number: PropTypes.number.isRequired,
10+
type: PropTypes.oneOf([
11+
'sponsors',
12+
'backers'
13+
]).isRequired
14+
};
15+
16+
state = {
17+
supporters: [],
18+
error: false
1819
}
19-
];
2020

21-
export default ({number, type}) => {
22-
const supportItems = [...Array(number)].map((x, i) =>
23-
<a key={ i }
24-
className="support__item"
25-
href={ `https://opencollective.com/webpack/${type}/${i}/website?requireActive=false` }
26-
target="_blank">
27-
<img
28-
src={ `//opencollective.com/webpack/${type}/${i}/avatar?requireActive=false` }
29-
alt={ `${type} avatar` } />
30-
</a>
31-
);
21+
render() {
22+
let { number, type } = this.props;
23+
let { supporters } = this.state;
24+
25+
return (
26+
<div className="support">
27+
{
28+
supporters.slice(0, number).map((supporter, i) => (
29+
<a key={ supporter.id }
30+
className="support__item"
31+
target="_blank"
32+
href={ supporter.website }>
33+
<img
34+
className={ `support__${type}-avatar` }
35+
src={ supporter.avatar }
36+
alt={ `${supporter.username}'s avatar` } />
37+
{ type === 'backers' ? <figure className="support__outline" /> : null }
38+
</a>
39+
))
40+
}
3241

33-
// add missing sponsors
34-
if (type === 'sponsor') {
35-
MISSING_SPONSORS.forEach(sponsor => {
36-
supportItems.splice(sponsor.index, 0, (
37-
<a key={ sponsor.name }
38-
className="support__item support__missing"
39-
href={ sponsor.url }
40-
target="_blank"
41-
title={ sponsor.title }>
42-
<img
43-
src={ sponsor.logo }
44-
height={ 45 }
45-
alt={ sponsor.name } />
46-
</a>
47-
));
48-
});
42+
<div className="support__bottom">
43+
<a className="support__button" href="https://opencollective.com/webpack#support">
44+
Become a { type.replace(/s$/, '') }
45+
</a>
46+
</div>
47+
</div>
48+
);
4949
}
5050

51-
return (
52-
<div className="support">
53-
{supportItems}
54-
</div>
55-
);
56-
};
51+
componentDidMount() {
52+
let { type } = this.props;
53+
54+
fetch(`https://opencollective.com/webpack/${type}.json`)
55+
.then(response => response.json())
56+
.then(json => this.setState({ supporters: json.concat(Additional) }))
57+
.catch(error => this.setState({ error: true }));
58+
}
59+
}

0 commit comments

Comments
 (0)