Skip to content
Permalink
Browse files

remove duplicate code

  • Loading branch information...
marcomontalbano committed Aug 8, 2019
1 parent d97abcc commit fda435a66336b30cb54d0d749f35b0e51acedb06
Showing with 12 additions and 12 deletions.
  1. +10 −10 src/app/components/Filter.js
  2. +2 −2 src/app/components/Results.js
@@ -18,20 +18,20 @@ class Filter extends Component {
}

componentDidMount() {
this.listener = SpeedtestStore.addListener(this.onSpeedtestStoreHandler.bind(this));
this.listener = SpeedtestStore.addListener(this.onSpeedtestStoreHandler);
}

componentWillUnmount() {
this.listener.remove();
}

onSpeedtestStoreHandler() {
onSpeedtestStoreHandler = () => {
this.setState({
speedtestStore: SpeedtestStore.getState()
});
}

startStopHandler() {
startStopHandler = () => {
if (this.state.speedtestStore.isRunning)  {
this.props.speedtest.stop();
} else {
@@ -43,21 +43,21 @@ class Filter extends Component {
}
}

filterDatacentersHandler(e) {
filterDatacentersHandler = (e) => {
const val = e.target.value;

this.setState(prevState => ({
filterDatacenters: _.xor(prevState.filterDatacenters, [val])
}));
}

filterHandler() {
filterHandler = () => {
this.setState(prevState => ({
isFilterOpen: !prevState.isFilterOpen
}));
}

checkFastestsHandler(e) {
checkFastestsHandler = (e) => {
this.setState({
checkFastests: e.target.checked
});
@@ -67,7 +67,7 @@ class Filter extends Component {
return items.length > 0 ? _.map(items, (item, key) => (
<div key={key} className="Datacenter uk-width-1-2">
<label>
<input disabled={this.state.speedtestStore.isRunning} onChange={this.filterDatacentersHandler.bind(this)} className="uk-checkbox" type="checkbox" value={item.name} defaultChecked={this.state.filterDatacenters.indexOf(item.name) >= 0} /> {item.name}
<input disabled={this.state.speedtestStore.isRunning} onChange={this.filterDatacentersHandler} className="uk-checkbox" type="checkbox" value={item.name} defaultChecked={this.state.filterDatacenters.indexOf(item.name) >= 0} /> {item.name}
</label>
</div>
)) : null;
@@ -93,16 +93,16 @@ class Filter extends Component {
<form>
<fieldset className="uk-fieldset">
<label>
<input className="uk-checkbox" type="checkbox" onClick={this.checkFastestsHandler.bind(this)} disabled={this.state.speedtestStore.isRunning} defaultChecked={this.state.checkFastests} /> Check only the fastest {this.state.fastestsQnt}
<input className="uk-checkbox" type="checkbox" onClick={this.checkFastestsHandler} disabled={this.state.speedtestStore.isRunning} defaultChecked={this.state.checkFastests} /> Check only the fastest {this.state.fastestsQnt}
</label>
</fieldset>
</form>
</div>
<div className="uk-width-1-1 uk-width-1-5@s uk-text-center">
<button className="uk-button uk-button-primary uk-width-1-1" onClick={this.startStopHandler.bind(this)}>{this.state.speedtestStore.isRunning ? 'stop' : 'start'}</button>
<button className="uk-button uk-button-primary uk-width-1-1" onClick={this.startStopHandler}>{this.state.speedtestStore.isRunning ? 'stop' : 'start'}</button>
</div>
<div className="uk-width-1-1 uk-width-1-5@s uk-text-center">
<button className="uk-button uk-button-default uk-width-1-1" onClick={this.filterHandler.bind(this)}>filter</button>
<button className="uk-button uk-button-default uk-width-1-1" onClick={this.filterHandler}>filter</button>
</div>
</div>
{ this.state.isFilterOpen &&
@@ -15,14 +15,14 @@ class Results extends Component {
}

componentDidMount() {
this.listener = SpeedtestStore.addListener(this.onSpeedtestStoreHandler.bind(this));
this.listener = SpeedtestStore.addListener(this.onSpeedtestStoreHandler);
}

componentWillUnmount() {
this.listener.remove();
}

onSpeedtestStoreHandler() {
onSpeedtestStoreHandler = () => {
this.setState({
speedtestStore: SpeedtestStore.getState()
});

0 comments on commit fda435a

Please sign in to comment.
You can’t perform that action at this time.