aboutsummaryrefslogtreecommitdiff
path: root/src/App.jsx
blob: 7398ba21cc8be149cd6603d5f1a88d6626c52fbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { useLocation, Routes, Route, Link } from "react-router-dom";
import { useState, lazy, Suspense } from "react";
import useFetch from "./useFetch";
import { DateTime } from "luxon";
import "./App.css";
const Index = lazy(() => import("./pages/Index"));
const Graph = lazy(() => import("./pages/Graph"));
import { useEffect } from "react";

const App = () => {
    const url = localStorage.getItem("url") ?? "/data.json";

    let routerLocation = useLocation();
    useEffect(() => {
        !window.goatcounter ??
            window.goatcounter.count({
                path: location.pathname + location.search + location.hash,
            });
    }, [routerLocation]);

    const response = useFetch(url);

    const [timeDifference, setTimeDifference] = useState(1);

    return (
        <div className="App">
            <header>
                <Link to="/">
                    <h1>2021-2022 RIT COVID Dashboard</h1>
                </Link>
            </header>
            <Routes>
                <Route
                    path="/totalstudents"
                    element={
                        <Suspense fallback={null}>
                            <Graph
                                name={"Total Student Cases"}
                                response={response}
                                dataKey={"total_students"}
                                timeDifference={timeDifference}
                            />
                        </Suspense>
                    }
                ></Route>
                <Route
                    path="/totalstaff"
                    element={
                        <Suspense fallback={null}>
                            <Graph
                                name={"Total Staff Cases"}
                                response={response}
                                dataKey={"total_staff"}
                                timeDifference={timeDifference}
                            />
                        </Suspense>
                    }
                ></Route>
                <Route
                    path="/newstudents"
                    element={
                        <Suspense fallback={null}>
                            <Graph
                                name={"New Student Cases"}
                                response={response}
                                dataKey={"new_students"}
                                timeDifference={timeDifference}
                            />
                        </Suspense>
                    }
                ></Route>
                <Route
                    path="/newstaff"
                    element={
                        <Suspense fallback={null}>
                            <Graph
                                name={"New Staff Cases"}
                                response={response}
                                dataKey={"new_staff"}
                                timeDifference={timeDifference}
                            />
                        </Suspense>
                    }
                ></Route>
                <Route
                    exact
                    path="/"
                    element={
                        <Suspense fallback={null}>
                            <Index response={response} timeDifference={timeDifference} />
                        </Suspense>
                    }
                />
            </Routes>
            <footer>
                <p>
                    By Galen Guyer. Source available on{" "}
                    <a className="BlueLink" href="https://github.com/galenguyer/rit-covid-dashboard">
                        GitHub
                    </a>{" "}
                    (
                    <a className="BlueLink" href="https://github.com/galenguyer/rit-covid-dashboard/issues">
                        Report Issue
                    </a>
                    )
                </p>
                <p>
                    <a className="BlueLink" href="https://galenguyer.com/projects/ritcoviddashboard">
                        API Documentation
                    </a>
                </p>
            </footer>
            <script data-goatcounter="https://rcd.goatcounter.com/count" async src="//gc.zgo.at/count.js"></script>
        </div>
    );
};

const Updated = (props) => {
    const { loading, lastUpdate, priorUpdate, timeDifference } = props;
    if (loading) {
        return <div></div>;
    }

    return (
        <div className="Updated">
            <div className="Latest">
                Last Updated:{" "}
                {lastUpdate.toLocaleString({
                    weekday: "long",
                    month: "long",
                    day: "2-digit",
                    hour: "2-digit",
                    minute: "2-digit",
                })}
            </div>
            <div className="Prior">
                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"})
            </div>
        </div>
    );
};

export default App;