Skip to content

Commit

Permalink
Update controllers to allow "all sites" on /themes and /theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons committed Feb 5, 2024
1 parent e3b15ce commit 95af80d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions client/my-sites/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,36 @@ export function selectSiteIfLoggedInWithSites( context, next ) {
siteSelection( context, next );
}

/**
* If the section has an "all sites" view to delay the site selection,
* only handle the site selection with 0 or 1 sites.
*/
export function selectSiteIfLoggedInWithOneSite( context, next ) {
const state = context.store.getState();
const isLoggedIn = isUserLoggedIn( state );
const siteCount = getCurrentUserSiteCount( state );
const siteFragment =
context.params.site || context.params.site_id || getSiteFragment( context.path );

// If the user is logged out, has 0 sites, or the path contains a site fragment,
// proceed with the regular site selection.
if ( ! isLoggedIn || ! siteCount || !! siteFragment ) {
siteSelection( context, next );
return;
}

// If the user only has 1 site and the path doesn't contain a site fragment,
// select the site automatically and move on.
if ( siteCount === 1 ) {
selectSite( context );
return;
}

// If the user has multiple sites and the path doesn't contain a site fragment,
// proceed with rendering the page, delaying the site selection.
next();
}

export function hideNavigationIfLoggedInWithNoSites( context, next ) {
const state = context.store.getState();
if ( isUserLoggedIn( state ) && getCurrentUserSiteCount( state ) === 0 ) {
Expand Down
4 changes: 2 additions & 2 deletions client/my-sites/theme/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getLanguageRouteParam } from '@automattic/i18n-utils';
import { translate } from 'i18n-calypso';
import { makeLayout, redirectWithoutLocaleParamIfLoggedIn } from 'calypso/controller';
import {
selectSiteIfLoggedInWithSites,
selectSiteIfLoggedInWithOneSite,
redirectToLoginIfSiteRequested,
} from 'calypso/my-sites/controller';
import { getTheme } from 'calypso/state/themes/selectors';
Expand Down Expand Up @@ -31,7 +31,7 @@ export default function ( router ) {
redirectWithoutLocaleParamIfLoggedIn,
redirectToLoginIfSiteRequested,
setTitleIfThemeExisted,
selectSiteIfLoggedInWithSites,
selectSiteIfLoggedInWithOneSite,
fetchThemeDetailsData,
details,
makeLayout
Expand Down
4 changes: 2 additions & 2 deletions client/my-sites/themes/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'calypso/controller';
import {
navigation,
selectSiteIfLoggedInWithSites,
selectSiteIfLoggedInWithOneSite,
siteSelection,
sites,
hideNavigationIfLoggedInWithNoSites,
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function ( router ) {
routesWithoutSites,
redirectWithoutLocaleParamIfLoggedIn,
fetchAndValidateVerticalsAndFilters,
selectSiteIfLoggedInWithSites,
selectSiteIfLoggedInWithOneSite,
renderThemes,
hideNavigationIfLoggedInWithNoSites,
addNavigationIfLoggedIn,
Expand Down

0 comments on commit 95af80d

Please sign in to comment.