From f5e6e747e272b0e7545fe46894c92b60001155bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pasteau?= <4895034+ClementPasteau@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:00:43 +0200 Subject: [PATCH] Allow opening any homepage tab from url --- .../EditorContainers/HomePage/index.js | 68 +++++++++---------- newIDE/app/src/MainFrame/RouterContext.js | 6 +- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js b/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js index 437a7d7e1baf..1c3a4b7e39fb 100644 --- a/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js +++ b/newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js @@ -53,13 +53,28 @@ import { type NewProjectSetup } from '../../../ProjectCreation/NewProjectSetupDi import { type ObjectWithContext } from '../../../ObjectsList/EnumerateObjects'; const gamesDashboardWikiArticle = getHelpLink('/interface/games-dashboard/'); -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 isGamesDashboardRequested = (routeArguments: RouteArguments): boolean => - routeArguments['initial-dialog'] === 'games-dashboard'; -const isBuildRequested = (routeArguments: RouteArguments): boolean => - routeArguments['initial-dialog'] === 'build'; +const getRequestedTab = (routeArguments: RouteArguments): HomeTab | null => { + if ( + routeArguments['initial-dialog'] === 'asset-store' || // Compatibility with old links + routeArguments['initial-dialog'] === 'store' // New way of opening the store + ) { + return 'shop'; + } else if (routeArguments['initial-dialog'] === 'games-dashboard') { + return 'manage'; + } else if (routeArguments['initial-dialog'] === 'build') { + return 'build'; + } else if (routeArguments['initial-dialog'] === 'education') { + return 'team-view'; + } else if (routeArguments['initial-dialog'] === 'play') { + return 'play'; + } else if (routeArguments['initial-dialog'] === 'community') { + return 'community'; + } else if (routeArguments['initial-dialog'] === 'get-started') { + return 'get-started'; + } + + return null; +}; const styles = { container: { @@ -216,21 +231,11 @@ export const HomePage = React.memo( const { values: { showGetStartedSectionByDefault }, } = React.useContext(PreferencesContext); - const isShopRequestedAtOpening = React.useRef( - isShopRequested(routeArguments) - ); - const isGamesDashboardRequestedAtOpening = React.useRef( - isGamesDashboardRequested(routeArguments) - ); - const isBuildRequestedAtOpening = React.useRef( - isBuildRequested(routeArguments) + const tabRequestedAtOpening = React.useRef( + getRequestedTab(routeArguments) ); - const initialTab = isShopRequestedAtOpening.current - ? 'shop' - : isGamesDashboardRequestedAtOpening.current - ? 'manage' - : isBuildRequestedAtOpening.current - ? 'build' + const initialTab = tabRequestedAtOpening.current + ? tabRequestedAtOpening.current : showGetStartedSectionByDefault ? 'get-started' : 'build'; @@ -286,8 +291,11 @@ export const HomePage = React.memo( // that redirects to the asset store for instance). React.useEffect( () => { - if (isShopRequested(routeArguments)) { - setActiveTab('shop'); + const requestedTab = getRequestedTab(routeArguments); + if (!requestedTab) return; + + setActiveTab(requestedTab); + if (requestedTab === 'shop') { if (routeArguments['asset-pack']) { setInitialPackUserFriendlySlug(routeArguments['asset-pack']); } @@ -297,18 +305,10 @@ export const HomePage = React.memo( ); } // Remove the arguments so that the asset store is not opened again. - removeRouteArguments([ - 'initial-dialog', - 'asset-pack', - 'game-template', - ]); - } else if (isGamesDashboardRequested(routeArguments)) { - setActiveTab('manage'); - removeRouteArguments(['initial-dialog']); - } else if (isBuildRequested(routeArguments)) { - setActiveTab('build'); - removeRouteArguments(['initial-dialog']); + removeRouteArguments(['asset-pack', 'game-template']); } + + removeRouteArguments(['initial-dialog']); }, [ routeArguments, diff --git a/newIDE/app/src/MainFrame/RouterContext.js b/newIDE/app/src/MainFrame/RouterContext.js index 601dc64905ca..356d4f1de09c 100644 --- a/newIDE/app/src/MainFrame/RouterContext.js +++ b/newIDE/app/src/MainFrame/RouterContext.js @@ -9,7 +9,11 @@ export type Route = | 'games-dashboard' | 'asset-store' // For compatibility when there was only asset packs. | 'store' // New way of opening the store. - | 'build'; + | 'build' + | 'education' + | 'play' + | 'community' + | 'get-started'; type RouteKey = | 'initial-dialog' | 'game-id'