'use strict';
const remote = require('electron').remote;
const settings = require('./common/settings');
var SettingsPage = React.createClass({
getInitialState: function() {
return {
teams: []
};
},
componentDidMount: function() {
var config = settings.readFileSync(this.props.configFile);
this.setState({
teams: config.teams
})
},
handleTeamsChange: function(teams) {
this.setState({
teams: teams
});
},
handleOK: function() {
var config = {
teams: this.state.teams,
version: 1
};
settings.writeFileSync(this.props.configFile, config);
window.location = './index.html';
},
handleCancel: function() {
window.location = './index.html';
},
render: function() {
return (
);
}
});
var TeamList = React.createClass({
handleTeamChange: function(index, team) {
var teams = this.props.teams;
teams[index] = team;
this.props.onTeamsChange(teams);
},
handleNewTeamAdd: function(team) {
var teams = this.props.teams;
teams.push(team);
this.props.onTeamsChange(teams);
},
render: function() {
var thisObj = this;
var teamNodes = this.props.teams.map(function(team, i) {
var handleTeamChange = function(team) {
thisObj.handleTeamChange(i, team);
};
return (
);
});
return (
);
}
});
var TeamItem = React.createClass({
handleNameChange: function(e) {
this.props.onTeamChange({
name: e.target.value,
url: this.props.url
});
},
handleURLChange: function(e) {
this.props.onTeamChange({
name: this.props.name,
url: e.target.value
});
},
render: function() {
return (
);
}
});
var NewTeamItem = React.createClass({
getInitialState: function() {
return {
name: '',
url: ''
};
},
handleNewTeamAdd: function() {
this.props.onNewTeamAdd({
name: this.state.name,
url: this.state.url
});
this.setState(this.getInitialState());
},
handleNameChange: function(e) {
this.setState({
name: e.target.value
});
},
handleURLChange: function(e) {
this.setState({
url: e.target.value
});
},
render: function() {
return (
);
}
});
var configFile = remote.getGlobal('config-file');
ReactDOM.render(
,
document.getElementById('content')
);