Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow opening any homepage tab from url #7007

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions newIDE/app/src/MainFrame/EditorContainers/HomePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -216,21 +231,11 @@ export const HomePage = React.memo<Props>(
const {
values: { showGetStartedSectionByDefault },
} = React.useContext(PreferencesContext);
const isShopRequestedAtOpening = React.useRef<boolean>(
isShopRequested(routeArguments)
);
const isGamesDashboardRequestedAtOpening = React.useRef<boolean>(
isGamesDashboardRequested(routeArguments)
);
const isBuildRequestedAtOpening = React.useRef<boolean>(
isBuildRequested(routeArguments)
const tabRequestedAtOpening = React.useRef<HomeTab | null>(
getRequestedTab(routeArguments)
);
const initialTab = isShopRequestedAtOpening.current
? 'shop'
: isGamesDashboardRequestedAtOpening.current
? 'manage'
: isBuildRequestedAtOpening.current
? 'build'
const initialTab = tabRequestedAtOpening.current
? tabRequestedAtOpening.current
: showGetStartedSectionByDefault
? 'get-started'
: 'build';
Expand Down Expand Up @@ -286,8 +291,11 @@ export const HomePage = React.memo<Props>(
// 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']);
}
Expand All @@ -297,18 +305,10 @@ export const HomePage = React.memo<Props>(
);
}
// 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,
Expand Down
6 changes: 5 additions & 1 deletion newIDE/app/src/MainFrame/RouterContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading