mirror of
https://github.com/SomboChea/ui
synced 2024-11-05 22:24:27 +07:00
97e8448098
* chore: refactoring version page * refactor: migrate version page to hooks * refactor: Version page better imports * fix: #100 render not found on click item * test: add test for version page * chore: update mocks * test: add scenario for not found package * chore: fix wrong mock path * chore: update mock * chore: add todo list
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import React, { Component, ReactNode, ReactElement } from 'react';
|
|
|
|
import Avatar from '@material-ui/core/Avatar';
|
|
import List from '@material-ui/core/List';
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
|
|
import { DetailContextConsumer } from '../../pages/Version';
|
|
import { Heading, AuthorListItem } from './styles';
|
|
import { isEmail } from '../../utils/url';
|
|
|
|
class Authors extends Component {
|
|
public render(): ReactElement<HTMLElement> {
|
|
return (
|
|
<DetailContextConsumer>
|
|
{context => {
|
|
return context && context.packageMeta && this.renderAuthor(context.packageMeta);
|
|
}}
|
|
</DetailContextConsumer>
|
|
);
|
|
}
|
|
|
|
public renderLinkForMail(email: string, avatarComponent: ReactNode, packageName: string, version: string): ReactElement<HTMLElement> | ReactNode {
|
|
if (!email || isEmail(email) === false) {
|
|
return avatarComponent;
|
|
}
|
|
|
|
return (
|
|
<a href={`mailto:${email}?subject=${packageName}@${version}`} target={'_top'}>
|
|
{avatarComponent}
|
|
</a>
|
|
);
|
|
}
|
|
|
|
public renderAuthor = packageMeta => {
|
|
const { author, name: packageName, version } = packageMeta.latest;
|
|
|
|
if (!author) {
|
|
return null;
|
|
}
|
|
|
|
const avatarComponent = <Avatar alt={author.name} src={author.avatar} />;
|
|
return (
|
|
<List subheader={<Heading variant={'subheading'}>{'Author'}</Heading>}>
|
|
<AuthorListItem>
|
|
{this.renderLinkForMail(author.email, avatarComponent, packageName, version)}
|
|
<ListItemText primary={author.name} />
|
|
</AuthorListItem>
|
|
</List>
|
|
);
|
|
};
|
|
}
|
|
|
|
export default Authors;
|