From 39943b5f9407f6df80a4846e07786020f5b8582a Mon Sep 17 00:00:00 2001
From: Aymeric Chaumont <aymeric.chaumont@student-cs.fr>
Date: Mon, 11 Jul 2022 10:35:37 +0200
Subject: [PATCH] update front graph component for time-dependance

---
 frontend/src/components/Graph.js | 38 ++++++++++----------------------
 frontend/src/components/index.js |  2 +-
 frontend/src/views/Restaurant.js |  5 +++--
 3 files changed, 16 insertions(+), 29 deletions(-)

diff --git a/frontend/src/components/Graph.js b/frontend/src/components/Graph.js
index 5b19367..776c272 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 76758d2..2ed4f88 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 ab762aa..827eaf7 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>
       )}
     </>
-- 
GitLab