From 5dbed921d54fe3021d56d1f87248b506d66cdeeb Mon Sep 17 00:00:00 2001 From: Mike Fix Date: Thu, 7 Feb 2019 19:34:47 -0800 Subject: [PATCH] clean up editor state more with Spinner wrapper --- components/Editor.js | 28 +++++----------------------- components/SpinnerWrapper.js | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 components/SpinnerWrapper.js diff --git a/components/Editor.js b/components/Editor.js index 3babc13..fed9939 100644 --- a/components/Editor.js +++ b/components/Editor.js @@ -2,7 +2,6 @@ import url from 'url' import React from 'react' import domtoimage from 'dom-to-image' -import Spinner from 'react-spinner' import dynamic from 'next/dynamic' import Dropzone from 'dropperx' @@ -15,6 +14,7 @@ import Carbon from './Carbon' import ExportMenu from './ExportMenu' import Themes from './Themes' import TweetButton from './TweetButton' +import SpinnerWrapper from './SpinnerWrapper' import { LANGUAGES, LANGUAGE_MIME_HASH, @@ -43,8 +43,7 @@ class Editor extends React.Component { super(props) this.state = { ...DEFAULT_SETTINGS, - preset: DEFAULT_PRESET_ID, - loading: true + preset: DEFAULT_PRESET_ID } this.export = this.export.bind(this) @@ -84,8 +83,7 @@ class Editor extends React.Component { // Load from localStorage ...getSettings(localStorage), // and then URL params - ...initialState, - loading: false + ...initialState } // Makes sure the slash in 'application/X' is decoded @@ -273,7 +271,6 @@ class Editor extends React.Component { render() { const { - loading, theme, language, backgroundColor, @@ -285,25 +282,10 @@ class Editor extends React.Component { exportSize } = this.state - if (loading) { - return ( -
- - -
- ) - } - const config = omit(this.state, ['code', 'aspectRatio', 'titleBar']) return ( - +
@@ -381,7 +363,7 @@ class Editor extends React.Component { } `} - + ) } } diff --git a/components/SpinnerWrapper.js b/components/SpinnerWrapper.js new file mode 100644 index 0000000..e973113 --- /dev/null +++ b/components/SpinnerWrapper.js @@ -0,0 +1,27 @@ +import React from 'react' +import Spinner from 'react-spinner' + +export default function SpinnerWrapper(props) { + const [loading, setLoading] = React.useState(true) + + React.useEffect(() => { + setLoading(false) + }, []) + + if (loading) { + return ( +
+ + +
+ ) + } + + return props.children +}