Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit bdef686

Browse files
anikethsahajuanpicado
authored andcommitted
feat: added download tarball button at list (#237)
* chore: added download button at packagelist * feat: added download btn in package list
1 parent 84257e1 commit bdef686

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/components/Package/Package.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import BugReport from '@material-ui/icons/BugReport';
3+
import DownloadIcon from '@material-ui/icons/CloudDownload';
34
import HomeIcon from '@material-ui/icons/Home';
45

56
import { PackageMetaInterface, Author as PackageAuthor } from '../../../types/packageMeta';
@@ -8,6 +9,7 @@ import fileSizeSI from '../../utils/file-size';
89
import { formatDate, formatDateDistance } from '../../utils/package';
910
import Tooltip from '../../muiComponents/Tooltip';
1011
import { isURL } from '../../utils/url';
12+
import { downloadHandler } from '../ActionBar/ActionBar';
1113
import ListItem from '../../muiComponents/ListItem';
1214
import Grid from '../../muiComponents/Grid';
1315

@@ -34,6 +36,7 @@ interface Bugs {
3436
}
3537
interface Dist {
3638
unpackedSize: number;
39+
tarball: string;
3740
}
3841

3942
export interface PackageInterface {
@@ -132,6 +135,21 @@ const Package: React.FC<PackageInterface> = ({
132135
</a>
133136
);
134137

138+
const renderDownloadLink = (): React.ReactNode =>
139+
dist &&
140+
dist.tarball &&
141+
isURL(dist.tarball) && (
142+
// eslint-disable-next-line
143+
<a onClick={() => downloadHandler(dist.tarball.replace(`https://registry.npmjs.org/`, window.location.href))} target={'_blank'}>
144+
<Tooltip aria-label={'Download the tar file'} title={'Download tarball'}>
145+
<IconButton aria-label={'Download'}>
146+
{/* eslint-disable-next-line react/jsx-max-depth */}
147+
<DownloadIcon />
148+
</IconButton>
149+
</Tooltip>
150+
</a>
151+
);
152+
135153
const renderPrimaryComponent = (): React.ReactNode => {
136154
return (
137155
<Grid container={true} item={true} xs={12}>
@@ -144,6 +162,7 @@ const Package: React.FC<PackageInterface> = ({
144162
<GridRightAligned item={true} xs={true}>
145163
{renderHomePageLink()}
146164
{renderBugsLink()}
165+
{renderDownloadLink()}
147166
</GridRightAligned>
148167
</Grid>
149168
);

0 commit comments

Comments
 (0)