2019-10-06 20:44:48 +07:00
|
|
|
import React, { FC, useContext } from 'react';
|
2019-06-20 19:37:28 +07:00
|
|
|
import List from '@material-ui/core/List';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
2019-05-16 21:25:40 +07:00
|
|
|
import { isEmail } from '../../utils/url';
|
2019-10-06 23:30:05 +07:00
|
|
|
import Avatar from '../../muiComponents/Avatar';
|
|
|
|
|
2019-10-13 02:41:42 +07:00
|
|
|
import { StyledText, AuthorListItem, AuthorListItemText } from './styles';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-10-06 23:30:05 +07:00
|
|
|
const Author: FC = () => {
|
2019-10-06 20:44:48 +07:00
|
|
|
const { packageMeta } = useContext(DetailContext);
|
|
|
|
|
|
|
|
if (!packageMeta) {
|
|
|
|
return null;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const { author, name: packageName, version } = packageMeta.latest;
|
2019-05-16 21:25:40 +07:00
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
if (!author) {
|
|
|
|
return null;
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
2019-10-06 20:44:48 +07:00
|
|
|
const { email, name } = author;
|
|
|
|
|
|
|
|
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
|
|
|
|
|
|
|
|
return (
|
2019-10-13 02:41:42 +07:00
|
|
|
<List subheader={<StyledText variant={'subtitle1'}>{'Author'}</StyledText>}>
|
2019-10-06 20:44:48 +07:00
|
|
|
<AuthorListItem button={true}>
|
|
|
|
{!email || !isEmail(email) ? (
|
|
|
|
avatarComponent
|
|
|
|
) : (
|
|
|
|
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
|
|
|
|
{avatarComponent}
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<AuthorListItemText primary={name} />
|
|
|
|
</AuthorListItem>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-06 23:30:05 +07:00
|
|
|
export default Author;
|