TimeScheduleWidget

This commit is contained in:
ronreg-ribdev 2020-06-01 02:00:04 -07:00
parent 30711cf98c
commit 574115922f

View File

@ -3,6 +3,34 @@ import { BrowserRouter, Route } from "react-router-dom";
import _ from 'lodash'; import _ from 'lodash';
import { HeaderBar } from "./lib/header-bar.js" import { HeaderBar } from "./lib/header-bar.js"
class TimeScheduleWidget extends Component {
constructor(props) {
super(props)
this.state = { curTime: new Date() };
}
componentDidMount() {
this.timerId = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.timerId);
}
tick() {
this.setState({curTime: new Date()});
}
render() {
const curTime = this.state.curTime;
const timeStr = curTime.toLocaleTimeString();
const serviceStr = curTime.getDay() === 0 ? "Sunday service" : "Weekday / Saturday service";
return (<div style={{textAlign: "center"}}>
<p className="lh-copy measure pt3">Current time: <b>{timeStr}</b></p>
<p className="lh-copy measure pt3">{serviceStr}</p>
</div>);
}
}
export class Root extends Component { export class Root extends Component {
constructor(props) { constructor(props) {
@ -62,8 +90,7 @@ export class Root extends Component {
<h1 className="mt0 f8 fw4">BART Info</h1> <h1 className="mt0 f8 fw4">BART Info</h1>
<div style={{display: "grid", gridTemplateColumns: "66% 34%", gridGap: "10px" }}> <div style={{display: "grid", gridTemplateColumns: "66% 34%", gridGap: "10px" }}>
<div className="topinfo" style={{gridColumn: "1 / 2"}}> <div className="topinfo" style={{gridColumn: "1 / 2"}}>
<p className="lh-copy measure pt3">Current time is (current time)</p> <TimeScheduleWidget/>
<p className="lh-copy measure pt3">Today's bart map:</p>
</div> </div>
<div className="map" style={{gridColumn: "1", gridRow: "2"}}> <div className="map" style={{gridColumn: "1", gridRow: "2"}}>
<img src="/~bartinfo/img/BART-Map-Weekday-Saturday.png" /> <img src="/~bartinfo/img/BART-Map-Weekday-Saturday.png" />