clean up editor state more with Spinner wrapper

main
Mike Fix 6 years ago
parent 109adb4cb0
commit 5dbed921d5

@ -2,7 +2,6 @@
import url from 'url' import url from 'url'
import React from 'react' import React from 'react'
import domtoimage from 'dom-to-image' import domtoimage from 'dom-to-image'
import Spinner from 'react-spinner'
import dynamic from 'next/dynamic' import dynamic from 'next/dynamic'
import Dropzone from 'dropperx' import Dropzone from 'dropperx'
@ -15,6 +14,7 @@ import Carbon from './Carbon'
import ExportMenu from './ExportMenu' import ExportMenu from './ExportMenu'
import Themes from './Themes' import Themes from './Themes'
import TweetButton from './TweetButton' import TweetButton from './TweetButton'
import SpinnerWrapper from './SpinnerWrapper'
import { import {
LANGUAGES, LANGUAGES,
LANGUAGE_MIME_HASH, LANGUAGE_MIME_HASH,
@ -43,8 +43,7 @@ class Editor extends React.Component {
super(props) super(props)
this.state = { this.state = {
...DEFAULT_SETTINGS, ...DEFAULT_SETTINGS,
preset: DEFAULT_PRESET_ID, preset: DEFAULT_PRESET_ID
loading: true
} }
this.export = this.export.bind(this) this.export = this.export.bind(this)
@ -84,8 +83,7 @@ class Editor extends React.Component {
// Load from localStorage // Load from localStorage
...getSettings(localStorage), ...getSettings(localStorage),
// and then URL params // and then URL params
...initialState, ...initialState
loading: false
} }
// Makes sure the slash in 'application/X' is decoded // Makes sure the slash in 'application/X' is decoded
@ -273,7 +271,6 @@ class Editor extends React.Component {
render() { render() {
const { const {
loading,
theme, theme,
language, language,
backgroundColor, backgroundColor,
@ -285,25 +282,10 @@ class Editor extends React.Component {
exportSize exportSize
} = this.state } = this.state
if (loading) {
return (
<div>
<Spinner />
<style jsx>
{`
div {
height: 160px;
}
`}
</style>
</div>
)
}
const config = omit(this.state, ['code', 'aspectRatio', 'titleBar']) const config = omit(this.state, ['code', 'aspectRatio', 'titleBar'])
return ( return (
<React.Fragment> <SpinnerWrapper>
<div className="editor"> <div className="editor">
<Toolbar> <Toolbar>
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} /> <Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
@ -381,7 +363,7 @@ class Editor extends React.Component {
} }
`} `}
</style> </style>
</React.Fragment> </SpinnerWrapper>
) )
} }
} }

@ -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 (
<div>
<Spinner />
<style jsx>
{`
div {
height: 160px;
}
`}
</style>
</div>
)
}
return props.children
}
Loading…
Cancel
Save