diff --git a/src/component/DAOLineChart.js b/src/component/DAOLineChart.js index 48388bfbea91ce2226963513299da643ef422437..8f1f15d57b6cf58b5aff045703d82f93956bb630 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 b98fe0d859c03c965825fec0c5124637e4a045b8..1e12c050b3b6c0feefac2458866385e17aa07053 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 aab7a277178d3ccf689f8dbdc8427414dbfbc1d0..8053a573d8287a1aee9ffe99da448e51f7cd9d2c 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 6879ad5432cc86fbe2a526c3b668de614e2268bb..f05ab053facc5b62944efccee34d1c79c6f1bece 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);