Use gist language response (#343)

* Use gist language response

* Use gist language response - fix when no queryparams are given (#344)

* fix when no queryparams are given
e.g. http://carbon.now.sh/3208813b324d82a9ebd197e4b1c3bae8 would still not set the language property because the initialState is null

* move gist language to its own test

* Update test
main
Michael Fix 7 years ago committed by GitHub
parent 4097e7978c
commit 80cf355b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -198,7 +198,8 @@ class Editor extends React.Component {
selected={
LANGUAGE_NAME_HASH[this.state.language] ||
LANGUAGE_MIME_HASH[this.state.language] ||
LANGUAGE_MODE_HASH[this.state.language]
LANGUAGE_MODE_HASH[this.state.language] ||
'auto'
}
list={LANGUAGES}
onChange={this.updateLanguage}

@ -2,12 +2,11 @@
/* global cy */
import { editorVisible } from '../support'
describe('Gist', () => {
const themeDropdown = () => cy.get('#toolbar .dropdown-container').first()
it('Should pull text from the first Gist file', () => {
cy.visit('/3208813b324d82a9ebd197e4b1c3bae8')
editorVisible()
cy.contains('Y-Combinator implemented in JavaScript')
cy.get('#downshift-input-Auto').should('have.value', 'JavaScript')
})
})

@ -36,7 +36,6 @@ function getGist(uid) {
.then(res => res.data)
.then(gist => gist.files)
.then(files => files[Object.keys(files)[0]])
.then(file => file.content)
}
// private

@ -12,11 +12,14 @@ class Index extends React.Component {
static async getInitialProps({ asPath, query }) {
const path = removeQueryString(asPath.split('/').pop())
const queryParams = getQueryStringState(query)
const initialState = Object.keys(queryParams).length ? queryParams : null
const initialState = Object.keys(queryParams).length ? queryParams : {}
try {
// TODO fix this hack
if (path.length >= 19 && path.indexOf('.') === -1) {
const content = await api.getGist(path)
const { content, language } = await api.getGist(path)
if (language) {
initialState.language = language.toLowerCase()
}
return { content, initialState }
}
} catch (e) {

Loading…
Cancel
Save