From 4d8cf5692241dda74b855041be3f6a53c590a832 Mon Sep 17 00:00:00 2001 From: AlexandreS <32449369+AlexandreSi@users.noreply.github.com> Date: Wed, 22 Nov 2023 16:29:44 +0100 Subject: [PATCH] Do not change homepage tab at opening if an item from the asset store is requested (#5936) --- .../EditorContainers/HomePage/index.js | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js b/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js index df4eef48bc..e1ee309311 100644 --- a/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js +++ b/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js @@ -35,6 +35,11 @@ import { sendUserSurveyHidden, sendUserSurveyStarted, } from '../../../Utils/Analytics/EventSender'; +import { type RouteArguments } from '../../RouterContext'; + +const isShopRequested = (routeArguments: RouteArguments): boolean => + routeArguments['initial-dialog'] === 'asset-store' || // Compatibility with old links + routeArguments['initial-dialog'] === 'store'; // New way of opening the store const styles = { container: { @@ -173,18 +178,49 @@ export const HomePage = React.memo( const [activeTab, setActiveTab] = React.useState(initialTab); + const { routeArguments, removeRouteArguments } = React.useContext( + RouterContext + ); + const { setInitialPackUserFriendlySlug } = React.useContext( + AssetStoreContext + ); + const isShopRequestedAtOpening = React.useRef( + isShopRequested(routeArguments) + ); + + // Open the store and a pack or game template if asked to do so. React.useEffect( () => { - if (initialTab === 'get-started') { - incrementGetStartedSectionViewCount(); + if (isShopRequested(routeArguments)) { + setActiveTab('shop'); + if (routeArguments['asset-pack']) { + setInitialPackUserFriendlySlug(routeArguments['asset-pack']); + } + if (routeArguments['game-template']) { + setInitialGameTemplateUserFriendlySlug( + routeArguments['game-template'] + ); + } + // Remove the arguments so that the asset store is not opened again. + removeRouteArguments([ + 'initial-dialog', + 'asset-pack', + 'game-template', + ]); } }, - [initialTab] + [ + routeArguments, + removeRouteArguments, + setInitialPackUserFriendlySlug, + setInitialGameTemplateUserFriendlySlug, + ] ); // If the user is not authenticated, the GetStarted section is displayed. React.useEffect( () => { + if (isShopRequestedAtOpening.current) return; if (shouldChangeTabAfterUserLoggedIn.current) { setActiveTab(authenticated ? initialTab : 'get-started'); } @@ -210,6 +246,15 @@ export const HomePage = React.memo( [loginState] ); + React.useEffect( + () => { + if (initialTab === 'get-started') { + incrementGetStartedSectionViewCount(); + } + }, + [initialTab] + ); + // Load everything when the user opens the home page, to avoid future loading times. React.useEffect( () => { @@ -290,45 +335,6 @@ export const HomePage = React.memo( forceUpdateEditor, })); - const { routeArguments, removeRouteArguments } = React.useContext( - RouterContext - ); - const { setInitialPackUserFriendlySlug } = React.useContext( - AssetStoreContext - ); - - // Open the store and a pack or game template if asked to do so. - React.useEffect( - () => { - if ( - routeArguments['initial-dialog'] === 'asset-store' || // Compatibility with old links - routeArguments['initial-dialog'] === 'store' // New way of opening the store - ) { - setActiveTab('shop'); - if (routeArguments['asset-pack']) { - setInitialPackUserFriendlySlug(routeArguments['asset-pack']); - } - if (routeArguments['game-template']) { - setInitialGameTemplateUserFriendlySlug( - routeArguments['game-template'] - ); - } - // Remove the arguments so that the asset store is not opened again. - removeRouteArguments([ - 'initial-dialog', - 'asset-pack', - 'game-template', - ]); - } - }, - [ - routeArguments, - removeRouteArguments, - setInitialPackUserFriendlySlug, - setInitialGameTemplateUserFriendlySlug, - ] - ); - // If the user logs out and is on the team view section, go back to the build section. React.useEffect( () => {