@ -6,7 +6,6 @@ import { DragDropContext } from 'react-dnd'
import domtoimage from 'dom-to-image'
import domtoimage from 'dom-to-image'
import ReadFileDropContainer , { DATA _URL , TEXT } from 'dropperx'
import ReadFileDropContainer , { DATA _URL , TEXT } from 'dropperx'
import Spinner from 'react-spinner'
import Spinner from 'react-spinner'
import shallowCompare from 'react-addons-shallow-compare'
// Ours
// Ours
import Button from './Button'
import Button from './Button'
@ -102,7 +101,7 @@ class Editor extends React.Component {
newState . language = unescapeHtml ( newState . language )
newState . language = unescapeHtml ( newState . language )
}
}
this . set State( newState )
this . update State( newState )
window . addEventListener ( 'offline' , this . setOffline )
window . addEventListener ( 'offline' , this . setOffline )
window . addEventListener ( 'online' , this . setOnline )
window . addEventListener ( 'online' , this . setOnline )
@ -113,18 +112,13 @@ class Editor extends React.Component {
window . removeEventListener ( 'online' , this . setOnline )
window . removeEventListener ( 'online' , this . setOnline )
}
}
componentDidUpdate ( prevProps , prevState ) {
updateState = updates => this . setState ( updates , ( ) => this . props . onUpdate ( this . state ) )
// this.props ensures props are not compared, only state
if ( shallowCompare ( this , this . props , prevState ) ) {
this . props . onUpdate ( this . state )
}
}
updateCode = code => this . set State( { code } )
updateCode = code => this . updateState ( { code } )
updateAspectRatio = aspectRatio => this . set State( { aspectRatio } )
updateAspectRatio = aspectRatio => this . updateState ( { aspectRatio } )
updateTitleBar = titleBar => this . set State( { titleBar } )
updateTitleBar = titleBar => this . updateState ( { titleBar } )
setOffline = ( ) => this . set State( { online : false } )
setOffline = ( ) => this . updateState ( { online : false } )
setOnline = ( ) => this . set State( { online : true } )
setOnline = ( ) => this . update State( { online : true } )
async getCarbonImage (
async getCarbonImage (
{
{
@ -208,9 +202,9 @@ class Editor extends React.Component {
}
}
updateSetting ( key , value ) {
updateSetting ( key , value ) {
this . set State( { [ key ] : value } )
this . update State( { [ key ] : value } )
if ( Object . prototype . hasOwnProperty . call ( DEFAULT _SETTINGS , key ) ) {
if ( Object . prototype . hasOwnProperty . call ( DEFAULT _SETTINGS , key ) ) {
this . set State( { preset : null } )
this . update State( { preset : null } )
}
}
}
}
@ -231,29 +225,29 @@ class Editor extends React.Component {
}
}
resetDefaultSettings ( ) {
resetDefaultSettings ( ) {
this . set State( { ... DEFAULT _SETTINGS , preset : DEFAULT _PRESET _ID } )
this . update State( { ... DEFAULT _SETTINGS , preset : DEFAULT _PRESET _ID } )
this . props . onReset ( )
this . props . onReset ( )
}
}
upload ( ) {
upload ( ) {
this . set State( { uploading : true } )
this . update State( { uploading : true } )
this . getCarbonImage ( { format : 'png' } )
this . getCarbonImage ( { format : 'png' } )
. then ( this . props . api . tweet . bind ( null , this . state . code || DEFAULT _CODE ) )
. then ( this . props . api . tweet . bind ( null , this . state . code || DEFAULT _CODE ) )
// eslint-disable-next-line
// eslint-disable-next-line
. catch ( console . error )
. catch ( console . error )
. then ( ( ) => this . set State( { uploading : false } ) )
. then ( ( ) => this . update State( { uploading : false } ) )
}
}
onDrop ( [ file ] ) {
onDrop ( [ file ] ) {
if ( isImage ( file ) ) {
if ( isImage ( file ) ) {
this . set State( {
this . update State( {
backgroundImage : file . content ,
backgroundImage : file . content ,
backgroundImageSelection : null ,
backgroundImageSelection : null ,
backgroundMode : 'image' ,
backgroundMode : 'image' ,
preset : null
preset : null
} )
} )
} else {
} else {
this . set State( { code : file . content , language : 'auto' } )
this . update State( { code : file . content , language : 'auto' } )
}
}
}
}
@ -267,13 +261,13 @@ class Editor extends React.Component {
updateBackground ( { photographer , ... changes } = { } ) {
updateBackground ( { photographer , ... changes } = { } ) {
if ( photographer ) {
if ( photographer ) {
this . set State( ( { code = DEFAULT _CODE } ) => ( {
this . update State( ( { code = DEFAULT _CODE } ) => ( {
... changes ,
... changes ,
code : code + ` \n \n // Photo by ${ photographer . name } on Unsplash ` ,
code : code + ` \n \n // Photo by ${ photographer . name } on Unsplash ` ,
preset : null
preset : null
} ) )
} ) )
} else {
} else {
this . set State( { ... changes , preset : null } )
this . update State( { ... changes , preset : null } )
}
}
}
}
@ -284,7 +278,7 @@ class Editor extends React.Component {
// create toast here in the future
// create toast here in the future
} )
} )
applyPreset = ( { id : preset , ... settings } ) => this . set State( { preset , ... settings } )
applyPreset = ( { id : preset , ... settings } ) => this . update State( { preset , ... settings } )
render ( ) {
render ( ) {
const {
const {