Skip to content

Commit

Permalink
Fix failing to rerender on new analysis bug
Browse files Browse the repository at this point in the history
  • Loading branch information
chowington committed Oct 2, 2023
1 parent 8071c9f commit 371ca5b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/libs/eda/src/lib/map/analysis/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getOrElseW } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/function';
import * as t from 'io-ts';
import { isEqual } from 'lodash';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useAnalysis, useGetDefaultVariableDescriptor } from '../../core';
import { VariableDescriptor } from '../../core/types/variable';
import { useGetDefaultTimeVariableDescriptor } from './hooks/eztimeslider';
Expand Down Expand Up @@ -122,11 +122,11 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
const analysisState = useAnalysis(analysisId);

// make some backwards compatability updates to the appstate retrieved from the back end
const appStateCheckedRef = useRef(false);
const [appStateChecked, setAppStateChecked] = useState(false);

useEffect(() => {
// flip bit when analysis id changes
appStateCheckedRef.current = false;
setAppStateChecked(false);
}, [analysisId]);

const { analysis, setVariableUISettings } = analysisState;
Expand Down Expand Up @@ -184,7 +184,7 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
);

useEffect(() => {
if (appStateCheckedRef.current) return;
if (appStateChecked) return;
if (analysis) {
if (!appState) {
setVariableUISettings((prev) => ({
Expand Down Expand Up @@ -219,9 +219,16 @@ export function useAppState(uiStateKey: string, analysisId?: string) {
}));
}
}
appStateCheckedRef.current = true;
setAppStateChecked(true);
}
}, [analysis, appState, setVariableUISettings, uiStateKey, defaultAppState]);
}, [
analysis,
appState,
setVariableUISettings,
uiStateKey,
defaultAppState,
appStateChecked,
]);

function useSetter<T extends keyof AppState>(key: T) {
return useCallback(
Expand Down

0 comments on commit 371ca5b

Please sign in to comment.