Skip to content

Commit

Permalink
Make SiteHub available for Pages, Patterns, and Templates in mobile v…
Browse files Browse the repository at this point in the history
…iewports (#63118) (#63156)

* Create a SiteHubMobile only available for Pages, Patterns, and Templates

* Fix spacing issues

Co-authored-by: André <583546+oandregal@users.noreply.github.com>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
Co-authored-by: annezazu <annezazu@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
  • Loading branch information
9 people authored Jul 5, 2024
1 parent 8fb9836 commit 01a2581
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import ErrorBoundary from '../error-boundary';
import { store as editSiteStore } from '../../store';
import useInitEditedEntityFromURL from '../sync-state-with-url/use-init-edited-entity-from-url';
import SiteHub from '../site-hub';
import { default as SiteHub, SiteHubMobile } from '../site-hub';
import ResizableFrame from '../resizable-frame';
import useSyncCanvasModeWithURL from '../sync-state-with-url/use-sync-canvas-mode-with-url';
import { unlock } from '../../lock-unlock';
Expand Down Expand Up @@ -220,6 +220,16 @@ export default function Layout() {

{ isMobileViewport && areas.mobile && (
<div className="edit-site-layout__mobile">
{ canvasMode !== 'edit' && (
<SidebarContent routeKey={ routeKey }>
<SiteHubMobile
ref={ toggleRef }
isTransparent={
isResizableFrameOversized
}
/>
</SidebarContent>
) }
{ areas.mobile }
</div>
) }
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
85 changes: 84 additions & 1 deletion packages/edit-site/src/components/site-hub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ 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
*/
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 ) => {
Expand Down Expand Up @@ -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 (
<div className="edit-site-site-hub">
<HStack justify="flex-start" spacing="0">
<div
className={ clsx(
'edit-site-site-hub__view-mode-toggle-container',
{
'has-transparent-background': isTransparent,
}
) }
>
<Button
ref={ ref }
label={ __( 'Go to Site Editor' ) }
className="edit-site-layout__view-mode-toggle"
style={ {
transform: 'scale(0.5)',
borderRadius: 4,
} }
onClick={ () => {
history.push( {} );
navigate( 'back' );
} }
>
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" />
</Button>
</div>

<HStack>
<div className="edit-site-site-hub__title">
<Button
variant="link"
href={ homeUrl }
target="_blank"
label={ __( 'View site (opens in a new tab)' ) }
>
{ decodeEntities( siteTitle ) }
</Button>
</div>
<HStack
spacing={ 0 }
expanded={ false }
className="edit-site-site-hub__actions"
>
<Button
className="edit-site-site-hub_toggle-command-center"
icon={ search }
onClick={ () => openCommandCenter() }
label={ __( 'Open command palette' ) }
shortcut={ displayShortcut.primary( 'k' ) }
/>
</HStack>
</HStack>
</HStack>
</div>
);
} )
);

0 comments on commit 01a2581

Please sign in to comment.