Skip to content

Commit

Permalink
ensure initialization of footprints
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Abby Wheelis committed Nov 9, 2023
1 parent b075738 commit ec4abff
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions www/js/metrics/MetricsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -41,6 +43,7 @@ function getLastTwoWeeksDtRange() {

const MetricsTab = () => {
const { t } = useTranslation();
const appConfig = useAppConfig();
const { getFormattedSpeed, speedSuffix, getFormattedDistance, distanceSuffix } =
useImperialConfig();

Expand All @@ -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);
Expand Down

0 comments on commit ec4abff

Please sign in to comment.