@@ -5,6 +5,7 @@ import { getInstancesTypes } from '../actions/types/getInstancesTypes';
55import { setFirstIDLoaded , setAlignTemplates , setTemplateID } from '../actions/globals' ;
66import { getInstanceByID , get3DMesh , triggerInstanceFailure , setBulkLoadingCount , clearUrlLoadingState , focusInstance , selectInstance } from '../actions/instances' ;
77import * as GeppettoActions from '@metacell/geppetto-meta-client/common/actions' ;
8+ import { DEFAULT_TEMPLATE_ID } from '../../utils/constants' ;
89
910function updateUrlParameterWithCurrentUrl ( param , value , reset ) {
1011 const urlObj = new URL ( window . location . href ) ;
@@ -54,7 +55,7 @@ function updateUrlWithInstancesAndSelectedId(selectedId, store) {
5455 }
5556}
5657
57- const DEFAULT_ID = "VFB_00101567" ;
58+ const DEFAULT_ID = DEFAULT_TEMPLATE_ID ;
5859const APP_LOADED_FLAG_KEY = "CURRENT_LOADED_URL" ;
5960
6061// Track the initial focus ID from URL to prevent templates from overwriting it
@@ -95,8 +96,8 @@ const isFirstTimeLoad = (allLoadedInstances, store) => {
9596 }
9697
9798 // id= parameter should always take priority for focus
98- const focusTarget = idSelected ||
99- ( queuedInstances . length > 0
99+ const focusTarget = idSelected ||
100+ ( queuedInstances . length > 0
100101 ? queuedInstances [ queuedInstances . length - 1 ]
101102 : uniqueLoadOrder [ uniqueLoadOrder . length - 1 ] ) ;
102103
@@ -150,9 +151,14 @@ export const urlUpdaterMiddleware = store => next => (action) => {
150151 const state = store . getState ( ) . instances ;
151152 const newFinishedCount = state . finishedLoadedInstances + 1 ;
152153 const isAllBulkInstancesLoaded = state . isBulkLoading && newFinishedCount >= state . bulkLoadingCount ;
153-
154+
154155 // If bulk loading completed from URL, apply focus/select and clear the flag
155156 if ( isAllBulkInstancesLoaded && isLoadingFromUrl ) {
157+ if ( ! launchTemplate ?. metadata ?. Id && ! action . payload ?. IsTemplate ) {
158+ getInstanceByID ( DEFAULT_TEMPLATE_ID , true , false , false ) ;
159+ updateUrlParameterWithCurrentUrl ( 'i' , DEFAULT_TEMPLATE_ID , false ) ;
160+ }
161+
156162 const urlParams = new URLSearchParams ( window . location . search ) ;
157163 const pendingFocusId = urlParams . get ( 'id' ) ;
158164
@@ -166,7 +172,7 @@ export const urlUpdaterMiddleware = store => next => (action) => {
166172 await focusInstance ( pendingFocusId ) ;
167173 await selectInstance ( pendingFocusId ) ;
168174 // Clear URL loading state after async operations complete
169- store . dispatch ( clearUrlLoadingState ( ) ) ;
175+ store . dispatch ( clearUrlLoadingState ( ) ) ;
170176 // Clear the initial focus ID after a longer delay to allow all pending template operations to complete
171177 setTimeout ( ( ) => {
172178 initialUrlFocusId = null ;
@@ -176,13 +182,11 @@ export const urlUpdaterMiddleware = store => next => (action) => {
176182 store . dispatch ( clearUrlLoadingState ( ) ) ;
177183 }
178184 }
179-
185+
180186 const IsTemplate = action . payload ?. IsTemplate || false ;
181187 const isClass = action . payload ?. IsClass || false ;
182188 const isIndividual = action . payload ?. IsIndividual || false ;
183189
184-
185-
186190 if ( ! IsTemplate && ! isClass && ! isIndividual ) {
187191 // If the instance is not a template, class, or individual, dispatch the getInstanceFailure with an error message
188192 if ( action . payload ?. Id === undefined ) {
@@ -202,7 +206,7 @@ export const urlUpdaterMiddleware = store => next => (action) => {
202206 }
203207 get3DMesh ( action . payload ) ;
204208 store . dispatch ( setTemplateID ( action . payload . Id ) ) ;
205-
209+
206210 if ( ! ( initialUrlFocusId && initialUrlFocusId !== action . payload . Id ) ) {
207211 updateUrlWithInstancesAndSelectedId ( action . payload . Id , store ) ;
208212 }
0 commit comments