-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-components): Ensure that SceneContainer only registers "all…
…-loaded" once (#4932) * fix(react-components): Ensure that SceneContainer only registers "all-loaded" once * chore: lint fix * chore: use input resources as ground thruth of expected resources * chore: make sure loaderror counts reset * chore: move functions, lint fix * chore: don't use useEffect for cleanup * chore: lint fix
- Loading branch information
1 parent
923b974
commit cf731a8
Showing
9 changed files
with
126 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
react-components/src/components/Reveal3DResources/hooks/useCallCallbackOnFinishedLoading.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
import { useEffect } from 'react'; | ||
import { type AddResourceOptions } from '../types'; | ||
import { | ||
useReveal3DResourceLoadFailCount, | ||
useReveal3DResourcesCount, | ||
useReveal3DResourcesExpectedInViewerCount | ||
} from '../Reveal3DResourcesInfoContext'; | ||
|
||
export function useCallCallbackOnFinishedLoading( | ||
resources: AddResourceOptions[], | ||
onResourcesAdded: (() => void) | undefined | ||
): void { | ||
const loadedCount = useReveal3DResourcesCount().reveal3DResourcesCount; | ||
const expectedLoadCount = useReveal3DResourcesExpectedInViewerCount(); | ||
const { reveal3DResourceLoadFailCount } = useReveal3DResourceLoadFailCount(); | ||
|
||
useEffect(() => { | ||
if (loadedCount === resources.length - reveal3DResourceLoadFailCount) { | ||
onResourcesAdded?.(); | ||
} | ||
}, [loadedCount, expectedLoadCount]); | ||
} |
18 changes: 18 additions & 0 deletions
18
react-components/src/components/Reveal3DResources/hooks/useSetExpectedLoadCount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*! | ||
* Copyright 2024 Cognite AS | ||
*/ | ||
import { useEffect } from 'react'; | ||
import { type AddResourceOptions } from '..'; | ||
import { | ||
useReveal3DResourcesCount, | ||
useReveal3DResourcesSetExpectedToLoadCount | ||
} from '../Reveal3DResourcesInfoContext'; | ||
|
||
export function useSetExpectedLoadCount(resources: AddResourceOptions[]): void { | ||
const setExpectedToLoadCount = useReveal3DResourcesSetExpectedToLoadCount(); | ||
const { setRevealResourcesCount } = useReveal3DResourcesCount(); | ||
|
||
useEffect(() => { | ||
setExpectedToLoadCount(resources.length); | ||
}, [resources, setRevealResourcesCount]); | ||
} |
Oops, something went wrong.