2019-12-03 15:44:44 +07:00
|
|
|
import React from 'react';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
|
|
|
import { isURL } from '../../utils/url';
|
|
|
|
import Box from '../../muiComponents/Box';
|
2019-07-28 15:25:22 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
import ActionBarAction, { ActionBarActionProps } from './ActionBarAction';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
/* eslint-disable verdaccio/jsx-spread */
|
|
|
|
const ActionBar: React.FC = () => {
|
|
|
|
const detailContext = React.useContext(DetailContext);
|
2019-07-28 15:25:22 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
const { packageMeta } = detailContext;
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
if (!packageMeta?.latest) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
const { homepage, bugs, dist } = packageMeta.latest;
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
const actions: Array<ActionBarActionProps> = [];
|
2019-08-31 16:02:46 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
if (homepage && isURL(homepage)) {
|
|
|
|
actions.push({ type: 'VISIT_HOMEPAGE', link: homepage });
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
if (bugs?.url && isURL(bugs.url)) {
|
|
|
|
actions.push({ type: 'OPEN_AN_ISSUE', link: bugs.url });
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
if (dist?.tarball && isURL(dist.tarball)) {
|
|
|
|
actions.push({ type: 'DOWNLOAD_TARBALL', link: dist.tarball });
|
|
|
|
}
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
return (
|
|
|
|
<Box alignItems="center" display="flex" marginBottom="8px">
|
|
|
|
{actions.map(action => (
|
|
|
|
<ActionBarAction key={action.link} {...action} />
|
|
|
|
))}
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
export default ActionBar;
|