Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Cookie behaves differen'tly on each browser
Browse files Browse the repository at this point in the history
  • Loading branch information
uppal101 committed Sep 14, 2017
1 parent 09d3433 commit 25b9881
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/api-explorer-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/api-explorer-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"classnames": "^2.2.5",
"httpsnippet": "^1.16.5",
"js-cookie": "^2.1.4",
"marked": "github:readmeio/marked",
"prop-types": "^15.5.10",
"react": "^15.6.1",
Expand Down
10 changes: 8 additions & 2 deletions packages/api-explorer-ui/src/Doc.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const React = require('react');
const PropTypes = require('prop-types');

const Cookies = require('js-cookie');
const extensions = require('../../readme-oas-extensions');

const PathUrl = require('./PathUrl');
Expand Down Expand Up @@ -29,10 +29,14 @@ class Doc extends React.Component {
}

render() {
const { doc, setLanguage } = this.props;
const { doc, setLanguage, language } = this.props;
const oas = this.oas;
const operation = oas.operation(doc.swagger.path, doc.api.method);

console.log(language);

Cookies.set('readme_language', language);

return (
<div className="hub-reference" id={`page-${doc.slug}`}>
{
Expand Down Expand Up @@ -74,6 +78,7 @@ class Doc extends React.Component {
setLanguage={setLanguage}
operation={operation}
formData={this.state.formData}
language={language}
/>
</div>
<div className="hub-reference-right" />
Expand Down Expand Up @@ -126,4 +131,5 @@ Doc.propTypes = {
}).isRequired,
oas: PropTypes.shape({}).isRequired,
setLanguage: PropTypes.func.isRequired,
language: PropTypes.string.isRequired,
};
5 changes: 4 additions & 1 deletion packages/api-explorer-ui/src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const React = require('react');
const PropTypes = require('prop-types');
const Cookies = require('js-cookie');
const extensions = require('../../readme-oas-extensions');

const Doc = require('./Doc');

class ApiExplorer extends React.Component {
constructor(props) {
super(props);
this.state = { language: 'curl' };
this.state = { language: Cookies.get('readme_language') };

try {
const firstOas = Object.keys(this.props.oasFiles)[0];
Expand All @@ -19,6 +20,7 @@ class ApiExplorer extends React.Component {
setLanguage(language) {
this.setState({ language });
}

render() {
return (
<div className={`is-lang-${this.state.language}`}>
Expand All @@ -29,6 +31,7 @@ class ApiExplorer extends React.Component {
doc={doc}
oas={doc.category.apiSetting ? this.props.oasFiles[doc.category.apiSetting] : {}}
setLanguage={this.setLanguage}
language={this.state.language}
/>
))}
</div>
Expand Down

0 comments on commit 25b9881

Please sign in to comment.