// @flow import * as MODALS from 'constants/modal_types'; import { Lbry, THUMBNAIL_STATUSES } from 'lbry-redux'; import { DOMAIN } from 'config'; import * as React from 'react'; import { FormField } from 'component/common/form'; import FileSelector from 'component/common/file-selector'; import Button from 'component/button'; import ThumbnailMissingImage from './thumbnail-missing.png'; import ThumbnailBrokenImage from './thumbnail-broken.png'; type Props = { filePath: ?string, fileInfos: { [string]: FileListItem }, myClaimForUri: ?StreamClaim, thumbnail: ?string, formDisabled: boolean, uploadThumbnailStatus: string, thumbnailPath: ?string, thumbnailError: ?string, openModal: (id: string, {}) => void, updatePublishForm: ({}) => void, resetThumbnailStatus: () => void, }; class SelectThumbnail extends React.PureComponent { constructor() { super(); (this: any).handleThumbnailChange = this.handleThumbnailChange.bind(this); } handleThumbnailChange(e: SyntheticInputEvent<*>) { const { updatePublishForm } = this.props; const newThumbnail = e.target.value.replace(' ', ''); updatePublishForm({ thumbnail: newThumbnail, thumbnailError: newThumbnail.startsWith('data:image'), }); } render() { const { filePath, fileInfos, myClaimForUri, thumbnail, formDisabled, uploadThumbnailStatus: status, openModal, updatePublishForm, thumbnailPath, thumbnailError, resetThumbnailStatus, } = this.props; const accept = '.png, .jpg, .jpeg, .gif'; const outpoint = myClaimForUri ? `${myClaimForUri.txid}:${myClaimForUri.nout}` : undefined; const fileInfo = outpoint ? fileInfos[outpoint] : undefined; const downloadPath = fileInfo ? fileInfo.download_path : undefined; const actualFilePath = filePath || downloadPath; let isSupportedVideo = false; if (typeof actualFilePath === 'string') { isSupportedVideo = Lbry.getMediaType(null, actualFilePath) === 'video'; } else if (actualFilePath && actualFilePath.type) { isSupportedVideo = actualFilePath.type.split('/')[0] === 'video'; } let thumbnailSrc; if (!thumbnail) { thumbnailSrc = ThumbnailMissingImage; } else if (thumbnailError) { thumbnailSrc = ThumbnailBrokenImage; } else { thumbnailSrc = thumbnail; } /* Note: We are using backgroundImage instead of an to zoom if the selected thumbnail isn't the proper aspect ratio. This is to avoid blackbars on the side of images and inconsistent thumbnails We still need to render the image to see if there is an error loading the url */ return (
{status === THUMBNAIL_STATUSES.API_DOWN || status === THUMBNAIL_STATUSES.MANUAL ? (
{__('Thumbnail { updatePublishForm({ thumbnailError: true }); }} />
) : ( {status === THUMBNAIL_STATUSES.READY && ( openModal(MODALS.CONFIRM_THUMBNAIL_UPLOAD, { file })} /> )} {status === THUMBNAIL_STATUSES.COMPLETE && thumbnail && (
{__('This will be visible in a few minutes.')}

{__('Upload complete.')}

)}
)} {status === THUMBNAIL_STATUSES.READY && (
)} {status === THUMBNAIL_STATUSES.IN_PROGRESS &&

{__('Uploading thumbnail')}...

} {status !== THUMBNAIL_STATUSES.COMPLETE && (

{status === THUMBNAIL_STATUSES.API_DOWN ? __('Enter a URL for your thumbnail.') : __('Upload your thumbnail to %domain%. Recommended size is 16:9.', { domain: DOMAIN })}

)}
); } } export default SelectThumbnail;