2019-06-20 19:37:28 +07:00
|
|
|
import React, { Component, ReactNode } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
2019-02-03 17:23:33 +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 { Heading, AuthorListItem } from './styles';
|
2019-05-16 21:25:40 +07:00
|
|
|
import { isEmail } from '../../utils/url';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
class Authors extends Component<any, any> {
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-20 19:37:28 +07:00
|
|
|
{(context: any) => {
|
|
|
|
return context && context.packageMeta && this.renderAuthor(context.packageMeta);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
renderLinkForMail(email: string, avatarComponent: ReactNode, packageName: string, version: string) {
|
2019-05-16 21:25:40 +07:00
|
|
|
if (!email || isEmail(email) === false) {
|
2019-03-28 05:39:06 +07:00
|
|
|
return avatarComponent;
|
|
|
|
}
|
2019-05-16 21:25:40 +07:00
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
return (
|
|
|
|
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
|
|
|
|
{avatarComponent}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
renderAuthor = packageMeta => {
|
2019-03-28 05:39:06 +07:00
|
|
|
const { author, name: packageName, version } = packageMeta.latest;
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
if (!author) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
2019-03-28 05:39:06 +07:00
|
|
|
<List subheader={<Heading variant={'subheading'}>{'Author'}</Heading>}>
|
|
|
|
<AuthorListItem>
|
|
|
|
{this.renderLinkForMail(author.email, avatarComponent, packageName, version)}
|
|
|
|
<ListItemText primary={author.name} />
|
|
|
|
</AuthorListItem>
|
|
|
|
</List>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Authors;
|