From 9cb4287a205de8ecdf6d640e6365181a2be2b512 Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Wed, 6 Feb 2019 21:14:19 -0800 Subject: [PATCH] move tweet button into its own Comp w/ useAsyncCallback --- components/Editor.js | 26 +++++--------------------- components/TweetButton.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 components/TweetButton.js diff --git a/components/Editor.js b/components/Editor.js index b9b2d28..e472e1c 100644 --- a/components/Editor.js +++ b/components/Editor.js @@ -7,7 +7,6 @@ import dynamic from 'next/dynamic' import Dropzone from 'dropperx' // Ours -import Button from './Button' import Dropdown from './Dropdown' import Settings from './Settings' import Toolbar from './Toolbar' @@ -15,6 +14,7 @@ import Overlay from './Overlay' import Carbon from './Carbon' import ExportMenu from './ExportMenu' import Themes from './Themes' +import TweetButton from './TweetButton' import { LANGUAGES, LANGUAGE_MIME_HASH, @@ -44,7 +44,6 @@ class Editor extends React.Component { this.state = { ...DEFAULT_SETTINGS, loading: true, - uploading: false, code: props.content, online: true, preset: DEFAULT_PRESET_ID @@ -234,12 +233,9 @@ class Editor extends React.Component { } upload() { - this.updateState({ uploading: true }) - this.getCarbonImage({ format: 'png' }) - .then(this.props.api.tweet.bind(null, this.state.code || DEFAULT_CODE)) - // eslint-disable-next-line - .catch(console.error) - .then(() => this.updateState({ uploading: false })) + this.getCarbonImage({ format: 'png' }).then( + this.props.api.tweet.bind(null, this.state.code || DEFAULT_CODE) + ) } onDrop([file]) { @@ -297,7 +293,6 @@ class Editor extends React.Component { backgroundImage, backgroundMode, aspectRatio, - uploading, online, titleBar, code, @@ -353,18 +348,7 @@ class Editor extends React.Component { getCarbonImage={this.getCarbonImage} />
- {this.props.api.tweet && online && ( - - )} + {this.props.api.tweet && online && } + {loading ? 'Loading...' : 'Tweet'} + + ) +} + +export default React.memo(TweetButton)