diff --git a/frontend/src/components/Graph.js b/frontend/src/components/Graph.js index 5b1936716c47cf43409cf48943f655a982e0063b..776c27282327fbf18479242f3df2accd97d7e3c2 100644 --- a/frontend/src/components/Graph.js +++ b/frontend/src/components/Graph.js @@ -11,33 +11,19 @@ import { } from "recharts"; import "../styles/Graph.css"; -export default function DailyGraph({ place }) { - const [day, min_time_hour, min_time_mn, max_time_hour, max_time_mn, interval] = [ - 3, 12, 0, 12, 40, 300, - ]; - const url = - process.env.REACT_APP_BASE_URL_BACK + - "/" + - place + - "/stats/" + - day + - "/" + - min_time_hour + - "/" + - min_time_mn + - "/" + - max_time_hour + - "/" + - max_time_mn + - "/" + - interval; - - const [data, setData] = React.useState([]); +export default function Graph({ place, type }) { + const [data, setData] = React.useState(null); React.useEffect(() => { - axios.get(url).then((response) => { - setData(response.data); - }); - }, [url]); + axios + .get( + `${process.env.REACT_APP_BASE_URL_BACK}/${encodeURIComponent(place)}/${encodeURIComponent( + type, + )}_graph`, + ) + .then((response) => { + setData(response.data); + }); + }, []); if (!data) return null; const CustomTooltip = ({ active, payload }) => { diff --git a/frontend/src/components/index.js b/frontend/src/components/index.js index 76758d28d9f9c9649ce6125ea0b07e3862024fb3..2ed4f885eb4c32b29c408a9496126867c343bf1d 100644 --- a/frontend/src/components/index.js +++ b/frontend/src/components/index.js @@ -2,5 +2,5 @@ export { default as Header } from "./Header"; export { default as Footer } from "./Footer"; export { default as Timetable } from "./Timetable"; export { default as WaitingTime } from "./WaitingTime"; -export { default as DailyGraph } from "./Graph"; +export { default as Graph } from "./Graph"; export { default as Comments } from "./Comments"; diff --git a/frontend/src/views/Restaurant.js b/frontend/src/views/Restaurant.js index ab762aa581986bc85a13f6b86b4678af365249b9..827eaf7e3aba8e3a13b34a54d620c6f48367bd12 100644 --- a/frontend/src/views/Restaurant.js +++ b/frontend/src/views/Restaurant.js @@ -1,6 +1,6 @@ import React from "react"; -import { DailyGraph, WaitingTime, Comments } from "../components"; +import { Graph, WaitingTime, Comments } from "../components"; import "../styles/restaurant.css"; @@ -12,9 +12,10 @@ export default function RestaurantPage({ selection }) { <Comments place={selection.name} infos /> <div className="restaurant-container" id="restaurant-main-page"> <WaitingTime place={selection.name} /> - <DailyGraph place={selection.name} /> + <Graph place={selection.name} type="current" /> </div> <Comments place={selection.name} /> + {/*<Graph place={selection.name} type="avg" />*/} </div> )} </>