From ec4abff2a35ea478c78d0750fe9b262ed8f3458a Mon Sep 17 00:00:00 2001 From: Abby Wheelis Date: Thu, 9 Nov 2023 09:52:03 -0700 Subject: [PATCH] ensure initialization of footprints we need to initialize the footprints before we can call them, accomplish this by calling the initialization function from the metrics tab once the app config is loaded --- www/js/metrics/MetricsTab.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/www/js/metrics/MetricsTab.tsx b/www/js/metrics/MetricsTab.tsx index d23cdd454..6385e2fd3 100644 --- a/www/js/metrics/MetricsTab.tsx +++ b/www/js/metrics/MetricsTab.tsx @@ -17,6 +17,8 @@ import DailyActiveMinutesCard from './DailyActiveMinutesCard'; import CarbonTextCard from './CarbonTextCard'; import ActiveMinutesTableCard from './ActiveMinutesTableCard'; import { getAggregateData, getMetrics } from '../commHelper'; +import useAppConfig from '../useAppConfig'; +import { initCustomDatasetHelper } from './CustomMetricsHelper'; export const METRIC_LIST = ['duration', 'mean_speed', 'count', 'distance'] as const; @@ -41,6 +43,7 @@ function getLastTwoWeeksDtRange() { const MetricsTab = () => { const { t } = useTranslation(); + const appConfig = useAppConfig(); const { getFormattedSpeed, speedSuffix, getFormattedDistance, distanceSuffix } = useImperialConfig(); @@ -53,6 +56,12 @@ const MetricsTab = () => { loadMetricsForPopulation('aggregate', dateRange); }, [dateRange]); + //initialize once config is populated + useEffect(() => { + if (!appConfig) return; + initCustomDatasetHelper(appConfig); + }, [appConfig]); + async function loadMetricsForPopulation(population: 'user' | 'aggregate', dateRange: DateTime[]) { const serverResponse = await fetchMetricsFromServer(population, dateRange); console.debug('Got metrics = ', serverResponse);