mirror of https://github.com/sgoudham/carbon.git
update gist handling (#715)
* update gist handling * address comments * clean up a bit * getRouteState(router) * move try/catch into getGist * updateQueryString -> updateRouteState * clean up more * add cypress tests * delete comments * remove waitmain
parent
eefc49b737
commit
d4d0ef9949
@ -1,40 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import { withRouter } from 'next/router'
|
|
||||||
import url from 'url'
|
|
||||||
|
|
||||||
import { escapeHtml } from '../lib/util'
|
|
||||||
import ApiContext from './ApiContext'
|
|
||||||
|
|
||||||
class GistContainer extends React.Component {
|
|
||||||
static contextType = ApiContext
|
|
||||||
|
|
||||||
async componentDidMount() {
|
|
||||||
const { asPath = '' } = this.props.router
|
|
||||||
const { pathname } = url.parse(asPath, true)
|
|
||||||
const path = escapeHtml(pathname.split('/').pop())
|
|
||||||
let newState = {}
|
|
||||||
|
|
||||||
if (this.context.gist && path.length >= 19 && path.indexOf('.') === -1) {
|
|
||||||
try {
|
|
||||||
const { code, language, config } = await this.context.gist.get(path)
|
|
||||||
if (typeof config === 'object') {
|
|
||||||
newState = config
|
|
||||||
}
|
|
||||||
if (language) {
|
|
||||||
newState.language = language.toLowerCase()
|
|
||||||
}
|
|
||||||
newState.code = code
|
|
||||||
} catch (e) {
|
|
||||||
// eslint-disable-next-line
|
|
||||||
console.log(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.props.onChange(newState)
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default withRouter(GistContainer)
|
|
Loading…
Reference in New Issue