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

Me: Make the back button point to the previous page #89075

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions client/layout/global-sidebar/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { GlobalSidebarHeader } from 'calypso/layout/global-sidebar/header';
import useSiteMenuItems from 'calypso/my-sites/sidebar/use-site-menu-items';
import { getIsRequestingAdminMenu } from 'calypso/state/admin-menu/selectors';
import { getCurrentUser } from 'calypso/state/current-user/selectors';
import getPreviousRoute from 'calypso/state/selectors/get-previous-route';
import { getSection } from 'calypso/state/ui/selectors';
import Sidebar from '../sidebar';
import { GLOBAL_SIDEBAR_EVENTS } from './events';
import { GlobalSidebarFooter } from './footer';
Expand All @@ -27,6 +29,9 @@ const GlobalSidebar = ( {
const translate = useTranslate();
const currentUser = useSelector( getCurrentUser );
const isDesktop = useBreakpoint( '>=782px' );
const previousRoute = useSelector( getPreviousRoute );
const section = useSelector( getSection );
const previousLink = useRef( previousRoute );

const handleWheel = useCallback( ( event ) => {
const bodyEl = bodyRef.current;
Expand All @@ -47,6 +52,13 @@ const GlobalSidebar = ( {
};
}, [ handleWheel ] );

useEffect( () => {
// Update the previous link only when the group is changed.
if ( previousRoute && ! previousRoute.startsWith( `/${ section.group }` ) ) {
previousLink.current = previousRoute;
}
}, [ previousRoute, section.group ] );

/**
* If there are no menu items and we are currently requesting some,
* then show a spinner. The check for menuItems is necessary because
Expand All @@ -57,8 +69,9 @@ const GlobalSidebar = ( {
return <Spinner className="sidebar__menu-loading" />;
}

const { requireBackLink, backLinkText, ...sidebarProps } = props;
const { requireBackLink, backLinkText, backLinkHref, ...sidebarProps } = props;
const sidebarBackLinkText = backLinkText ?? translate( 'Back' );
const sidebarBackLinkHref = backLinkHref || previousLink.current || '/sites';

return (
<div className="global-sidebar" ref={ wrapperRef }>
Expand All @@ -67,7 +80,7 @@ const GlobalSidebar = ( {
<Sidebar className={ className } { ...sidebarProps } onClick={ onClick }>
{ requireBackLink && (
<div className="sidebar__back-link">
<a href="/sites" onClick={ handleBackLinkClick }>
<a href={ sidebarBackLinkHref } onClick={ handleBackLinkClick }>
DustyReagan marked this conversation as resolved.
Show resolved Hide resolved
<Gridicon icon="chevron-left" size={ 24 } />
<span className="sidebar__back-link-text">{ sidebarBackLinkText }</span>
</a>
Expand Down
1 change: 1 addition & 0 deletions client/reader/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class ReaderSidebar extends Component {
onClick: this.handleClick,
requireBackLink: true,
backLinkText: i18n.translate( 'All sites' ),
backLinkHref: '/sites',
};
return (
<GlobalSidebar { ...props }>
Expand Down
Loading