// @flow import React, { useState } from 'react'; import FileSelector from 'component/common/file-selector'; import Button from 'component/button'; import FileThumbnail from 'component/fileThumbnail'; import * as MODALS from 'constants/modal_types'; import { serializeFileObj } from 'util/file'; type Props = { uploadItem: FileUploadItem, doPublishResume: (any) => void, doUpdateUploadRemove: (any) => void, doOpenModal: (string, {}) => void, }; export default function WebUploadItem(props: Props) { const { uploadItem, doPublishResume, doUpdateUploadRemove, doOpenModal } = props; const { params, file, fileFingerprint, progress, status, tusUploader } = uploadItem; const [showFileSelector, setShowFileSelector] = useState(false); function handleFileChange(newFile: WebFile, clearName = true) { if (serializeFileObj(newFile) === fileFingerprint) { setShowFileSelector(false); doPublishResume({ ...params, file_path: newFile }); } else { doOpenModal(MODALS.CONFIRM, { title: __('Invalid file'), subtitle: __('It appears to be a different or modified file.'), body:
{__('Please select the same file from the initial upload.')}
, onConfirm: (closeModal) => closeModal(), hideCancel: true, }); } } function handleCancel() { doOpenModal(MODALS.CONFIRM, { title: __('Cancel upload'), subtitle: __('Cancel and remove the selected upload?'), body: params.name ?{`lbry://${params.name}`}
: undefined, onConfirm: (closeModal) => { if (tusUploader) { tusUploader.abort(true); } doUpdateUploadRemove(params); closeModal(); }, }); } function resolveProgressStr() { if (!tusUploader) { return __('Stopped.'); } else if (status) { switch (status) { case 'retry': return __('Retrying...'); case 'error': return __('Failed.'); default: return status; } } else { const progressInt = parseInt(progress); return progressInt === 100 ? __('Processing...') : __('Uploading...'); } } function getRetryButton() { if (!tusUploader) { const isFileActive = file instanceof File; return (