From 5699c485f7aec83c88afa23b1732400b4a9395d4 Mon Sep 17 00:00:00 2001 From: Galen Guyer Date: Sat, 14 Nov 2020 20:21:52 -0500 Subject: add toggle for one day or week ago --- src/App.js | 12 +++++++++++- src/Card.js | 6 +++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 3c0b486..68d7f08 100644 --- a/src/App.js +++ b/src/App.js @@ -1,3 +1,4 @@ +import React from "react"; import useSWR from "swr"; import { DateTime } from "luxon"; import { BrowserRouter, Route, Switch, Link } from "react-router-dom"; @@ -10,6 +11,8 @@ const url = "https://ritcoviddashboard.com/api/v0/history"; function App() { const { data: data, error: error } = useSWR(url); + const [timeDifference, setTimeDifference] = React.useState(1); + if (error) return (
@@ -26,7 +29,7 @@ function App() { ); const latest = data[data.length - 1]; - const prior = data[data.length - 2]; + const prior = data[data.length - (1 + timeDifference)]; const local = DateTime.local().zoneName; const lastUpdate = DateTime.fromSQL(latest.last_updated, { zone: "UTC" }).setZone(local); const priorUpdate = DateTime.fromSQL(prior.last_updated, { zone: "UTC" }).setZone(local); @@ -57,6 +60,13 @@ function App() { minute: "2-digit", })} + +
diff --git a/src/Card.js b/src/Card.js index 86ee54d..a296681 100644 --- a/src/Card.js +++ b/src/Card.js @@ -8,8 +8,8 @@ const Card = (props) => { diff = "+" + diff.toString(); } return ( - -
+ +

{props.latest} @@ -21,7 +21,7 @@ const Card = (props) => {

{props.name}

-
+
); }; -- cgit v1.2.3