// @flow import * as ICONS from 'constants/icons'; import * as MODALS from 'constants/modal_types'; import React from 'react'; import Button from 'component/button'; type Props = { uri: string, claim: StreamClaim, claimIsMine: boolean, downloading: boolean, loading: boolean, focusable: boolean, fileInfo: ?FileListItem, openModal: (id: string, { path: string }) => void, pause: () => void, download: (string) => void, costInfo: ?{ cost: string }, buttonType: ?string, showLabel: ?boolean, hideOpenButton: boolean, hideDownloadStatus: boolean, streamingUrl: ?string, }; function FileDownloadLink(props: Props) { const { fileInfo, downloading, loading, openModal, pause, claimIsMine, download, uri, claim, buttonType, focusable = true, showLabel = false, hideOpenButton = false, hideDownloadStatus = false, } = props; function handleDownload(e) { e.preventDefault(); download(uri); } if (!claim) { return null; } // @if TARGET='app' if (downloading || loading) { if (hideDownloadStatus) { return null; } if (fileInfo && fileInfo.written_bytes > 0) { const progress = (fileInfo.written_bytes / fileInfo.total_bytes) * 100; return {__('%percent%% downloaded', { percent: progress.toFixed(0) })}; } else { return {__('Connecting...')}; } } // @endif if (fileInfo && fileInfo.download_path && fileInfo.completed) { const openLabel = __('Open file'); return hideOpenButton ? null : (