Skip to content

Commit

Permalink
Theme Showcase: Update Controllers for an "All Sites" View (#87000)
Browse files Browse the repository at this point in the history
  • Loading branch information
Copons authored and TimBroddin committed Feb 20, 2024
1 parent 30e04bd commit b2e30ba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
26 changes: 23 additions & 3 deletions client/my-sites/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,14 +879,34 @@ export function selectSiteIfLoggedIn( context, next ) {
selectSite( context );
}

export function selectSiteIfLoggedInWithSites( 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 selectSiteOrSkipIfLoggedInWithMultipleSites( context, next ) {
const state = context.store.getState();
if ( isUserLoggedIn( state ) && getCurrentUserSiteCount( state ) && ! context.params.site_id ) {
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;
}

siteSelection( context, next );
// 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 ) {
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,
selectSiteOrSkipIfLoggedInWithMultipleSites,
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,
selectSiteOrSkipIfLoggedInWithMultipleSites,
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,
selectSiteOrSkipIfLoggedInWithMultipleSites,
siteSelection,
sites,
hideNavigationIfLoggedInWithNoSites,
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function ( router ) {
routesWithoutSites,
redirectWithoutLocaleParamIfLoggedIn,
fetchAndValidateVerticalsAndFilters,
selectSiteIfLoggedInWithSites,
selectSiteOrSkipIfLoggedInWithMultipleSites,
renderThemes,
hideNavigationIfLoggedInWithNoSites,
addNavigationIfLoggedIn,
Expand Down

0 comments on commit b2e30ba

Please sign in to comment.