Skip to content

Commit 4d8cf56

Browse files
authored
Do not change homepage tab at opening if an item from the asset store is requested (#5936)
1 parent 1a6e0ba commit 4d8cf56

File tree

1 file changed

+48
-42
lines changed
  • newIDE/app/src/MainFrame/EditorContainers/HomePage

1 file changed

+48
-42
lines changed

newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js

+48-42
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ import {
3535
sendUserSurveyHidden,
3636
sendUserSurveyStarted,
3737
} 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
3843

3944
const styles = {
4045
container: {
@@ -173,18 +178,49 @@ export const HomePage = React.memo<Props>(
173178

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

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.
176192
React.useEffect(
177193
() => {
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+
]);
180210
}
181211
},
182-
[initialTab]
212+
[
213+
routeArguments,
214+
removeRouteArguments,
215+
setInitialPackUserFriendlySlug,
216+
setInitialGameTemplateUserFriendlySlug,
217+
]
183218
);
184219

185220
// If the user is not authenticated, the GetStarted section is displayed.
186221
React.useEffect(
187222
() => {
223+
if (isShopRequestedAtOpening.current) return;
188224
if (shouldChangeTabAfterUserLoggedIn.current) {
189225
setActiveTab(authenticated ? initialTab : 'get-started');
190226
}
@@ -210,6 +246,15 @@ export const HomePage = React.memo<Props>(
210246
[loginState]
211247
);
212248

249+
React.useEffect(
250+
() => {
251+
if (initialTab === 'get-started') {
252+
incrementGetStartedSectionViewCount();
253+
}
254+
},
255+
[initialTab]
256+
);
257+
213258
// Load everything when the user opens the home page, to avoid future loading times.
214259
React.useEffect(
215260
() => {
@@ -290,45 +335,6 @@ export const HomePage = React.memo<Props>(
290335
forceUpdateEditor,
291336
}));
292337

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-
332338
// If the user logs out and is on the team view section, go back to the build section.
333339
React.useEffect(
334340
() => {

0 commit comments

Comments
 (0)