Skip to content
This repository has been archived by the owner on Mar 8, 2019. It is now read-only.

Code Splitting #10

Merged
merged 1 commit into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions src/DrupalCoreSelector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import DrupalSelection from './DrupalSelection';

class DrupalCoreSelector extends React.Component {

constructor(props) {
super(props);
this.getDrupalCoreBranches = this.getDrupalCoreBranches.bind(this);
this.state = {
d7options: [],
d8options: [],
};
}

getDrupalCoreBranches() {
const parseString = require('react-native-xml2js').parseString;
//TO DO - remove proxy and cache in STM
var proxy = 'https://cors-anywhere.herokuapp.com/';
var d7url = 'https://updates.drupal.org/release-history/drupal/7.x';
var d8url = 'https://updates.drupal.org/release-history/drupal/8.x';

fetch(proxy + d8url, {
//mode: 'no-cors'
})
.then(response => response.text())
.then((response) => {
parseString(response, (err, result) => {
var feedData = JSON.parse(JSON.stringify(result));
console.log(feedData.project.releases[0].release);
this.setState({d8options: feedData.project.releases[0].release});
});
}).catch((err) => {
console.log('fetch', err)
});

fetch(proxy + d7url, {
//mode: 'no-cors'
})
.then(response => response.text())
.then((response) => {
parseString(response, (err, result) => {
//console.log(response);
var feedData = JSON.parse(JSON.stringify(result));
this.setState({d7options: feedData.project.releases[0].release});
});
}).catch((err) => {
console.log('fetch', err)
});
}

componentDidMount() {
this.getDrupalCoreBranches();
}

render() {
return (
<select className="drupalCoreSelector">
<option disabled="true">Drupal 8 Releases</option>
{this.state.d8options.map(function(release, i) { return (
<option value={release.tag} key={release.tag}>
{release.name}
</option>
)})}
<option disabled="true">Drupal 7 Releases</option>
{this.state.d7options.map(function(release, i) { return (
<option value={release.tag} key={release.tag}>
{release.name}
</option>
)})}
</select>
);
}
}

export default DrupalCoreSelector;
17 changes: 17 additions & 0 deletions src/DrupalSelection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import DrupalCoreSelector from './DrupalCoreSelector';

class DrupalSelection extends React.Component {
render() {
return (
<div className="drupal-selection">
<div className="drupal-core-selection">
<DrupalCoreSelector />
</div>
<button value="yes">Select</button>
</div>
);
}
}

export default DrupalSelection;
87 changes: 1 addition & 86 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,8 @@
import React from 'react';
import DrupalSelection from './DrupalSelection'
import ReactDOM from 'react-dom';
import './index.css';

class DrupalCoreSelector extends React.Component {

constructor(props) {
super(props);
this.getDrupalCoreBranches = this.getDrupalCoreBranches.bind(this);
this.state = {
d7options: [],
d8options: [],
};
}

getDrupalCoreBranches() {
const parseString = require('react-native-xml2js').parseString;
//TO DO - remove proxy and cache in STM
var proxy = 'https://cors-anywhere.herokuapp.com/';
var d7url = 'https://updates.drupal.org/release-history/drupal/7.x';
var d8url = 'https://updates.drupal.org/release-history/drupal/8.x';

fetch(proxy + d8url, {
//mode: 'no-cors'
})
.then(response => response.text())
.then((response) => {
parseString(response, (err, result) => {
var feedData = JSON.parse(JSON.stringify(result));
console.log(feedData.project.releases[0].release);
this.setState({d8options: feedData.project.releases[0].release});
});
}).catch((err) => {
console.log('fetch', err)
});

fetch(proxy + d7url, {
//mode: 'no-cors'
})
.then(response => response.text())
.then((response) => {
parseString(response, (err, result) => {
//console.log(response);
var feedData = JSON.parse(JSON.stringify(result));
this.setState({d7options: feedData.project.releases[0].release});
});
}).catch((err) => {
console.log('fetch', err)
});
}

componentDidMount() {
this.getDrupalCoreBranches();
}

render() {
return (
<select className="drupalCoreSelector">
<option disabled="true">Drupal 8 Releases</option>
{this.state.d8options.map(function(release, i) { return (
<option value={release.tag} key={release.tag}>
{release.name}
</option>
)})}
<option disabled="true">Drupal 7 Releases</option>
{this.state.d7options.map(function(release, i) { return (
<option value={release.tag} key={release.tag}>
{release.name}
</option>
)})}
</select>
);
}
}

class DrupalSelection extends React.Component {
render() {
return (
<div className="drupal-selection">
<div className="drupal-core-selection">
<DrupalCoreSelector />
</div>
<button value="yes">Select</button>
</div>
);
}
}

// ========================================

ReactDOM.render(
<DrupalSelection />,
document.getElementById('root')
Expand Down
Loading