2018-04-02 18:39:00 +02:00
|
|
|
// @flow
|
2018-10-29 18:23:53 +01:00
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-08-02 08:28:14 +02:00
|
|
|
import { Lbry, THUMBNAIL_STATUSES } from 'lbry-redux';
|
2020-07-22 17:24:51 +02:00
|
|
|
import { DOMAIN } from 'config';
|
2018-07-18 17:46:21 +02:00
|
|
|
import * as React from 'react';
|
|
|
|
import { FormField } from 'component/common/form';
|
2018-04-02 18:39:00 +02:00
|
|
|
import FileSelector from 'component/common/file-selector';
|
2018-06-08 06:05:45 +02:00
|
|
|
import Button from 'component/button';
|
2019-03-05 05:46:57 +01:00
|
|
|
import ThumbnailMissingImage from './thumbnail-missing.png';
|
|
|
|
import ThumbnailBrokenImage from './thumbnail-broken.png';
|
2018-04-02 18:39:00 +02:00
|
|
|
|
|
|
|
type Props = {
|
2019-05-21 23:18:11 +02:00
|
|
|
filePath: ?string,
|
2019-08-29 17:19:37 +02:00
|
|
|
fileInfos: { [string]: FileListItem },
|
|
|
|
myClaimForUri: ?StreamClaim,
|
2018-04-02 18:39:00 +02:00
|
|
|
thumbnail: ?string,
|
|
|
|
formDisabled: boolean,
|
|
|
|
uploadThumbnailStatus: string,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: ?string,
|
2019-01-08 00:29:40 +01:00
|
|
|
openModal: (id: string, {}) => void,
|
2018-04-02 18:39:00 +02:00
|
|
|
updatePublishForm: ({}) => void,
|
2018-06-08 06:05:45 +02:00
|
|
|
resetThumbnailStatus: () => void,
|
2018-04-02 18:39:00 +02:00
|
|
|
};
|
|
|
|
|
2018-07-17 19:43:43 +02:00
|
|
|
type State = {
|
2018-07-18 17:46:21 +02:00
|
|
|
thumbnailError: boolean,
|
|
|
|
};
|
2018-07-17 19:43:43 +02:00
|
|
|
|
|
|
|
class SelectThumbnail extends React.PureComponent<Props, State> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2018-07-18 17:46:21 +02:00
|
|
|
|
2018-07-17 19:43:43 +02:00
|
|
|
this.state = {
|
2018-07-18 17:46:21 +02:00
|
|
|
thumbnailError: false,
|
2018-07-17 19:43:43 +02:00
|
|
|
};
|
2018-07-18 17:46:21 +02:00
|
|
|
|
2018-07-17 19:43:43 +02:00
|
|
|
(this: any).handleThumbnailChange = this.handleThumbnailChange.bind(this);
|
|
|
|
}
|
2018-07-18 17:46:21 +02:00
|
|
|
|
|
|
|
handleThumbnailChange(e: SyntheticInputEvent<*>) {
|
2018-07-17 19:43:43 +02:00
|
|
|
const { updatePublishForm } = this.props;
|
|
|
|
const newThumbnail = e.target.value.replace(' ', '');
|
2018-07-18 17:46:21 +02:00
|
|
|
|
2018-07-17 19:43:43 +02:00
|
|
|
updatePublishForm({ thumbnail: newThumbnail });
|
2019-03-05 05:46:57 +01:00
|
|
|
this.setState({ thumbnailError: false });
|
2018-07-17 19:43:43 +02:00
|
|
|
}
|
2018-07-18 17:46:21 +02:00
|
|
|
|
2018-04-02 18:39:00 +02:00
|
|
|
render() {
|
|
|
|
const {
|
2019-05-21 23:18:11 +02:00
|
|
|
filePath,
|
2019-08-29 17:19:37 +02:00
|
|
|
fileInfos,
|
|
|
|
myClaimForUri,
|
2018-04-02 18:39:00 +02:00
|
|
|
thumbnail,
|
|
|
|
formDisabled,
|
|
|
|
uploadThumbnailStatus: status,
|
|
|
|
openModal,
|
|
|
|
updatePublishForm,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath,
|
|
|
|
resetThumbnailStatus,
|
2018-04-02 18:39:00 +02:00
|
|
|
} = this.props;
|
2019-03-05 05:46:57 +01:00
|
|
|
|
|
|
|
const { thumbnailError } = this.state;
|
2019-10-07 22:02:32 +02:00
|
|
|
const accept = '.png, .jpg, .jpeg, .gif';
|
2019-03-05 05:46:57 +01:00
|
|
|
|
2019-08-29 17:19:37 +02:00
|
|
|
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;
|
2019-10-07 22:02:32 +02:00
|
|
|
let isSupportedVideo = false;
|
2020-04-24 15:51:00 +02:00
|
|
|
if (typeof actualFilePath === 'string') {
|
2019-10-07 22:02:32 +02:00
|
|
|
isSupportedVideo = Lbry.getMediaType(null, actualFilePath) === 'video';
|
2020-04-24 15:51:00 +02:00
|
|
|
} else if (actualFilePath && actualFilePath.type) {
|
|
|
|
isSupportedVideo = actualFilePath.type.split('/')[0] === 'video';
|
2019-10-07 22:02:32 +02:00
|
|
|
}
|
2019-05-21 23:18:11 +02:00
|
|
|
|
2019-03-05 05:46:57 +01:00
|
|
|
let thumbnailSrc;
|
|
|
|
if (!thumbnail) {
|
|
|
|
thumbnailSrc = ThumbnailMissingImage;
|
|
|
|
} else if (thumbnailError) {
|
|
|
|
thumbnailSrc = ThumbnailBrokenImage;
|
|
|
|
} else {
|
|
|
|
thumbnailSrc = thumbnail;
|
|
|
|
}
|
2018-07-18 17:46:21 +02:00
|
|
|
|
2018-09-02 03:49:12 +02:00
|
|
|
/*
|
|
|
|
Note:
|
|
|
|
We are using backgroundImage instead of an <img /> 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
|
|
|
|
*/
|
|
|
|
|
2018-04-02 18:39:00 +02:00
|
|
|
return (
|
2019-07-21 23:31:22 +02:00
|
|
|
<div>
|
2018-06-14 22:28:50 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.API_DOWN || status === THUMBNAIL_STATUSES.MANUAL ? (
|
2018-07-17 19:43:43 +02:00
|
|
|
<div className="column">
|
2019-05-07 23:38:29 +02:00
|
|
|
<div className="column__item thumbnail-preview" style={{ backgroundImage: `url(${thumbnailSrc})` }}>
|
2018-09-02 03:49:12 +02:00
|
|
|
<img
|
|
|
|
style={{ display: 'none' }}
|
|
|
|
src={thumbnailSrc}
|
|
|
|
alt={__('Thumbnail Preview')}
|
2021-03-03 20:23:42 +01:00
|
|
|
onError={(e) => {
|
2018-09-02 03:49:12 +02:00
|
|
|
this.setState({
|
|
|
|
thumbnailError: true,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-07-17 19:43:43 +02:00
|
|
|
<div className="column__item">
|
|
|
|
<FormField
|
|
|
|
type="text"
|
|
|
|
name="content_thumbnail"
|
2018-07-18 17:46:21 +02:00
|
|
|
label="URL"
|
2020-07-22 17:24:51 +02:00
|
|
|
placeholder="https://images.fbi.gov/alien"
|
2018-07-17 19:43:43 +02:00
|
|
|
value={thumbnail}
|
|
|
|
disabled={formDisabled}
|
|
|
|
onChange={this.handleThumbnailChange}
|
2018-07-18 17:46:21 +02:00
|
|
|
/>
|
2018-07-17 19:43:43 +02:00
|
|
|
<div className="card__actions">
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Use thumbnail upload tool')}
|
2019-05-07 23:38:29 +02:00
|
|
|
onClick={() => updatePublishForm({ uploadThumbnailStatus: THUMBNAIL_STATUSES.READY })}
|
2018-07-17 19:43:43 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-08 06:05:45 +02:00
|
|
|
) : (
|
2018-07-18 17:46:21 +02:00
|
|
|
<React.Fragment>
|
2018-07-17 19:43:43 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.READY && (
|
2018-06-08 06:05:45 +02:00
|
|
|
<FileSelector
|
|
|
|
currentPath={thumbnailPath}
|
2019-06-28 09:27:55 +02:00
|
|
|
label={__('Thumbnail')}
|
2021-03-03 20:23:42 +01:00
|
|
|
placeholder={__('Thumbnails that entice a viewer to watch a video work best')}
|
2019-10-07 22:02:32 +02:00
|
|
|
accept={accept}
|
2021-03-03 20:23:42 +01:00
|
|
|
onFileChosen={(file) => openModal(MODALS.CONFIRM_THUMBNAIL_UPLOAD, { file })}
|
2018-06-08 06:05:45 +02:00
|
|
|
/>
|
|
|
|
)}
|
2019-03-05 05:46:57 +01:00
|
|
|
{status === THUMBNAIL_STATUSES.COMPLETE && thumbnail && (
|
|
|
|
<div className="column column--space-between">
|
2020-11-11 23:07:45 +01:00
|
|
|
<div
|
|
|
|
className="column__item thumbnail-preview"
|
|
|
|
// style={{ backgroundImage: `url(${thumbnail})` }}
|
|
|
|
>
|
|
|
|
{__('This will be visible in a few minutes.')}
|
|
|
|
</div>
|
2019-03-05 05:46:57 +01:00
|
|
|
<div className="column__item">
|
2020-07-23 19:11:53 +02:00
|
|
|
<p>{__('Upload complete.')}</p>
|
|
|
|
<div className="section__actions">
|
2019-05-07 23:38:29 +02:00
|
|
|
<Button button="link" label={__('New thumbnail')} onClick={resetThumbnailStatus} />
|
2018-07-18 18:01:28 +02:00
|
|
|
</div>
|
2018-07-17 19:43:43 +02:00
|
|
|
</div>
|
2019-03-05 05:46:57 +01:00
|
|
|
</div>
|
|
|
|
)}
|
2018-07-18 17:46:21 +02:00
|
|
|
</React.Fragment>
|
2018-04-02 18:39:00 +02:00
|
|
|
)}
|
2018-07-18 17:46:21 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.READY && (
|
2020-07-23 19:11:53 +02:00
|
|
|
<div className="section__actions">
|
2018-06-08 06:05:45 +02:00
|
|
|
<Button
|
|
|
|
button="link"
|
2019-05-21 23:18:11 +02:00
|
|
|
label={__('Enter a thumbnail URL')}
|
2019-05-07 23:38:29 +02:00
|
|
|
onClick={() => updatePublishForm({ uploadThumbnailStatus: THUMBNAIL_STATUSES.MANUAL })}
|
2018-06-08 06:05:45 +02:00
|
|
|
/>
|
2020-10-15 20:21:17 +02:00
|
|
|
{isSupportedVideo && IS_WEB && (
|
|
|
|
// Disabled on desktop until this is resolved
|
|
|
|
// https://github.com/electron/electron/issues/20750#issuecomment-709505902
|
2019-05-21 23:18:11 +02:00
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Take a snapshot from your video')}
|
2019-08-29 17:19:37 +02:00
|
|
|
onClick={() => openModal(MODALS.AUTO_GENERATE_THUMBNAIL, { filePath: actualFilePath })}
|
2019-05-21 23:18:11 +02:00
|
|
|
/>
|
|
|
|
)}
|
2018-07-18 17:46:21 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2018-04-02 18:39:00 +02:00
|
|
|
|
2018-06-14 22:28:50 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.IN_PROGRESS && <p>{__('Uploading thumbnail')}...</p>}
|
2020-07-23 19:11:53 +02:00
|
|
|
{status !== THUMBNAIL_STATUSES.COMPLETE && (
|
|
|
|
<p className="help">
|
|
|
|
{status === THUMBNAIL_STATUSES.API_DOWN
|
|
|
|
? __('Enter a URL for your thumbnail.')
|
|
|
|
: __('Upload your thumbnail to %domain%. Recommended size is 16:9.', { domain: DOMAIN })}
|
|
|
|
</p>
|
|
|
|
)}
|
2018-04-02 18:39:00 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SelectThumbnail;
|