From 264e571b0ca34d24f4997c5864a43d4f475e14dc Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Wed, 13 Apr 2022 19:10:44 -0400 Subject: full version 2 re-write --- src/App.jsx | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/App.jsx (limited to 'src/App.jsx') diff --git a/src/App.jsx b/src/App.jsx new file mode 100644 index 0000000..af8f570 --- /dev/null +++ b/src/App.jsx @@ -0,0 +1,142 @@ +import { BrowserRouter, Routes, Route, Link } from "react-router-dom"; +import { useState } from "react"; +import useFetch from "./useFetch"; +import Index from "./pages/Index"; +import { DateTime } from "luxon"; +import "./App.css"; +import Graph from "./pages/Graph"; + +const App = () => { + const url = localStorage.getItem("url") ?? "https://ritcoviddashboard.com/api/v0/history"; + + const response = useFetch(url); + + const [timeDifference, setTimeDifference] = useState(1); + const local = DateTime.local().zoneName; + + let data = response.data ?? []; + + const latest = response.loading ? null : data[data.length - 1]; + const prior = response.loading ? null : data[data.length - (1 + timeDifference)]; + + const lastUpdate = response.loading ? null : DateTime.fromSQL(latest.last_updated).setZone(local); + const priorUpdate = response.loading ? null : DateTime.fromSQL(prior.last_updated).setZone(local); + + return ( + +
+
+ +

RIT COVID Dashboard

+ + +
+ + + } + > + + } + > + + } + > + + } + > + } /> + + +
+
+ ); +}; + +const Updated = (props) => { + const { loading, lastUpdate, priorUpdate, timeDifference } = props; + if (loading) { + return
; + } + + return ( +
+
+ Last Updated:{" "} + {lastUpdate.toLocaleString({ + weekday: "long", + month: "long", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + })} +
+
+ Prior Update:{" "} + {priorUpdate.toLocaleString({ + weekday: "long", + month: "long", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + })}{" "} + ({timeDifference == 1 ? "one weekday ago" : timeDifference == 5 ? "one week ago" : "two weeks ago"}) +
+
+ ); +}; + +export default App; -- cgit v1.2.3