Skip to content

Commit

Permalink
Do not change homepage tab at opening if an item from the asset store…
Browse files Browse the repository at this point in the history
… is requested (#5936)
  • Loading branch information
AlexandreSi authored Nov 22, 2023
1 parent 1a6e0ba commit 4d8cf56
Showing 1 changed file with 48 additions and 42 deletions.
90 changes: 48 additions & 42 deletions newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -173,18 +178,49 @@ export const HomePage = React.memo<Props>(

const [activeTab, setActiveTab] = React.useState<HomeTab>(initialTab);

const { routeArguments, removeRouteArguments } = React.useContext(
RouterContext
);
const { setInitialPackUserFriendlySlug } = React.useContext(
AssetStoreContext
);
const isShopRequestedAtOpening = React.useRef<boolean>(
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');
}
Expand All @@ -210,6 +246,15 @@ export const HomePage = React.memo<Props>(
[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(
() => {
Expand Down Expand Up @@ -290,45 +335,6 @@ export const HomePage = React.memo<Props>(
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(
() => {
Expand Down

0 comments on commit 4d8cf56

Please sign in to comment.