From bdef686914863fdef0ca51b29627aad6b9ac6982 Mon Sep 17 00:00:00 2001 From: Anix Date: Thu, 7 Nov 2019 22:41:08 +0530 Subject: [PATCH] feat: added download tarball button at list (#237) * chore: added download button at packagelist * feat: added download btn in package list --- src/components/Package/Package.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/components/Package/Package.tsx b/src/components/Package/Package.tsx index 3a3981d..43cb21d 100644 --- a/src/components/Package/Package.tsx +++ b/src/components/Package/Package.tsx @@ -1,5 +1,6 @@ import React from 'react'; import BugReport from '@material-ui/icons/BugReport'; +import DownloadIcon from '@material-ui/icons/CloudDownload'; import HomeIcon from '@material-ui/icons/Home'; import { PackageMetaInterface, Author as PackageAuthor } from '../../../types/packageMeta'; @@ -8,6 +9,7 @@ import fileSizeSI from '../../utils/file-size'; import { formatDate, formatDateDistance } from '../../utils/package'; import Tooltip from '../../muiComponents/Tooltip'; import { isURL } from '../../utils/url'; +import { downloadHandler } from '../ActionBar/ActionBar'; import ListItem from '../../muiComponents/ListItem'; import Grid from '../../muiComponents/Grid'; @@ -34,6 +36,7 @@ interface Bugs { } interface Dist { unpackedSize: number; + tarball: string; } export interface PackageInterface { @@ -132,6 +135,21 @@ const Package: React.FC = ({ ); + const renderDownloadLink = (): React.ReactNode => + dist && + dist.tarball && + isURL(dist.tarball) && ( + // eslint-disable-next-line + downloadHandler(dist.tarball.replace(`https://registry.npmjs.org/`, window.location.href))} target={'_blank'}> + + + {/* eslint-disable-next-line react/jsx-max-depth */} + + + + + ); + const renderPrimaryComponent = (): React.ReactNode => { return ( @@ -144,6 +162,7 @@ const Package: React.FC = ({ {renderHomePageLink()} {renderBugsLink()} + {renderDownloadLink()} );