Skip to content

Commit

Permalink
Fixes from pairing with Fabs & Mike (#2420)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwallacespeckle authored Jun 21, 2024
1 parent b5452de commit 25c92ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
11 changes: 9 additions & 2 deletions packages/frontend-2/lib/viewer/composables/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export type InjectableViewerState = Readonly<{
views: ComputedRef<SpeckleView[]>
filteringState: ComputedRef<Optional<FilteringState>>
}
/**
* Whether the Viewer has finished doing the initial object loading
*/
hasDoneInitialLoad: Ref<boolean>
}
/**
* Loaded/loadable resources
Expand Down Expand Up @@ -395,6 +399,7 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState {
createViewerDataBuilder({ viewerDebug })
) || { initPromise: Promise.resolve() }
initPromise.then(() => (isInitialized.value = true))
const hasDoneInitialLoad = ref(false)

return {
projectId,
Expand All @@ -412,7 +417,8 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState {
availableFilters: computed(() => undefined),
views: computed(() => []),
filteringState: computed(() => undefined)
}
},
hasDoneInitialLoad
} as unknown as InitialSetupState['viewer'])
: {
instance,
Expand All @@ -421,7 +427,8 @@ function setupInitialState(params: UseSetupViewerParams): InitialSetupState {
promise: initPromise,
ref: computed(() => isInitialized.value)
},
metadata: setupViewerMetadata({ viewer: instance })
metadata: setupViewerMetadata({ viewer: instance }),
hasDoneInitialLoad
},
urlHashState: setupUrlHashState()
}
Expand Down
18 changes: 11 additions & 7 deletions packages/frontend-2/lib/viewer/composables/setup/postSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ function useViewerObjectAutoLoading() {
projectId,
viewer: {
instance: viewer,
init: { ref: isInitialized }
init: { ref: isInitialized },
hasDoneInitialLoad
},
resources: {
response: { resourceItems }
Expand Down Expand Up @@ -112,21 +113,24 @@ function useViewerObjectAutoLoading() {
uniq(resourceItems.map((i) => i.objectId))

watch(
() => <const>[resourceItems.value, isInitialized.value],
async ([newResources, newIsInitialized], oldData) => {
() => <const>[resourceItems.value, isInitialized.value, hasDoneInitialLoad.value],
async ([newResources, newIsInitialized, newHasDoneInitialLoad], oldData) => {
// Wait till viewer loaded in
if (!newIsInitialized) return

const [oldResources, oldIsInitialized] = oldData || [[], false]
const [oldResources] = oldData || [[], false]
const zoomToObject = !focusedThreadId.value // we want to zoom to the thread instead

// Viewer initialized - load in all resources
if (newIsInitialized && !oldIsInitialized) {
if (!newHasDoneInitialLoad) {
const allObjectIds = getUniqueObjectIds(newResources)

await Promise.all(
const res = await Promise.all(
allObjectIds.map((i) => loadObject(i, false, { zoomToObject }))
)
if (res.length) {
hasDoneInitialLoad.value = true
}

return
}
Expand All @@ -139,7 +143,7 @@ function useViewerObjectAutoLoading() {

await Promise.all(removableObjectIds.map((i) => loadObject(i, true)))
await Promise.all(
addableObjectIds.map((i) => loadObject(i, false, { zoomToObject }))
addableObjectIds.map((i) => loadObject(i, false, { zoomToObject: false }))
)
},
{ deep: true, immediate: true }
Expand Down

0 comments on commit 25c92ff

Please sign in to comment.