Validate thumbnails #1755
5 changed files with 90 additions and 31 deletions
|
@ -74,7 +74,7 @@ class PublishForm extends React.PureComponent<Props> {
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
const { isStillEditing, thumbnail } = this.props;
|
const { isStillEditing, thumbnail } = this.props;
|
||||||
if (!isStillEditing || !thumbnail) {
|
if (!thumbnail) {
|
||||||
this.props.resetThumbnailStatus();
|
this.props.resetThumbnailStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import React from 'react';
|
||||||
import { FormField, FormRow } from 'component/common/form';
|
import { FormField, FormRow } from 'component/common/form';
|
||||||
import FileSelector from 'component/common/file-selector';
|
import FileSelector from 'component/common/file-selector';
|
||||||
import Button from 'component/button';
|
import Button from 'component/button';
|
||||||
|
import Native from 'native';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
thumbnail: ?string,
|
thumbnail: ?string,
|
||||||
|
@ -15,7 +16,29 @@ type Props = {
|
||||||
resetThumbnailStatus: () => void,
|
resetThumbnailStatus: () => void,
|
||||||
};
|
};
|
||||||
|
|
||||||
class SelectThumbnail extends React.PureComponent<Props> {
|
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 })
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
thumbnail,
|
thumbnail,
|
||||||
|
@ -27,24 +50,43 @@ class SelectThumbnail extends React.PureComponent<Props> {
|
||||||
resetThumbnailStatus,
|
resetThumbnailStatus,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
const { thumbnailValid } = this.state;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="card__content">
|
||||||
{status === THUMBNAIL_STATUSES.API_DOWN || status === THUMBNAIL_STATUSES.MANUAL ? (
|
{status === THUMBNAIL_STATUSES.API_DOWN || status === THUMBNAIL_STATUSES.MANUAL ? (
|
||||||
<FormRow padded>
|
<div className="column">
|
||||||
<FormField
|
<div className="column__item">
|
||||||
stretch
|
<FormField
|
||||||
type="text"
|
stretch
|
||||||
name="content_thumbnail"
|
type="text"
|
||||||
label={__('URL')}
|
name="content_thumbnail"
|
||||||
placeholder="http://spee.ch/mylogo"
|
label={'URL'}
|
||||||
value={thumbnail}
|
placeholder="http://spee.ch/mylogo"
|
||||||
disabled={formDisabled}
|
value={thumbnail}
|
||||||
onChange={e => updatePublishForm({ thumbnail: e.target.value })}
|
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 })
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</FormRow>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="form-row--padded">
|
<div className="form-row--padded">
|
||||||
{(status === THUMBNAIL_STATUSES.READY || status === THUMBNAIL_STATUSES.COMPLETE) && (
|
{status === THUMBNAIL_STATUSES.READY && (
|
||||||
<FileSelector
|
<FileSelector
|
||||||
currentPath={thumbnailPath}
|
currentPath={thumbnailPath}
|
||||||
fileLabel={__('Choose Thumbnail')}
|
fileLabel={__('Choose Thumbnail')}
|
||||||
|
@ -52,13 +94,19 @@ class SelectThumbnail extends React.PureComponent<Props> {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{status === THUMBNAIL_STATUSES.COMPLETE && (
|
{status === THUMBNAIL_STATUSES.COMPLETE && (
|
||||||
<div>
|
<div className="column column--space-between">
|
||||||
<p>
|
<img
|
||||||
Upload complete. View it{' '}
|
className="column__item thumbnail-preview"
|
||||||
<Button button="link" href={thumbnail} label={__('here')} />.
|
src={thumbnail}
|
||||||
</p>
|
/>
|
||||||
<Button button="link" label={__('New thumbnail')} onClick={resetThumbnailStatus} />
|
<div className="column__item">
|
||||||
</div>
|
<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>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -72,13 +120,6 @@ class SelectThumbnail extends React.PureComponent<Props> {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{status === THUMBNAIL_STATUSES.MANUAL && (
|
|
||||||
<Button
|
|
||||||
button="link"
|
|
||||||
label={__('Use thumbnail upload tool')}
|
|
||||||
onClick={() => updatePublishForm({ uploadThumbnailStatus: THUMBNAIL_STATUSES.READY })}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{status === THUMBNAIL_STATUSES.IN_PROGRESS && <p>{__('Uploading thumbnail')}...</p>}
|
{status === THUMBNAIL_STATUSES.IN_PROGRESS && <p>{__('Uploading thumbnail')}...</p>}
|
||||||
|
|
|
@ -153,7 +153,6 @@ dd {
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-family: 'metropolis-medium';
|
font-family: 'metropolis-medium';
|
||||||
padding: $spacing-vertical * 1/3 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.page {
|
.page {
|
||||||
|
@ -302,6 +301,14 @@ p {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.column {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
.column__item:not(:first-child) {
|
||||||
|
padding-left: $spacing-width * 2/3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.truncated-text {
|
.truncated-text {
|
||||||
//display: inline-block;
|
//display: inline-block;
|
||||||
display: -webkit-box;
|
display: -webkit-box;
|
||||||
|
@ -361,3 +368,8 @@ p {
|
||||||
margin-top: $spacing-vertical * 2/3;
|
margin-top: $spacing-vertical * 2/3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thumbnail-preview {
|
||||||
|
height: 100px;
|
||||||
|
width: 177px;
|
||||||
|
}
|
||||||
|
|
|
@ -255,6 +255,12 @@
|
||||||
right: $spacing-vertical;
|
right: $spacing-vertical;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card__actions-bottom-corner {
|
||||||
|
position: absolute;
|
||||||
|
bottom: $spacing-vertical;
|
||||||
|
right: $spacing-vertical;
|
||||||
|
}
|
||||||
|
|
||||||
.card__actions--end {
|
.card__actions--end {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
BIN
static/img/thumbnail.png
Normal file
BIN
static/img/thumbnail.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
Loading…
Reference in a new issue