2019-06-20 19:37:28 +07:00
|
|
|
import React, { ReactElement } from 'react';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItem from '@material-ui/core/ListItem';
|
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 NoItems from '../NoItems';
|
2019-02-03 17:23:33 +07:00
|
|
|
import { formatDateDistance } from '../../utils/package';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
import { Heading, Spacer, ListItemText } from './styles';
|
|
|
|
|
2019-06-22 16:43:59 +07:00
|
|
|
class UpLinks extends React.PureComponent<{}> {
|
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 &&
|
|
|
|
context.packageMeta &&
|
|
|
|
context.packageMeta._uplinks &&
|
|
|
|
context.packageMeta.latest &&
|
|
|
|
this.renderContent(context.packageMeta._uplinks, context.packageMeta.latest)
|
|
|
|
);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
public renderUpLinksList = uplinks => (
|
2019-02-03 17:23:33 +07:00
|
|
|
<List>
|
|
|
|
{Object.keys(uplinks)
|
|
|
|
.reverse()
|
|
|
|
.map(name => (
|
|
|
|
<ListItem key={name}>
|
|
|
|
<ListItemText>{name}</ListItemText>
|
|
|
|
<Spacer />
|
|
|
|
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
|
|
|
|
</ListItem>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
public renderContent(uplinks, { name }): ReactElement<HTMLElement> {
|
2019-03-28 05:39:06 +07:00
|
|
|
if (Object.keys(uplinks).length > 0) {
|
|
|
|
return (
|
|
|
|
uplinks && (
|
|
|
|
<>
|
2019-06-20 19:37:28 +07:00
|
|
|
<Heading variant="subheading">{'Uplinks'}</Heading>
|
2019-03-28 05:39:06 +07:00
|
|
|
{this.renderUpLinksList(uplinks)}
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return <NoItems text={`${name} has no uplinks.`} />;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default UpLinks;
|