From 80cf355b44c8a59751701d5f3f66b926e856fe23 Mon Sep 17 00:00:00 2001 From: Michael Fix Date: Mon, 23 Apr 2018 10:07:17 -0700 Subject: [PATCH] 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 --- components/Editor.js | 3 ++- cypress/integration/gist.js | 3 +-- lib/api.js | 1 - pages/index.js | 7 +++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/Editor.js b/components/Editor.js index 9ead294..33b7a6e 100644 --- a/components/Editor.js +++ b/components/Editor.js @@ -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} diff --git a/cypress/integration/gist.js b/cypress/integration/gist.js index 97c1947..54c4cb4 100644 --- a/cypress/integration/gist.js +++ b/cypress/integration/gist.js @@ -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') }) }) diff --git a/lib/api.js b/lib/api.js index 067bbb6..1351b5c 100644 --- a/lib/api.js +++ b/lib/api.js @@ -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 diff --git a/pages/index.js b/pages/index.js index 1a4066b..0440ee6 100644 --- a/pages/index.js +++ b/pages/index.js @@ -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) {