thumbnail preview on publish page

This commit is contained in:
Sean Yesmunt 2018-07-17 13:43:43 -04:00
parent 863a95bffb
commit 45de83fdf3
5 changed files with 90 additions and 31 deletions

View file

@ -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();
} }
} }

View file

@ -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">
<div className="column__item">
<FormField <FormField
stretch stretch
type="text" type="text"
name="content_thumbnail" name="content_thumbnail"
label={__('URL')} label={'URL'}
placeholder="http://spee.ch/mylogo" placeholder="http://spee.ch/mylogo"
value={thumbnail} value={thumbnail}
disabled={formDisabled} disabled={formDisabled}
onChange={e => updatePublishForm({ thumbnail: e.target.value })} onChange={this.handleThumbnailChange}
/> />
</FormRow> <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 })
}}
/>
</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">
<img
className="column__item thumbnail-preview"
src={thumbnail}
/>
<div className="column__item">
<p> <p>
Upload complete. View it{' '} Upload complete.{' '}
<Button button="link" href={thumbnail} label={__('here')} />. <Button button="link" href={thumbnail} label={__('View it on spee.ch')} />
</p> </p>
<Button button="link" label={__('New thumbnail')} onClick={resetThumbnailStatus} /> <Button button="link" label={__('New thumbnail')} onClick={resetThumbnailStatus} />
</div> </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>}

View file

@ -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;
}

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB