Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 38x 38x 38x 38x 1x 1x 38x 38x 35x 88x 32x 24x 37x 37x 88x | import { useState } from "react";
import BasicLayout from "main/layouts/BasicLayout/BasicLayout";
import { useQueries } from "react-query";
import axios from "axios";
import { useBackend } from "main/utils/useBackend";
import DiningCommonsTable from "main/components/DiningCommons/DiningCommonsTable";
export default function HomePage() {
const { data } = useBackend(
// Stryker disable next-line all : don't test internal caching of React Query
[`/api/dining/all`],
{ method: "GET", url: "/api/dining/all" },
[],
);
const date = new Date().toISOString().split("T")[0];
const [selectedDate, setSelectedDate] = useState(date);
const onChangeDate = (e) => {
const newDate = e.target.value;
setSelectedDate(newDate);
};
const queries = [];
if (Array.isArray(data)) {
for (const d of data) {
queries.push({
queryKey: ["meals", d.code, selectedDate],
queryFn: () =>
axios
.get(`/api/diningcommons/${selectedDate}/${d.code}`)
.then((res) => res.data),
});
}
}
const mealsOffered = useQueries(queries);
const combined = Array.isArray(data)
? data.map((d, i) => ({
...d,
mealsOfferedToday: mealsOffered[i]?.data ?? [],
}))
: // Stryker disable next-line all : default empty array when dining data is missing
[];
return (
<BasicLayout>
<h1>Dining Commons</h1>
<p>
<label htmlFor="dateSelector">Select Date:</label>
<br></br>
<input
type="date"
id="dateSelector"
name="dateSelector"
value={selectedDate}
onChange={onChangeDate}
/>
</p>
<DiningCommonsTable commons={combined} date={selectedDate} />
</BasicLayout>
);
}
|