// @flow import * as MODALS from 'constants/modal_types'; import { THUMBNAIL_STATUSES } from 'lbry-redux'; 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 = { thumbnail: ?string, formDisabled: boolean, uploadThumbnailStatus: string, thumbnailPath: ?string, openModal: (id: string, {}) => void, updatePublishForm: ({}) => void, resetThumbnailStatus: () => void, }; type State = { thumbnailError: boolean, }; const filters = [ { name: __('Thumbnail Image'), extensions: ['png', 'jpg', 'jpeg', 'gif'], }, ]; class SelectThumbnail extends React.PureComponent { constructor() { super(); this.state = { thumbnailError: false, }; (this: any).handleThumbnailChange = this.handleThumbnailChange.bind(this); } handleThumbnailChange(e: SyntheticInputEvent<*>) { const { updatePublishForm } = this.props; const newThumbnail = e.target.value.replace(' ', ''); updatePublishForm({ thumbnail: newThumbnail }); this.setState({ thumbnailError: false }); } render() { const { thumbnail, formDisabled, uploadThumbnailStatus: status, openModal, updatePublishForm, thumbnailPath, resetThumbnailStatus, } = this.props; const { thumbnailError } = this.state; 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 { this.setState({ thumbnailError: true, }); }} />
) : ( {status === THUMBNAIL_STATUSES.READY && ( openModal(MODALS.CONFIRM_THUMBNAIL_UPLOAD, { path })} /> )} {status === THUMBNAIL_STATUSES.COMPLETE && thumbnail && (

Upload complete.{' '}

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

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

}
); } } export default SelectThumbnail;