@@ -35,6 +35,11 @@ import {
35
35
sendUserSurveyHidden ,
36
36
sendUserSurveyStarted ,
37
37
} from '../../../Utils/Analytics/EventSender' ;
38
+ import { type RouteArguments } from '../../RouterContext' ;
39
+
40
+ const isShopRequested = ( routeArguments : RouteArguments ) : boolean =>
41
+ routeArguments [ 'initial-dialog' ] === 'asset-store' || // Compatibility with old links
42
+ routeArguments [ 'initial-dialog' ] === 'store' ; // New way of opening the store
38
43
39
44
const styles = {
40
45
container : {
@@ -173,18 +178,49 @@ export const HomePage = React.memo<Props>(
173
178
174
179
const [ activeTab , setActiveTab ] = React . useState < HomeTab > ( initialTab ) ;
175
180
181
+ const { routeArguments, removeRouteArguments } = React . useContext (
182
+ RouterContext
183
+ ) ;
184
+ const { setInitialPackUserFriendlySlug } = React . useContext (
185
+ AssetStoreContext
186
+ ) ;
187
+ const isShopRequestedAtOpening = React . useRef < boolean > (
188
+ isShopRequested ( routeArguments )
189
+ ) ;
190
+
191
+ // Open the store and a pack or game template if asked to do so.
176
192
React . useEffect (
177
193
( ) => {
178
- if ( initialTab === 'get-started' ) {
179
- incrementGetStartedSectionViewCount ( ) ;
194
+ if ( isShopRequested ( routeArguments ) ) {
195
+ setActiveTab ( 'shop' ) ;
196
+ if ( routeArguments [ 'asset-pack' ] ) {
197
+ setInitialPackUserFriendlySlug ( routeArguments [ 'asset-pack' ] ) ;
198
+ }
199
+ if ( routeArguments [ 'game-template' ] ) {
200
+ setInitialGameTemplateUserFriendlySlug (
201
+ routeArguments [ 'game-template' ]
202
+ ) ;
203
+ }
204
+ // Remove the arguments so that the asset store is not opened again.
205
+ removeRouteArguments ( [
206
+ 'initial-dialog' ,
207
+ 'asset-pack' ,
208
+ 'game-template' ,
209
+ ] ) ;
180
210
}
181
211
} ,
182
- [ initialTab ]
212
+ [
213
+ routeArguments ,
214
+ removeRouteArguments ,
215
+ setInitialPackUserFriendlySlug ,
216
+ setInitialGameTemplateUserFriendlySlug ,
217
+ ]
183
218
) ;
184
219
185
220
// If the user is not authenticated, the GetStarted section is displayed.
186
221
React . useEffect (
187
222
( ) => {
223
+ if ( isShopRequestedAtOpening . current ) return ;
188
224
if ( shouldChangeTabAfterUserLoggedIn . current ) {
189
225
setActiveTab ( authenticated ? initialTab : 'get-started' ) ;
190
226
}
@@ -210,6 +246,15 @@ export const HomePage = React.memo<Props>(
210
246
[ loginState ]
211
247
) ;
212
248
249
+ React . useEffect (
250
+ ( ) => {
251
+ if ( initialTab === 'get-started' ) {
252
+ incrementGetStartedSectionViewCount ( ) ;
253
+ }
254
+ } ,
255
+ [ initialTab ]
256
+ ) ;
257
+
213
258
// Load everything when the user opens the home page, to avoid future loading times.
214
259
React . useEffect (
215
260
( ) => {
@@ -290,45 +335,6 @@ export const HomePage = React.memo<Props>(
290
335
forceUpdateEditor,
291
336
} ) ) ;
292
337
293
- const { routeArguments, removeRouteArguments } = React . useContext (
294
- RouterContext
295
- ) ;
296
- const { setInitialPackUserFriendlySlug } = React . useContext (
297
- AssetStoreContext
298
- ) ;
299
-
300
- // Open the store and a pack or game template if asked to do so.
301
- React . useEffect (
302
- ( ) => {
303
- if (
304
- routeArguments [ 'initial-dialog' ] === 'asset-store' || // Compatibility with old links
305
- routeArguments [ 'initial-dialog' ] === 'store' // New way of opening the store
306
- ) {
307
- setActiveTab ( 'shop' ) ;
308
- if ( routeArguments [ 'asset-pack' ] ) {
309
- setInitialPackUserFriendlySlug ( routeArguments [ 'asset-pack' ] ) ;
310
- }
311
- if ( routeArguments [ 'game-template' ] ) {
312
- setInitialGameTemplateUserFriendlySlug (
313
- routeArguments [ 'game-template' ]
314
- ) ;
315
- }
316
- // Remove the arguments so that the asset store is not opened again.
317
- removeRouteArguments ( [
318
- 'initial-dialog' ,
319
- 'asset-pack' ,
320
- 'game-template' ,
321
- ] ) ;
322
- }
323
- } ,
324
- [
325
- routeArguments ,
326
- removeRouteArguments ,
327
- setInitialPackUserFriendlySlug ,
328
- setInitialGameTemplateUserFriendlySlug ,
329
- ]
330
- ) ;
331
-
332
338
// If the user logs out and is on the team view section, go back to the build section.
333
339
React . useEffect (
334
340
( ) => {
0 commit comments