2019-10-07 19:13:05 +07:00
|
|
|
import React, { useContext } from 'react';
|
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 03:26:56 +07:00
|
|
|
import List from '../../muiComponents/List';
|
2019-10-13 02:11:23 +07:00
|
|
|
import ListItem from '../../muiComponents/ListItem';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-13 02:41:42 +07:00
|
|
|
import { StyledText, Spacer, ListItemText } from './styles';
|
2019-02-03 17:23:33 +07:00
|
|
|
|
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 (
|
|
|
|
<>
|
2019-10-13 02:41:42 +07:00
|
|
|
<StyledText variant="subtitle1">{'Uplinks'}</StyledText>
|
2019-10-07 19:13:05 +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-02-03 17:23:33 +07:00
|
|
|
|
|
|
|
export default UpLinks;
|