2019-02-03 17:23:33 +07:00
|
|
|
/* eslint react/jsx-max-depth: 0 */
|
|
|
|
|
2019-10-08 03:19:18 +07:00
|
|
|
import React, { Component, Fragment, ReactElement } from 'react';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-08 03:19:18 +07:00
|
|
|
import Avatar from '../../muiComponents/Avatar';
|
2019-08-25 19:34:27 +07:00
|
|
|
import { DetailContextConsumer } from '../../pages/Version';
|
2019-10-08 03:19:18 +07:00
|
|
|
import { isURL } from '../../utils/url';
|
2019-02-03 17:23:33 +07:00
|
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
2019-10-13 03:26:56 +07:00
|
|
|
import List from '../../muiComponents/List';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
import git from './img/git.png';
|
2019-10-13 02:41:42 +07:00
|
|
|
import { GithubLink, StyledText, RepositoryListItem, RepositoryListItemText } from './styles';
|
2019-10-06 23:30:05 +07:00
|
|
|
|
2019-06-22 16:43:59 +07:00
|
|
|
class Repository extends Component {
|
2019-06-20 19:37:28 +07:00
|
|
|
public render(): ReactElement<HTMLElement> {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-20 19:37:28 +07:00
|
|
|
{context => {
|
|
|
|
return context && context.packageMeta && this.renderRepository(context.packageMeta);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
2019-06-20 19:37:28 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderRepositoryText(url: string): ReactElement<HTMLElement> {
|
|
|
|
return (
|
|
|
|
<GithubLink href={url} target="_blank">
|
|
|
|
{url}
|
|
|
|
</GithubLink>
|
|
|
|
);
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
private renderRepository = packageMeta => {
|
2019-06-22 16:43:59 +07:00
|
|
|
const { repository: { url = null } = {} } = packageMeta.latest;
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-05-16 21:25:40 +07:00
|
|
|
if (!url || isURL(url) === false) {
|
2019-02-03 17:23:33 +07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-06-20 19:37:28 +07:00
|
|
|
<Fragment>
|
2019-10-13 02:41:42 +07:00
|
|
|
<List dense={true} subheader={<StyledText variant="subtitle1">{'Repository'}</StyledText>}>
|
2019-08-31 16:02:46 +07:00
|
|
|
<RepositoryListItem button={true}>
|
2019-03-28 05:39:06 +07:00
|
|
|
<Avatar src={git} />
|
2019-08-31 16:02:46 +07:00
|
|
|
<RepositoryListItemText primary={this.renderContent(url)} />
|
2019-03-28 05:39:06 +07:00
|
|
|
</RepositoryListItem>
|
|
|
|
</List>
|
2019-06-20 19:37:28 +07:00
|
|
|
</Fragment>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-06-20 19:37:28 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
private renderContent(url: string): ReactElement<HTMLElement> {
|
|
|
|
return <CopyToClipBoard text={url}>{this.renderRepositoryText(url)}</CopyToClipBoard>;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Repository;
|