From 4761e36a927ca6ddfff47a1572ec3bf62ae9cf02 Mon Sep 17 00:00:00 2001 From: Jim O'Donnell Date: Wed, 18 Aug 2021 10:05:01 +0100 Subject: [PATCH] Refactor the daily counts Calculation of the daily counts is a bit hard to follow. This might help clarify it. --- .../DailyClassificationsChartContainer.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/app-project/src/screens/ClassifyPage/components/YourStats/components/DailyClassificationsChart/DailyClassificationsChartContainer.js b/packages/app-project/src/screens/ClassifyPage/components/YourStats/components/DailyClassificationsChart/DailyClassificationsChartContainer.js index 2e95b74c0b..975b78868d 100644 --- a/packages/app-project/src/screens/ClassifyPage/components/YourStats/components/DailyClassificationsChart/DailyClassificationsChartContainer.js +++ b/packages/app-project/src/screens/ClassifyPage/components/YourStats/components/DailyClassificationsChart/DailyClassificationsChartContainer.js @@ -13,14 +13,15 @@ function DailyClassificationsChartContainer({ thisWeek = [] }) { const TODAY = new Date() - const stats = thisWeek.map(stat => { - const day = new Date(stat.period) - const locale = counterpart.getLocale() - const count = (day.getUTCDay() === TODAY.getDay()) ? counts.today : stat.count + const locale = counterpart.getLocale() + const stats = thisWeek.map(({ count: statsCount, period }) => { + const day = new Date(period) + const isToday = day.getUTCDay() === TODAY.getDay() + const count = isToday ? counts.today : statsCount const longLabel = day.toLocaleDateString(locale, { timeZone: 'UTC', weekday: 'long' }) const alt = `${longLabel}: ${count}` const label = day.toLocaleDateString(locale, { timeZone: 'UTC', weekday: 'narrow' }) - return Object.assign({}, stat, { alt, count, label, longLabel }) + return { alt, count, label, longLabel, period } }) return (