2019-08-25 19:34:27 +07:00
|
|
|
import React, { ReactElement } from 'react';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
|
|
|
import Card from '@material-ui/core/Card';
|
|
|
|
import CardContent from '@material-ui/core/CardContent';
|
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
|
2019-08-31 16:02:46 +07:00
|
|
|
import { ActionBar } from '../ActionBar/ActionBar';
|
2019-06-20 19:37:28 +07:00
|
|
|
import Author from '../Author';
|
|
|
|
import Developers from '../Developers';
|
|
|
|
import Dist from '../Dist/Dist';
|
|
|
|
import Engine from '../Engines/Engines';
|
|
|
|
import Install from '../Install';
|
|
|
|
import Repository from '../Repository/Repository';
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
|
|
|
import { TitleListItem, TitleListItemText } from './styles';
|
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
const renderLatestDescription = (description, version, isLatest: boolean = true) => {
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
<div>{description}</div>
|
|
|
|
{version ? <small>{`${isLatest ? 'Latest v' : 'v'}${version}`}</small> : null}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
const renderCopyCLI = () => <Install />;
|
|
|
|
const renderMaintainers = () => <Developers type="maintainers" />;
|
|
|
|
const renderContributors = () => <Developers type="contributors" />;
|
|
|
|
const renderRepository = () => <Repository />;
|
|
|
|
const renderAuthor = () => <Author />;
|
|
|
|
const renderEngine = () => <Engine />;
|
|
|
|
const renderDist = () => <Dist />;
|
|
|
|
const renderActionBar = () => <ActionBar />;
|
2019-09-01 18:09:23 +07:00
|
|
|
const renderTitle = (packageName, packageVersion, packageMeta) => {
|
|
|
|
const version = packageVersion ? packageVersion : packageMeta.latest.version;
|
|
|
|
const isLatest = typeof packageVersion === 'undefined';
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
return (
|
|
|
|
<List className="detail-info">
|
2019-08-31 16:02:46 +07:00
|
|
|
<TitleListItem alignItems="flex-start" button={true}>
|
2019-09-01 18:09:23 +07:00
|
|
|
<TitleListItemText primary={<b>{packageName}</b>} secondary={renderLatestDescription(packageMeta.latest.description, version, isLatest)} />
|
2019-08-25 19:34:27 +07:00
|
|
|
</TitleListItem>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
function renderSideBar(packageName, packageVersion, packageMeta): ReactElement<HTMLElement> {
|
2019-08-25 19:34:27 +07:00
|
|
|
return (
|
|
|
|
<div className={'sidebar-info'}>
|
|
|
|
<Card>
|
|
|
|
<CardContent>
|
2019-09-01 18:09:23 +07:00
|
|
|
{renderTitle(packageName, packageVersion, packageMeta)}
|
2019-08-25 19:34:27 +07:00
|
|
|
{renderActionBar()}
|
|
|
|
{renderCopyCLI()}
|
|
|
|
{renderRepository()}
|
|
|
|
{renderEngine()}
|
|
|
|
{renderDist()}
|
|
|
|
{renderAuthor()}
|
|
|
|
{renderMaintainers()}
|
|
|
|
{renderContributors()}
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
const DetailSidebar = () => {
|
2019-09-01 18:09:23 +07:00
|
|
|
const { packageName, packageMeta, packageVersion } = React.useContext(DetailContext);
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-09-01 18:09:23 +07:00
|
|
|
return renderSideBar(packageName, packageVersion, packageMeta);
|
2019-08-25 19:34:27 +07:00
|
|
|
};
|
2019-06-20 19:37:28 +07:00
|
|
|
|
|
|
|
export default DetailSidebar;
|