From 574115922f80b14d95e7309afd2bccb7a29bfadb Mon Sep 17 00:00:00 2001 From: ronreg-ribdev <56719257+ronreg-ribdev@users.noreply.github.com> Date: Mon, 1 Jun 2020 02:00:04 -0700 Subject: [PATCH] TimeScheduleWidget --- src/js/components/root.js | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/js/components/root.js b/src/js/components/root.js index a864427..07a5e95 100644 --- a/src/js/components/root.js +++ b/src/js/components/root.js @@ -3,6 +3,34 @@ import { BrowserRouter, Route } from "react-router-dom"; import _ from 'lodash'; 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 (
+

Current time: {timeStr}

+

{serviceStr}

+
); + } +} + export class Root extends Component { constructor(props) { @@ -62,8 +90,7 @@ export class Root extends Component {

BART Info

-

Current time is (current time)

-

Today's bart map:

+