|
|
@ -64,15 +64,21 @@ class Editor extends React.Component {
|
|
|
|
const { query, pathname } = url.parse(asPath, true)
|
|
|
|
const { query, pathname } = url.parse(asPath, true)
|
|
|
|
const path = escapeHtml(pathname.split('/').pop())
|
|
|
|
const path = escapeHtml(pathname.split('/').pop())
|
|
|
|
const queryParams = getQueryStringState(query)
|
|
|
|
const queryParams = getQueryStringState(query)
|
|
|
|
const initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
let initialState = Object.keys(queryParams).length ? queryParams : {}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// TODO fix this hack
|
|
|
|
// TODO fix this hack
|
|
|
|
if (this.context.gist && path.length >= 19 && path.indexOf('.') === -1) {
|
|
|
|
if (path.length >= 19 && path.indexOf('.') === -1 && this.context.gist) {
|
|
|
|
const { content, language } = await this.context.gist.get(path)
|
|
|
|
const { code, language, config } = await await this.context.gist.get(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof config === 'object') {
|
|
|
|
|
|
|
|
initialState = config
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (language) {
|
|
|
|
if (language) {
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
initialState.language = language.toLowerCase()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
initialState.code = content
|
|
|
|
|
|
|
|
|
|
|
|
initialState.code = code
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
// eslint-disable-next-line
|
|
|
@ -293,7 +299,6 @@ class Editor extends React.Component {
|
|
|
|
const config = omit(this.state, ['code', 'aspectRatio'])
|
|
|
|
const config = omit(this.state, ['code', 'aspectRatio'])
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
|
|
|
|
<div className="editor">
|
|
|
|
<div className="editor">
|
|
|
|
<Toolbar>
|
|
|
|
<Toolbar>
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
|
<Themes key={theme} updateTheme={this.updateTheme} theme={theme} />
|
|
|
@ -354,7 +359,6 @@ class Editor extends React.Component {
|
|
|
|
</Overlay>
|
|
|
|
</Overlay>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
</Dropzone>
|
|
|
|
</Dropzone>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style jsx>
|
|
|
|
<style jsx>
|
|
|
|
{`
|
|
|
|
{`
|
|
|
|
.editor {
|
|
|
|
.editor {
|
|
|
@ -370,7 +374,7 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}
|
|
|
|
`}
|
|
|
|
</style>
|
|
|
|
</style>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|