2019-04-09 03:29:20 +07:00
|
|
|
import React, { Component } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import Add from '@material-ui/icons/Add';
|
2019-04-09 03:29:20 +07:00
|
|
|
import Tooltip from '@material-ui/core/Tooltip';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { DetailContextConsumer } from '../../pages/version/Version';
|
2019-03-28 05:39:06 +07:00
|
|
|
import { Details, Heading, Content, Fab } from './styles';
|
2019-05-16 21:25:40 +07:00
|
|
|
import { isEmail } from '../../utils/url';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
interface Props {
|
2019-04-09 03:29:20 +07:00
|
|
|
type: 'contributors' | 'maintainers';
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
class Developers extends Component<Props, any> {
|
2019-06-25 04:03:21 +07:00
|
|
|
public state = {
|
2019-02-03 17:23:33 +07:00
|
|
|
visibleDevs: 6,
|
|
|
|
};
|
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
public render(): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-20 19:37:28 +07:00
|
|
|
{({ packageMeta }: any) => {
|
2019-02-03 17:23:33 +07:00
|
|
|
const { type } = this.props;
|
|
|
|
const developerType = packageMeta.latest[type];
|
|
|
|
if (!developerType || developerType.length === 0) return null;
|
2019-03-28 05:39:06 +07:00
|
|
|
return this.renderDevelopers(developerType, packageMeta);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
2019-04-09 03:29:20 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-25 04:03:21 +07:00
|
|
|
public handleLoadMore = () => {
|
2019-04-09 03:29:20 +07:00
|
|
|
this.setState(prev => ({ visibleDevs: prev.visibleDevs + 6 }));
|
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-06-25 04:03:21 +07:00
|
|
|
private renderDevelopers = (developers, packageMeta) => {
|
2019-02-03 17:23:33 +07:00
|
|
|
const { type } = this.props;
|
|
|
|
const { visibleDevs } = this.state;
|
|
|
|
return (
|
2019-03-28 05:39:06 +07:00
|
|
|
<>
|
|
|
|
<Heading variant={'subheading'}>{type}</Heading>
|
|
|
|
<Content>
|
|
|
|
{developers.slice(0, visibleDevs).map(developer => (
|
|
|
|
<Details key={developer.email}>{this.renderDeveloperDetails(developer, packageMeta)}</Details>
|
|
|
|
))}
|
2019-04-09 03:29:20 +07:00
|
|
|
{visibleDevs < developers.length && (
|
2019-06-20 19:37:28 +07:00
|
|
|
<Fab onClick={this.handleLoadMore} size="small">
|
2019-04-09 03:29:20 +07:00
|
|
|
<Add />
|
|
|
|
</Fab>
|
|
|
|
)}
|
2019-03-28 05:39:06 +07:00
|
|
|
</Content>
|
|
|
|
</>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-04-09 03:29:20 +07:00
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-25 05:01:13 +07:00
|
|
|
private renderLinkForMail(email, avatarComponent, packageName, version): JSX.Element {
|
2019-05-16 21:25:40 +07:00
|
|
|
if (!email || isEmail(email) === false) {
|
2019-03-28 05:39:06 +07:00
|
|
|
return avatarComponent;
|
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
2019-04-09 03:29:20 +07:00
|
|
|
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
|
2019-03-28 05:39:06 +07:00
|
|
|
{avatarComponent}
|
|
|
|
</a>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 04:03:21 +07:00
|
|
|
private renderDeveloperDetails = ({ name, avatar, email }, packageMeta) => {
|
2019-04-09 03:29:20 +07:00
|
|
|
const { name: packageName, version } = packageMeta.latest;
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-04-09 03:29:20 +07:00
|
|
|
const avatarComponent = <Avatar aria-label={name} src={avatar} />;
|
|
|
|
return <Tooltip title={name}>{this.renderLinkForMail(email, avatarComponent, packageName, version)}</Tooltip>;
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Developers;
|