import React, { Component, ReactElement } from 'react';
import BugReportIcon from '@material-ui/icons/BugReport';
import DownloadIcon from '@material-ui/icons/CloudDownload';
import HomeIcon from '@material-ui/icons/Home';
import List from '@material-ui/core/List';
import Tooltip from '@material-ui/core/Tooltip';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { Fab, ActionListItem } from './styles';
import { isURL } from '../../utils/url';
const ACTIONS = {
homepage: {
icon: ,
title: 'Visit homepage',
},
issue: {
icon: ,
title: 'Open an issue',
},
tarball: {
icon: ,
title: 'Download tarball',
},
};
class ActionBar extends Component {
public render(): ReactElement {
return (
{context => {
return this.renderActionBar(context as VersionPageConsumerProps);
}}
);
}
private renderIconsWithLink(link: string, component: any): ReactElement {
return (
{component}
);
}
private renderActionBarListItems = packageMeta => {
// @ts-ignore
const { latest: { bugs: { url: issue } = {}, homepage, dist: { tarball } = {} } = {} } = packageMeta;
const actionsMap = {
homepage,
issue,
tarball,
};
const renderList = Object.keys(actionsMap).reduce((component, value, key) => {
const link = actionsMap[value];
if (link && isURL(link)) {
const fab = {ACTIONS[value]['icon']};
component.push(
// @ts-ignore
<>{this.renderIconsWithLink(link, fab)}>
);
}
return component;
}, []);
return (
<>
{renderList}
>
);
};
private renderActionBar = ({ packageMeta = {} }) => {
return {this.renderActionBarListItems(packageMeta)}
;
};
}
export default ActionBar;