From 76d2ea5f84ea47a4dd43883c2d1c13aca75355ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com> Date: Fri, 5 Jul 2024 01:48:47 +0200 Subject: [PATCH] Make SiteHub available for Pages, Patterns, and Templates in mobile viewports (#63118) * Create a SiteHubMobile only available for Pages, Patterns, and Templates * Fix spacing issues Co-authored-by: oandregal Co-authored-by: MaggieCabrera Co-authored-by: andrewserong Co-authored-by: jameskoster Co-authored-by: ramonjd Co-authored-by: aaronrobertshaw Co-authored-by: annezazu Co-authored-by: youknowriad --- .../edit-site/src/components/layout/index.js | 12 ++- .../src/components/layout/style.scss | 12 +++ .../src/components/site-hub/index.js | 85 ++++++++++++++++++- 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/packages/edit-site/src/components/layout/index.js b/packages/edit-site/src/components/layout/index.js index 443ca04ebd03ea..a609f616471dbb 100644 --- a/packages/edit-site/src/components/layout/index.js +++ b/packages/edit-site/src/components/layout/index.js @@ -34,7 +34,7 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands */ import ErrorBoundary from '../error-boundary'; import { store as editSiteStore } from '../../store'; -import SiteHub from '../site-hub'; +import { default as SiteHub, SiteHubMobile } from '../site-hub'; import ResizableFrame from '../resizable-frame'; import { unlock } from '../../lock-unlock'; import KeyboardShortcutsRegister from '../keyboard-shortcuts/register'; @@ -174,6 +174,16 @@ export default function Layout( { route } ) { { isMobileViewport && areas.mobile && (
+ { canvasMode !== 'edit' && ( + + + + ) } { areas.mobile }
) } diff --git a/packages/edit-site/src/components/layout/style.scss b/packages/edit-site/src/components/layout/style.scss index 01c31de0d65d6c..a7539ccdca79b2 100644 --- a/packages/edit-site/src/components/layout/style.scss +++ b/packages/edit-site/src/components/layout/style.scss @@ -56,6 +56,18 @@ position: relative; width: 100%; z-index: z-index(".edit-site-layout__canvas-container"); + + /* + * The SiteHubMobile component is displayed + * for pages that do not have a sidebar, + * yet it needs the Sidebar component for the React context. + * + * This removes the padding in this scenario. + * See https://github.com/WordPress/gutenberg/pull/63118 + */ + .edit-site-sidebar__screen-wrapper { + padding: 0; + } } .edit-site-layout__canvas-container { diff --git a/packages/edit-site/src/components/site-hub/index.js b/packages/edit-site/src/components/site-hub/index.js index b53fed2d7a94f4..301f7165d59354 100644 --- a/packages/edit-site/src/components/site-hub/index.js +++ b/packages/edit-site/src/components/site-hub/index.js @@ -11,11 +11,12 @@ import { Button, __experimentalHStack as HStack } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { store as coreStore } from '@wordpress/core-data'; import { decodeEntities } from '@wordpress/html-entities'; -import { memo, forwardRef } from '@wordpress/element'; +import { memo, forwardRef, useContext } from '@wordpress/element'; import { search } from '@wordpress/icons'; import { store as commandsStore } from '@wordpress/commands'; import { displayShortcut } from '@wordpress/keycodes'; import { filterURLForDisplay } from '@wordpress/url'; +import { privateApis as routerPrivateApis } from '@wordpress/router'; /** * Internal dependencies @@ -23,6 +24,8 @@ import { filterURLForDisplay } from '@wordpress/url'; import { store as editSiteStore } from '../../store'; import SiteIcon from '../site-icon'; import { unlock } from '../../lock-unlock'; +const { useHistory } = unlock( routerPrivateApis ); +import { SidebarNavigationContext } from '../sidebar'; const SiteHub = memo( forwardRef( ( { isTransparent }, ref ) => { @@ -103,3 +106,83 @@ const SiteHub = memo( ); export default SiteHub; + +export const SiteHubMobile = memo( + forwardRef( ( { isTransparent }, ref ) => { + const history = useHistory(); + const { navigate } = useContext( SidebarNavigationContext ); + + const { homeUrl, siteTitle } = useSelect( ( select ) => { + const { + getSite, + getUnstableBase, // Site index. + } = select( coreStore ); + const _site = getSite(); + return { + homeUrl: getUnstableBase()?.home, + siteTitle: + ! _site?.title && !! _site?.url + ? filterURLForDisplay( _site?.url ) + : _site?.title, + }; + }, [] ); + const { open: openCommandCenter } = useDispatch( commandsStore ); + + return ( +
+ +
+ +
+ + +
+ +
+ +
+ ); + } ) +);