Skip to content

Commit

Permalink
split into different useEffects hooks to let render the spinner sooner
Browse files Browse the repository at this point in the history
  • Loading branch information
danpriori committed Jun 28, 2024
1 parent 2c1857c commit 67a8b9d
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ export const RuleBasedOutputsButton = ({
const { t } = useTranslation();
const models = use3dModels();
const cadModels = models.filter((model) => model.type === 'cad') as CadModelOptions[];

const { isLoading: isAssetMappingsLoading } = useAssetMappedNodesForRevisions(cadModels);
const [isRuleLoading, setIsRuleLoading] = useState(false);

const [newRuleSetEnabled, setNewRuleSetEnabled] = useState<RuleAndEnabled>();

const ruleInstancesResult = useFetchRuleInstances();

useEffect(() => {
Expand All @@ -46,11 +49,13 @@ export const RuleBasedOutputsButton = ({
setRuleInstances(ruleInstancesResult.data);
}, [ruleInstancesResult]);

useEffect(() => {
setCurrentRuleSetEnabled(newRuleSetEnabled);
}, [newRuleSetEnabled]);

const onChange = useCallback(
(data: string | undefined): void => {

setIsRuleLoading(true);

ruleInstances?.forEach((item) => {
if (item === undefined) return;
item.isEnabled = false;
Expand Down Expand Up @@ -80,8 +85,10 @@ export const RuleBasedOutputsButton = ({

if (callbackFunction !== undefined) callbackFunction(callbackLoaded);

setIsRuleLoading(true);

setEmptyRuleSelected(emptySelection);
setCurrentRuleSetEnabled(selectedRule);
setNewRuleSetEnabled(selectedRule);
},
[ruleInstances, onRuleSetStylingChanged, onRuleSetSelectedChanged]
);
Expand Down

0 comments on commit 67a8b9d

Please sign in to comment.