Add time picker
This commit is contained in:
parent
ec47ad1622
commit
701a55ce29
@ -109,19 +109,23 @@ class TimeScheduleWidget extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RoutePlanner extends Component {
|
class RouteSearch extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
const now = new Date();
|
||||||
this.state = {
|
this.state = {
|
||||||
fromStation: "",
|
fromStation: "",
|
||||||
toStation: "",
|
toStation: "",
|
||||||
|
depart: 'now',
|
||||||
|
min: now.getMinutes(),
|
||||||
|
hour: now.getHours(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props, state) {
|
static getDerivedStateFromProps(props, state) {
|
||||||
if (state.fromStation === "" && props.stations && props.stations[0]) {
|
if (state.fromStation === "" && props.stations && props.stations[0]) {
|
||||||
const abbr = props.stations[0].abbr;
|
const abbr = props.stations[0].abbr;
|
||||||
return { fromStation: abbr, toStation: abbr};
|
return { ...state, fromStation: abbr, toStation: abbr};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -143,7 +147,53 @@ class RoutePlanner extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderStationForm() {
|
setDepartNow(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
this.setState({depart: "now"});
|
||||||
|
}
|
||||||
|
|
||||||
|
setDepartAt(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
const now = new Date();
|
||||||
|
this.setState({
|
||||||
|
depart: "givenTime",
|
||||||
|
hour: now.getHours(),
|
||||||
|
min: now.getMinutes(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
renderTimePicker() {
|
||||||
|
const state = this.state;
|
||||||
|
const departNow = this.state.depart === 'now';
|
||||||
|
return (<div style={{display: "flex"}}>
|
||||||
|
<div>
|
||||||
|
<a href="" onClick={ this.setDepartNow.bind(this) }>
|
||||||
|
<div>
|
||||||
|
<p>{ departNow ? <b>Now</b> : "Now" }</p>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<a href="" onClick={ this.setDepartAt.bind(this)}>
|
||||||
|
<div>
|
||||||
|
<p>{ departNow ? "At..." : <b>At...</b>}</p>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div></div>
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
<select name="hour" value={this.state.hour} onChange={(evt) => this.setState({hour: evt.target.value}) } disabled={departNow}>
|
||||||
|
{ _.map(_.range(0, 24), (hour) => { return <option key={`h-${hour}`} value={hour}>{hour}</option>;}) }
|
||||||
|
</select>
|
||||||
|
<span>:</span>
|
||||||
|
<select name="min" value={this.state.min} onChange={(evt) => this.setState({min: evt.target.value}) } disabled={departNow}>
|
||||||
|
{ _.map(_.range(0, 60), (min) => { return <option key={`m-${min}`} value={min}>{min}</option>;}) }
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
const receivedStations = this.props.stations;
|
const receivedStations = this.props.stations;
|
||||||
return (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
|
return (<form name="bartSearch" onSubmit={this.stationSearch.bind(this)}>
|
||||||
From:
|
From:
|
||||||
@ -155,9 +205,17 @@ class RoutePlanner extends Component {
|
|||||||
<select disabled={!receivedStations} name="toStation" value={this.state.toStation} onChange={this.changeStation.bind(this)}>
|
<select disabled={!receivedStations} name="toStation" value={this.state.toStation} onChange={this.changeStation.bind(this)}>
|
||||||
{ getOptionsFromStations(receivedStations) }
|
{ getOptionsFromStations(receivedStations) }
|
||||||
</select>
|
</select>
|
||||||
|
<div>
|
||||||
|
Depart at:
|
||||||
|
{ this.renderTimePicker() }
|
||||||
|
</div>
|
||||||
<input type="submit" value="Search"/>
|
<input type="submit" value="Search"/>
|
||||||
</form>);
|
</form>);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoutePlanner extends Component {
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const curTime = this.props.curTime;
|
const curTime = this.props.curTime;
|
||||||
@ -177,8 +235,7 @@ class RoutePlanner extends Component {
|
|||||||
</div>
|
</div>
|
||||||
<div className="searchsidebar" style={{gridColumn: "2", gridRow: "2"}}>
|
<div className="searchsidebar" style={{gridColumn: "2", gridRow: "2"}}>
|
||||||
Search scheduled trains:
|
Search scheduled trains:
|
||||||
{ this.renderStationForm() }
|
<RouteSearch stations={this.props.stations} curTime={curTime} />
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
or see the official bart scheduler for a given station, date and time:
|
or see the official bart scheduler for a given station, date and time:
|
||||||
<ScheduleWidget stations={this.props.stations}/>
|
<ScheduleWidget stations={this.props.stations}/>
|
||||||
|
Loading…
Reference in New Issue
Block a user