mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
952 B
JavaScript
39 lines
952 B
JavaScript
import React from 'react'
|
|
import { withRouter } from 'next/router'
|
|
|
|
import { escapeHtml } from '../lib/util'
|
|
import ApiContext from './ApiContext'
|
|
|
|
class GistContainer extends React.Component {
|
|
static contextType = ApiContext
|
|
|
|
async componentDidMount() {
|
|
const { pathname } = this.props.router
|
|
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)
|