2019-08-25 19:34:27 +07:00
|
|
|
import React, { ReactElement } from 'react';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-12-03 15:44:44 +07:00
|
|
|
import ActionBar from '../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-10-13 03:26:56 +07:00
|
|
|
import List from '../../muiComponents/List';
|
2019-10-26 13:44:25 +07:00
|
|
|
import Card from '../../muiComponents/Card';
|
2019-10-31 14:12:18 +07:00
|
|
|
import CardContent from '../../muiComponents/CardContent';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-10-05 04:19:50 +07:00
|
|
|
import { TitleListItem, TitleListItemText, PackageDescription, PackageVersion } from './styles';
|
2019-06-20 19:37:28 +07:00
|
|
|
|
2019-10-27 21:49:30 +07:00
|
|
|
const renderLatestDescription = (description, version, isLatest = true): JSX.Element => {
|
2019-09-01 18:09:23 +07:00
|
|
|
return (
|
2019-10-05 04:19:50 +07:00
|
|
|
<>
|
|
|
|
<PackageDescription>{description}</PackageDescription>
|
|
|
|
{version ? (
|
|
|
|
<PackageVersion>
|
|
|
|
<small>{`${isLatest ? 'Latest v' : 'v'}${version}`}</small>
|
|
|
|
</PackageVersion>
|
|
|
|
) : null}
|
|
|
|
</>
|
2019-09-01 18:09:23 +07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-10-03 02:52:27 +07:00
|
|
|
const renderCopyCLI = (): JSX.Element => <Install />;
|
|
|
|
const renderMaintainers = (): JSX.Element => <Developers type="maintainers" />;
|
|
|
|
const renderContributors = (): JSX.Element => <Developers type="contributors" />;
|
|
|
|
const renderRepository = (): JSX.Element => <Repository />;
|
|
|
|
const renderAuthor = (): JSX.Element => <Author />;
|
|
|
|
const renderEngine = (): JSX.Element => <Engine />;
|
|
|
|
const renderDist = (): JSX.Element => <Dist />;
|
|
|
|
const renderActionBar = (): JSX.Element => <ActionBar />;
|
|
|
|
const renderTitle = (packageName, packageVersion, packageMeta): JSX.Element => {
|
2019-09-01 18:09:23 +07:00
|
|
|
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-10-27 21:49:30 +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-10-03 02:52:27 +07:00
|
|
|
const DetailSidebar = (): JSX.Element => {
|
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;
|