From 88edd12827599300d1e2c7e230c16ead258031fd Mon Sep 17 00:00:00 2001 From: briandennis Date: Sun, 18 Jun 2017 21:10:28 -0700 Subject: [PATCH] fix jank on editor load with spinner --- components/CodeImage.js | 91 +++++++++++++++++++++++++++------------- components/Meta.js | 1 + package.json | 4 +- static/react-spinner.css | 35 ++++++++++++++++ yarn.lock | 25 ++++++++--- 5 files changed, 121 insertions(+), 35 deletions(-) create mode 100644 static/react-spinner.css diff --git a/components/CodeImage.js b/components/CodeImage.js index f5a251c..89912a2 100644 --- a/components/CodeImage.js +++ b/components/CodeImage.js @@ -3,6 +3,7 @@ import React from 'react' import domtoimage from 'dom-to-image' import CodeMirror from 'react-codemirror' import WindowControls from '../components/svg/Controls' +import Spinner from 'react-spinner' // hack to only call modes on browser if (typeof window !== 'undefined' && typeof window.navigator !== 'undefined') { @@ -19,40 +20,74 @@ const DEFAULT_SETTINGS = { language: 'javascript' } -const CodeImage = (props) => { - const config = Object.assign(DEFAULT_SETTINGS, props.config) + class CodeImage extends React.Component { - const options = { - lineNumbers: false, - mode: config.language, - theme: config.theme, - scrollBarStyle: null, - viewportMargin: Infinity, - lineWrapping: true + constructor (props) { + super(props) + + this.state = { + loading: true + } } - // create styles - const containerStyle = { - background: config.background, - padding: `${config.paddingVertical} ${config.paddingHorizontal}` + componentDidMount() { + this.setState({ + loading: false + }) } - return ( -
-
- { true ? : null } - + render () { + const config = Object.assign(DEFAULT_SETTINGS, this.props.config) + + const options = { + lineNumbers: false, + mode: config.language, + theme: config.theme, + scrollBarStyle: null, + viewportMargin: Infinity, + lineWrapping: true + } + + const containerStyle = { + background: config.background, + padding: `${config.paddingVertical} ${config.paddingHorizontal}` + } + + // set content to spinner if loading, else editor + let content = ( +
+ +
- -
- ) + ) + if (this.state.loading === false) { + content = ( +
+ +
+ ) + } + + return ( +
+ { content } + +
+ ) + } } export default CodeImage diff --git a/components/Meta.js b/components/Meta.js index f462bcb..c8c79f4 100644 --- a/components/Meta.js +++ b/components/Meta.js @@ -9,6 +9,7 @@ export default () => ( +