From 0fa3b73269b58341e38a020de0c7e3d665cacfcd Mon Sep 17 00:00:00 2001
From: DelGaylord <60885865+DelGaylord@users.noreply.github.com>
Date: Tue, 2 Apr 2024 15:44:36 +0200
Subject: [PATCH] feat: finalisation

---
 src/component/DAOLineChart.js       |  4 ++--
 src/component/Dashboard.js          | 32 +++++++++++++++++------------
 src/component/FalseDataGenerator.js |  2 +-
 src/component/VoteBarGraph.js       |  4 ++--
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/component/DAOLineChart.js b/src/component/DAOLineChart.js
index 48388bf..8f1f15d 100644
--- a/src/component/DAOLineChart.js
+++ b/src/component/DAOLineChart.js
@@ -18,11 +18,11 @@ function DAOLineChart(title, apiData, day) {
     };
 
 
-    const parsedDay = parse(day, 'dd/MM/yy', new Date());
+    const parsedDay = parse(day, 'MM/dd/yy', new Date());
 
     const labels = Array.from({ length: 30 }, (_, index) => {
       const date = addDays(parsedDay, index); // Ajouter les jours pour obtenir les jours suivants
-      return format(date, 'dd/MM/yy'); // Formatage de la date pour l'affichage
+      return format(date, 'MM/dd/yy'); // Formatage de la date pour l'affichage
     });
 
     const data = labels.map(label => apiData[label] || 0);
diff --git a/src/component/Dashboard.js b/src/component/Dashboard.js
index b98fe0d..1e12c05 100644
--- a/src/component/Dashboard.js
+++ b/src/component/Dashboard.js
@@ -16,11 +16,7 @@ const DashBoard = () => {
     const [currentPropo, setCurrentPropo] = useState('')
     const [startDate, setStartDate] = useState(new Date());
 
-    const url = [ 'https://api.ghostnet.tzkt.io/v1/contracts/KT1QTwmF2eptKss2FWbT1rHP5wCERL16kihQ/storage',
-                  'https://api.ghostnet.tzkt.io/v1/contracts/KT1ACcRhzuDzVKpwzjZTudcQchEijvj7b7cp/views/listAllAssociations',
-                  'https://api.ghostnet.tzkt.io/v1/contracts/KT1LnPY3excYVUTLBuCfBbf1hLeGJTLhXNSz/storage',
-                  'https://api.ghostnet.tzkt.io/v1/contracts/KT1Jrg6G9ziKbpSvzPLhjM4pXWYJqxoZdhMZ/views'
-                ]
+    const url = [ 'https://api.ghostnet.tzkt.io/v1/contracts/KT1QTwmF2eptKss2FWbT1rHP5wCERL16kihQ/storage']
 
     const getData = async () => {
         const data = await fetch( url[0], {
@@ -31,14 +27,19 @@ const DashBoard = () => {
         },
         });
         const response = await data.json()
-        console.log(response)
         const objectsArray = Object.values(response);
         let listeAsso= []
+        let day = startDate.getDate()
+        if (day < 10) day = '0' + day
+        let month = startDate.getMonth() + 1
+        if (month < 10) month = '0' + month
+        let year = startDate.getFullYear() - 2000
+        const fullDate = month + '/' + day + '/' + year
         objectsArray.forEach(asso => {
             const assoData= {
                 nom: asso.name,
-                lineData: generateData("01/01/24", 1000),
-                barData: generateData("01/01/24", 20),
+                lineData: generateData(fullDate, 1000),
+                barData: generateData(fullDate, 20),
                 propositions: [ 
                     {nom: 'Proposition 1', pieData: generatePieData() },
                     {nom: 'Proposition 2', pieData: generatePieData() },
@@ -52,9 +53,16 @@ const DashBoard = () => {
 
     const setDataAsso = (assoName) => {
         const asso = association.find(asso => asso.nom === assoName)
-        setLine(DAOLineChart('Nombre de DAO token achetés sur un mois glissant', asso.lineData, "01/01/24"))
-        setBar(VoteBarChart('Nombre de propositions soumises au vote sur un mois glissant', asso.barData, "01/01/24"))
+        let day = startDate.getDate()
+        if (day < 10) day = '0' + day
+        let month = startDate.getMonth() + 1
+        if (month < 10) month = '0' + month
+        let year = startDate.getFullYear() - 2000
+        const fullDate = month + '/' + day + '/' + year
+        setLine(DAOLineChart('Nombre de DAO token achetés sur un mois glissant', asso.lineData, fullDate))
+        setBar(VoteBarChart('Nombre de propositions soumises au vote sur un mois glissant', asso.barData, fullDate))
         setPie('')
+        setCurrentPropo('')
         setCurrentAsso(asso)
     }
 
@@ -65,8 +73,7 @@ const DashBoard = () => {
         let month = date.getMonth() + 1
         if (month < 10) month = '0' + month
         let year = date.getFullYear() - 2000
-        const fullDate = day + '/' + month + '/' + year
-        console.log(fullDate)
+        const fullDate = month + '/' + day + '/' + year
         setLine(DAOLineChart('Nombre de DAO token achetés sur un mois glissant', generateData(fullDate, 1000), fullDate))
         setBar(VoteBarChart('Nombre de propositions soumises au vote sur un mois glissant', generateData(fullDate, 20), fullDate))
     }
@@ -81,7 +88,6 @@ const DashBoard = () => {
         if (line === '' && bar === '' && pie === '') {
             getData()
         }
-          // eslint-disable-next-line react-hooks/exhaustive-deps
     }, [line, bar, pie])
 
     const showAssociation = () => {
diff --git a/src/component/FalseDataGenerator.js b/src/component/FalseDataGenerator.js
index aab7a27..8053a57 100644
--- a/src/component/FalseDataGenerator.js
+++ b/src/component/FalseDataGenerator.js
@@ -4,7 +4,7 @@ export function generateData(startDate, max) {
     let currentDate = startDate;
     const data = {};
     for (let i = 0; i < 30; i++) {
-        const formattedDate = format(currentDate, 'dd/MM/yy');
+        const formattedDate = format(currentDate, 'MM/dd/yy');
         const randomValue = Math.floor(Math.random() * max); 
         data[formattedDate] = randomValue;
         currentDate = addDays(currentDate, 1);
diff --git a/src/component/VoteBarGraph.js b/src/component/VoteBarGraph.js
index 6879ad5..f05ab05 100644
--- a/src/component/VoteBarGraph.js
+++ b/src/component/VoteBarGraph.js
@@ -17,11 +17,11 @@ function VoteBarChart(title, apiData, day) {
     },
   };
 
-  const parsedDay = parse(day, 'dd/MM/yy', new Date());
+  const parsedDay = parse(day, 'MM/dd/yy', new Date());
 
   const labels = Array.from({ length: 30 }, (_, index) => {
     const date = addDays(parsedDay, index); // Ajouter les jours pour obtenir les jours suivants
-    return format(date, 'dd/MM/yy'); // Formatage de la date pour l'affichage
+    return format(date, 'MM/dd/yy'); // Formatage de la date pour l'affichage
   });
 
   const data = labels.map(label => apiData[label] || 0);
-- 
GitLab