Code cleanup, implement some editing
This commit is contained in:
parent
63d1de3147
commit
8ee57c25e4
3 changed files with 90 additions and 35 deletions
|
@ -124,8 +124,8 @@ export default class Creatify extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const me = this;
|
const me = this;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
props,
|
||||||
state,
|
state,
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
|
@ -139,6 +139,7 @@ export default class Creatify extends Component {
|
||||||
<RichDraggable bounds={state.bounds}>
|
<RichDraggable bounds={state.bounds}>
|
||||||
<EditableFontface fontFace={FontPresets[state.fontName]} value="Hello from LBRY" />
|
<EditableFontface fontFace={FontPresets[state.fontName]} value="Hello from LBRY" />
|
||||||
</RichDraggable>
|
</RichDraggable>
|
||||||
|
{props.children}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { validateFile } from '../../utils/file';
|
import { validateFile } from '../../utils/file';
|
||||||
|
import Creatify from '@components/Creatify';
|
||||||
import DropzonePreviewImage from '@components/DropzonePreviewImage';
|
import DropzonePreviewImage from '@components/DropzonePreviewImage';
|
||||||
import DropzoneDropItDisplay from '@components/DropzoneDropItDisplay';
|
import DropzoneDropItDisplay from '@components/DropzoneDropItDisplay';
|
||||||
import DropzoneInstructionsDisplay from '@components/DropzoneInstructionsDisplay';
|
import DropzoneInstructionsDisplay from '@components/DropzoneInstructionsDisplay';
|
||||||
|
@ -7,11 +8,21 @@ import DropzoneInstructionsDisplay from '@components/DropzoneInstructionsDisplay
|
||||||
class Dropzone extends React.Component {
|
class Dropzone extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
dragOver : false,
|
dragOver : false,
|
||||||
mouseOver : false,
|
mouseOver : false,
|
||||||
dimPreview: false,
|
dimPreview : false,
|
||||||
|
filePreview: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(props.file) {
|
||||||
|
// No side effects allowed with `getDerivedStateFromProps`, so
|
||||||
|
// we must use `componentDidUpdate` and `constructor` routines.
|
||||||
|
// Note: `FileReader` has an `onloadend` side-effect
|
||||||
|
this.updateFilePreview();
|
||||||
|
}
|
||||||
|
|
||||||
this.handleDrop = this.handleDrop.bind(this);
|
this.handleDrop = this.handleDrop.bind(this);
|
||||||
this.handleDragOver = this.handleDragOver.bind(this);
|
this.handleDragOver = this.handleDragOver.bind(this);
|
||||||
this.handleDragEnd = this.handleDragEnd.bind(this);
|
this.handleDragEnd = this.handleDragEnd.bind(this);
|
||||||
|
@ -23,6 +34,25 @@ class Dropzone extends React.Component {
|
||||||
this.handleFileInput = this.handleFileInput.bind(this);
|
this.handleFileInput = this.handleFileInput.bind(this);
|
||||||
this.chooseFile = this.chooseFile.bind(this);
|
this.chooseFile = this.chooseFile.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
if(prevProps.file !== this.props.file) {
|
||||||
|
this.updateFilePreview();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateFilePreview() {
|
||||||
|
if (this.props.file) {
|
||||||
|
const fileReader = new FileReader();
|
||||||
|
fileReader.readAsDataURL(this.props.file);
|
||||||
|
fileReader.onloadend = () => {
|
||||||
|
this.setState({
|
||||||
|
filePreview: fileReader.result
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
handleDrop (event) {
|
handleDrop (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({dragOver: false});
|
this.setState({dragOver: false});
|
||||||
|
@ -35,9 +65,11 @@ class Dropzone extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDragOver (event) {
|
handleDragOver (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDragEnd (event) {
|
handleDragEnd (event) {
|
||||||
var dt = event.dataTransfer;
|
var dt = event.dataTransfer;
|
||||||
if (dt.items) {
|
if (dt.items) {
|
||||||
|
@ -48,27 +80,34 @@ class Dropzone extends React.Component {
|
||||||
event.dataTransfer.clearData();
|
event.dataTransfer.clearData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDragEnter () {
|
handleDragEnter () {
|
||||||
this.setState({dragOver: true, dimPreview: true});
|
this.setState({dragOver: true, dimPreview: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleDragLeave () {
|
handleDragLeave () {
|
||||||
this.setState({dragOver: false, dimPreview: false});
|
this.setState({dragOver: false, dimPreview: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseEnter () {
|
handleMouseEnter () {
|
||||||
this.setState({mouseOver: true, dimPreview: true});
|
this.setState({mouseOver: true, dimPreview: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMouseLeave () {
|
handleMouseLeave () {
|
||||||
this.setState({mouseOver: false, dimPreview: false});
|
this.setState({mouseOver: false, dimPreview: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick (event) {
|
handleClick (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document.getElementById('file_input').click();
|
document.getElementById('file_input').click();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleFileInput (event) {
|
handleFileInput (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const fileList = event.target.files;
|
const fileList = event.target.files;
|
||||||
this.chooseFile(fileList[0]);
|
this.chooseFile(fileList[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseFile (file) {
|
chooseFile (file) {
|
||||||
if (file) {
|
if (file) {
|
||||||
try {
|
try {
|
||||||
|
@ -80,9 +119,49 @@ class Dropzone extends React.Component {
|
||||||
this.props.selectFile(file);
|
this.props.selectFile(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { dragOver, mouseOver, dimPreview } = this.state;
|
const { dragOver, mouseOver, dimPreview, filePreview } = this.state;
|
||||||
const { file, thumbnail, fileError, isUpdate, sourceUrl, fileExt } = this.props;
|
const { file, thumbnail, fileError, isUpdate, sourceUrl, fileExt } = this.props;
|
||||||
|
|
||||||
|
const hasContent = !!(file || isUpdate);
|
||||||
|
|
||||||
|
const dropZoneHooks = file ? {} : {
|
||||||
|
onDrop: this.handleDrop,
|
||||||
|
onDragOver: this.handleDragOver,
|
||||||
|
onDragEnd: this.handleDragEnd,
|
||||||
|
onDragEnter: this.handleDragEnter,
|
||||||
|
onDragLeave: this.handleDragLeave,
|
||||||
|
onMouseEnter: this.handleMouseEnter,
|
||||||
|
onMouseLeave: this.handleMouseLeave,
|
||||||
|
onClick: this.handleClick,
|
||||||
|
};
|
||||||
|
|
||||||
|
const dropZonePreviewProps = file ? {
|
||||||
|
dimPreview,
|
||||||
|
file,
|
||||||
|
thumbnail,
|
||||||
|
} : {
|
||||||
|
dimPreview: true,
|
||||||
|
isUpdate: true,
|
||||||
|
sourceUrl,
|
||||||
|
};
|
||||||
|
|
||||||
|
let memeify = file && filePreview ? (
|
||||||
|
<Creatify>
|
||||||
|
<img src={filePreview} />
|
||||||
|
</Creatify>
|
||||||
|
) : null;
|
||||||
|
|
||||||
|
console.log({
|
||||||
|
file,
|
||||||
|
thumbnail,
|
||||||
|
sourceUrl,
|
||||||
|
filePreview,
|
||||||
|
});
|
||||||
|
|
||||||
|
const dropZoneClassName = 'dropzone' + (dragOver ? ' dropzone--drag-over' : '');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
{isUpdate && fileExt === 'mp4' ? (
|
{isUpdate && fileExt === 'mp4' ? (
|
||||||
|
@ -100,31 +179,10 @@ class Dropzone extends React.Component {
|
||||||
encType='multipart/form-data'
|
encType='multipart/form-data'
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
<div
|
<div className={dropZoneClassName} {...dropZoneHooks}>
|
||||||
className={'dropzone' + (dragOver ? ' dropzone--drag-over' : '')}
|
{hasContent ? (
|
||||||
onDrop={this.handleDrop}
|
|
||||||
onDragOver={this.handleDragOver}
|
|
||||||
onDragEnd={this.handleDragEnd}
|
|
||||||
onDragEnter={this.handleDragEnter}
|
|
||||||
onDragLeave={this.handleDragLeave}
|
|
||||||
onMouseEnter={this.handleMouseEnter}
|
|
||||||
onMouseLeave={this.handleMouseLeave}
|
|
||||||
onClick={this.handleClick}>
|
|
||||||
{file || isUpdate ? (
|
|
||||||
<div className={'dropzone-preview-wrapper'}>
|
<div className={'dropzone-preview-wrapper'}>
|
||||||
{file ? (
|
<DropzonePreviewImage {...dropZonePreviewProps} />
|
||||||
<DropzonePreviewImage
|
|
||||||
dimPreview={dimPreview}
|
|
||||||
file={file}
|
|
||||||
thumbnail={thumbnail}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<DropzonePreviewImage
|
|
||||||
dimPreview
|
|
||||||
isUpdate
|
|
||||||
sourceUrl={sourceUrl}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<div className={'dropzone-preview-overlay'}>
|
<div className={'dropzone-preview-overlay'}>
|
||||||
{ dragOver ? <DropzoneDropItDisplay /> : null }
|
{ dragOver ? <DropzoneDropItDisplay /> : null }
|
||||||
{ mouseOver ? (
|
{ mouseOver ? (
|
||||||
|
@ -133,13 +191,12 @@ class Dropzone extends React.Component {
|
||||||
message={fileExt === 'mp4' ? 'Drag & drop new thumbnail' : null}
|
message={fileExt === 'mp4' ? 'Drag & drop new thumbnail' : null}
|
||||||
/>
|
/>
|
||||||
) : null }
|
) : null }
|
||||||
|
{memeify}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
dragOver ? <DropzoneDropItDisplay /> : (
|
dragOver ? <DropzoneDropItDisplay /> : (
|
||||||
<DropzoneInstructionsDisplay
|
<DropzoneInstructionsDisplay fileError={fileError} />
|
||||||
fileError={fileError}
|
|
||||||
/>
|
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,8 +3,6 @@ import PageLayout from '@components/PageLayout';
|
||||||
import PublishTool from '@containers/PublishTool';
|
import PublishTool from '@containers/PublishTool';
|
||||||
import ContentPageWrapper from '@pages/ContentPageWrapper';
|
import ContentPageWrapper from '@pages/ContentPageWrapper';
|
||||||
|
|
||||||
import Creatify from '@components/Creatify';
|
|
||||||
|
|
||||||
class HomePage extends React.Component {
|
class HomePage extends React.Component {
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.props.clearFile();
|
this.props.clearFile();
|
||||||
|
@ -18,7 +16,6 @@ class HomePage extends React.Component {
|
||||||
pageTitle={'Speech'}
|
pageTitle={'Speech'}
|
||||||
pageUri={''}
|
pageUri={''}
|
||||||
>
|
>
|
||||||
<Creatify />
|
|
||||||
<PublishTool />
|
<PublishTool />
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue