2018-04-02 18:39:00 +02:00
|
|
|
// @flow
|
2018-06-14 22:28:50 +02:00
|
|
|
import { THUMBNAIL_STATUSES, MODALS } from 'lbry-redux';
|
2018-04-02 18:39:00 +02:00
|
|
|
import React from 'react';
|
2018-06-08 06:05:45 +02:00
|
|
|
import { FormField, FormRow } 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';
|
2018-07-17 19:43:43 +02:00
|
|
|
import Native from 'native';
|
2018-04-02 18:39:00 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
thumbnail: ?string,
|
|
|
|
formDisabled: boolean,
|
|
|
|
uploadThumbnailStatus: string,
|
2018-06-08 06:05:45 +02:00
|
|
|
thumbnailPath: ?string,
|
|
|
|
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 = {
|
|
|
|
thumbnailValid: boolean,
|
|
|
|
}
|
|
|
|
|
|
|
|
class SelectThumbnail extends React.PureComponent<Props, State> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
thumbnailValid: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
(this: any).handleThumbnailChange = this.handleThumbnailChange.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleThumbnailChange(e) {
|
|
|
|
const { updatePublishForm } = this.props;
|
|
|
|
const newThumbnail = e.target.value.replace(' ', '');
|
|
|
|
|
|
|
|
updatePublishForm({ thumbnail: newThumbnail });
|
|
|
|
this.setState({ thumbnailValid: true })
|
|
|
|
}
|
|
|
|
|
2018-04-02 18:39:00 +02:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
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;
|
2018-07-17 19:43:43 +02:00
|
|
|
|
|
|
|
const { thumbnailValid } = this.state;
|
|
|
|
|
2018-04-02 18:39:00 +02:00
|
|
|
return (
|
2018-07-17 19:43:43 +02:00
|
|
|
<div className="card__content">
|
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">
|
|
|
|
<div className="column__item">
|
|
|
|
<FormField
|
|
|
|
stretch
|
|
|
|
type="text"
|
|
|
|
name="content_thumbnail"
|
|
|
|
label={'URL'}
|
|
|
|
placeholder="http://spee.ch/mylogo"
|
|
|
|
value={thumbnail}
|
|
|
|
disabled={formDisabled}
|
|
|
|
onChange={this.handleThumbnailChange}
|
|
|
|
/>
|
|
|
|
<div className="card__actions">
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Use thumbnail upload tool')}
|
|
|
|
onClick={() => updatePublishForm({ uploadThumbnailStatus: THUMBNAIL_STATUSES.READY })}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<img
|
|
|
|
src={(!thumbnail || !thumbnailValid) ? Native.imagePath('thumbnail.png') : thumbnail}
|
|
|
|
className="column__item thumbnail-preview"
|
|
|
|
alt="Thumbnail Preview"
|
|
|
|
onError={() => {
|
|
|
|
this.setState({ thumbnailValid: false })
|
|
|
|
}}
|
2018-04-02 18:39:00 +02:00
|
|
|
/>
|
2018-07-17 19:43:43 +02:00
|
|
|
</div>
|
2018-06-08 06:05:45 +02:00
|
|
|
) : (
|
|
|
|
<div className="form-row--padded">
|
2018-07-17 19:43:43 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.READY && (
|
2018-06-08 06:05:45 +02:00
|
|
|
<FileSelector
|
|
|
|
currentPath={thumbnailPath}
|
|
|
|
fileLabel={__('Choose Thumbnail')}
|
|
|
|
onFileChosen={path => openModal({ id: MODALS.CONFIRM_THUMBNAIL_UPLOAD }, { path })}
|
|
|
|
/>
|
|
|
|
)}
|
2018-06-14 22:28:50 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.COMPLETE && (
|
2018-07-17 19:43:43 +02:00
|
|
|
<div className="column column--space-between">
|
|
|
|
<img
|
|
|
|
className="column__item thumbnail-preview"
|
|
|
|
src={thumbnail}
|
|
|
|
/>
|
|
|
|
<div className="column__item">
|
|
|
|
<p>
|
|
|
|
Upload complete.{' '}
|
|
|
|
<Button button="link" href={thumbnail} label={__('View it on spee.ch')} />
|
|
|
|
</p>
|
|
|
|
<Button button="link" label={__('New thumbnail')} onClick={resetThumbnailStatus} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-06-08 06:05:45 +02:00
|
|
|
)}
|
2018-04-02 18:39:00 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2018-06-08 06:05:45 +02:00
|
|
|
<div className="card__actions">
|
2018-06-14 22:28:50 +02:00
|
|
|
{status === THUMBNAIL_STATUSES.READY && (
|
2018-06-08 06:05:45 +02:00
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
label={__('Or enter a URL manually')}
|
2018-06-14 22:28:50 +02:00
|
|
|
onClick={() =>
|
|
|
|
updatePublishForm({ uploadThumbnailStatus: THUMBNAIL_STATUSES.MANUAL })
|
|
|
|
}
|
2018-06-08 06:05:45 +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>}
|
2018-04-02 18:39:00 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SelectThumbnail;
|