Skip to content

Commit

Permalink
minor refactoring to force spinner more stable - still not fully but …
Browse files Browse the repository at this point in the history
…a bit better
  • Loading branch information
danpriori committed Jul 11, 2024
1 parent 44c7891 commit 63bf233
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export const Reveal3DResources = ({
defaultResourceStyling
);

const setModel3DStylingLoading = useReveal3DResourcesStylingLoadingSetter();
setModel3DStylingLoading(!(isModelMappingsFetched || !isModelMappingsLoading));

useEffect(() => {
setModel3DStylingLoading(!(isModelMappingsFetched || !isModelMappingsLoading));
}, [isModelMappingsFetched, isModelMappingsLoading]);

const instaceStylingWithAssetMappings =
instanceStyling?.filter(isAssetMappingStylingGroup) ?? EMPTY_ARRAY;

Expand Down Expand Up @@ -131,10 +138,6 @@ export const Reveal3DResources = ({
}
};

const setModel3DStylingLoading = useReveal3DResourcesStylingLoadingSetter();

setModel3DStylingLoading(!(isModelMappingsFetched || !isModelMappingsLoading));

return (
<>
{styledCadModelOptions.map(({ styleGroups, model }, index) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ export const RuleBasedOutputsButton = ({
const isRuleLoadingFromContext = useReveal3DResourcesStylingLoading();
const setModel3DStylingLoading = useReveal3DResourcesStylingLoadingSetter();

const ruleInstancesResult = useFetchRuleInstances();
const { data: ruleInstancesResult } = useFetchRuleInstances();

useEffect(() => {
if (ruleInstancesResult.data === undefined) return;

setRuleInstances(ruleInstancesResult.data);
setRuleInstances(ruleInstancesResult);
}, [ruleInstancesResult]);

useEffect(() => {
setCurrentRuleSetEnabled(newRuleSetEnabled);
if (onRuleSetSelectedChanged !== undefined) onRuleSetSelectedChanged(newRuleSetEnabled);

const hasNewRuleSetEnabled = newRuleSetEnabled !== undefined;

Expand All @@ -73,8 +72,8 @@ export const RuleBasedOutputsButton = ({
currentStylingGroups !== undefined &&
currentStylingGroups.length > 0 &&
isRuleLoadingFromContext;

setIsRuleLoading(hasRuleLoading);
setModel3DStylingLoading(hasRuleLoading);
}, [isRuleLoadingFromContext, currentStylingGroups]);

const onChange = useCallback(
Expand All @@ -97,10 +96,10 @@ export const RuleBasedOutputsButton = ({
if (onRuleSetStylingChanged !== undefined) onRuleSetStylingChanged(undefined);
}

if (onRuleSetSelectedChanged !== undefined) onRuleSetSelectedChanged(selectedRule);

setEmptyRuleSelected(emptySelection);
setNewRuleSetEnabled(selectedRule);
setIsRuleLoading(true);
setModel3DStylingLoading(true);
},
[ruleInstances, onRuleSetStylingChanged, onRuleSetSelectedChanged]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { type UseQueryResult, useQuery } from '@tanstack/react-query';
import { type RuleAndEnabled, type RuleOutputSet } from '../types';
import { fdmViewsExist } from '../../../utilities/fdmViewsExist';

export const useFetchRuleInstances = (): UseQueryResult<RuleAndEnabled[], unknown> => {
export const useFetchRuleInstances = (): UseQueryResult<RuleAndEnabled[], undefined> => {
const fdmSdk = useFdmSdk();

return useQuery({
Expand Down

0 comments on commit 63bf233

Please sign in to comment.