1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-06-26 21:15:32 +07:00
verdaccio-ui/src/webui/components/Author/index.js

58 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-03-28 05:39:06 +07:00
/**
* @prettier
*/
2019-02-03 17:23:33 +07:00
2019-03-28 05:39:06 +07:00
import React, { Component } from 'react';
2019-02-03 17:23:33 +07:00
2019-03-28 05:39:06 +07:00
import Avatar from '@material-ui/core/Avatar/index';
import List from '@material-ui/core/List/index';
import ListItemText from '@material-ui/core/ListItemText/index';
import { DetailContextConsumer } from '../../pages/version/index';
import { Heading, AuthorListItem } from './styles';
import { isEmail } from '../../utils/url';
2019-02-03 17:23:33 +07:00
class Authors extends Component<any, any> {
render() {
return (
<DetailContextConsumer>
2019-03-28 05:39:06 +07:00
{context => {
2019-02-03 17:23:33 +07:00
return this.renderAuthor(context);
}}
</DetailContextConsumer>
);
}
2019-03-28 05:39:06 +07:00
renderLinkForMail(email, avatarComponent, packageName, version) {
if (!email || isEmail(email) === false) {
2019-03-28 05:39:06 +07:00
return avatarComponent;
}
2019-03-28 05:39:06 +07:00
return (
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
{avatarComponent}
</a>
);
}
renderAuthor = ({ packageMeta }) => {
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;