2019-10-07 19:13:05 +07:00
|
|
|
import React, { 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-07 19:13:05 +07:00
|
|
|
import { DetailContext } from '../../pages/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-10-13 02:11:23 +07:00
|
|
|
import ListItem from '../../muiComponents/ListItem';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
import { Heading, Spacer, ListItemText } from './styles';
|
|
|
|
|
2019-10-07 19:13:05 +07:00
|
|
|
const UpLinks: React.FC = () => {
|
|
|
|
const { packageMeta } = useContext(DetailContext);
|
|
|
|
|
|
|
|
if (!packageMeta || !packageMeta._uplinks || !packageMeta.latest) {
|
|
|
|
return null;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
2019-10-07 19:13:05 +07:00
|
|
|
const { _uplinks: uplinks, latest } = packageMeta;
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-10-07 19:13:05 +07:00
|
|
|
if (Object.keys(uplinks).length === 0) {
|
|
|
|
return <NoItems text={`${latest.name} has no uplinks.`} />;
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
2019-10-07 19:13:05 +07:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Heading variant="subtitle1">{'Uplinks'}</Heading>
|
|
|
|
<List>
|
|
|
|
{Object.keys(uplinks)
|
|
|
|
.reverse()
|
|
|
|
.map(name => (
|
|
|
|
<ListItem key={name}>
|
|
|
|
<ListItemText>{name}</ListItemText>
|
|
|
|
<Spacer />
|
|
|
|
<ListItemText>{`${formatDateDistance(uplinks[name].fetched)} ago`}</ListItemText>
|
|
|
|
</ListItem>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
export default UpLinks;
|