Skip to content

Commit

Permalink
handle back functionality better
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison-Stavlo committed Jun 20, 2024
1 parent a4361b9 commit 95c269f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
7 changes: 6 additions & 1 deletion client/layout/global-sidebar/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ const GlobalSidebar = ( {
}
}, [] );

const handleBackLinkClick = () => {
const handleBackLinkClick = ( ev ) => {
recordTracksEvent( GLOBAL_SIDEBAR_EVENTS.MENU_BACK_CLICK, { path } );
if ( props.onClose ) {
ev.preventDefault();
ev.stopPropagation();
props.onClose();
}
};

const getBackLinkFromURL = () => {
Expand Down
40 changes: 36 additions & 4 deletions client/reader/full-post/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import page from '@automattic/calypso-router';
import { defer } from 'lodash';
import AsyncLoad from 'calypso/components/async-load';
import { trackPageLoad } from 'calypso/reader/controller-helper';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';

const analyticsPageTitle = 'Reader';

Expand All @@ -13,6 +14,7 @@ const scrollTopIfNoHash = () =>
} );

export function blogPost( context, next ) {
const state = context.store.getState();
const blogId = context.params.blog;
const postId = context.params.post;
const basePath = '/read/blogs/:blog_id/posts/:post_id';
Expand All @@ -24,32 +26,49 @@ export function blogPost( context, next ) {
}
trackPageLoad( basePath, fullPageTitle, 'full_post' );

const lastRoute = context.lastRoute || '/';
function closer() {
page.back( lastRoute );
}

context.primary = (
<AsyncLoad
require="calypso/blocks/reader-full-post"
blogId={ blogId }
postId={ postId }
referral={ referral }
referralStream={ context.lastRoute }
onClose={ function () {
page.back( context.lastRoute || '/' );
} }
onClose={ closer }
/>
);

if ( isUserLoggedIn( state ) ) {
context.secondary = (
<AsyncLoad
require="calypso/reader/sidebar"
path={ context.path }
placeholder={ null }
returnPath={ lastRoute }
onClose={ closer }
/>
);
}
scrollTopIfNoHash();
next();
}

export function feedPost( context, next ) {
const state = context.store.getState();
const feedId = context.params.feed;
const postId = context.params.post;
const basePath = '/read/feeds/:feed_id/posts/:feed_item_id';
const fullPageTitle = analyticsPageTitle + ' > Feed Post > ' + feedId + ' > ' + postId;

trackPageLoad( basePath, fullPageTitle, 'full_post' );

const lastRoute = context.lastRoute || '/';
function closer() {
page.back( context.lastRoute || '/' );
page.back( lastRoute );
}

context.primary = (
Expand All @@ -61,6 +80,19 @@ export function feedPost( context, next ) {
referralStream={ context.lastRoute }
/>
);

if ( isUserLoggedIn( state ) ) {
context.secondary = (
<AsyncLoad
require="calypso/reader/sidebar"
path={ context.path }
placeholder={ null }
returnPath={ lastRoute }
onClose={ closer }
/>
);
}

scrollTopIfNoHash();
next();
}
4 changes: 1 addition & 3 deletions client/reader/full-post/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import page from '@automattic/calypso-router';
import { makeLayout, redirectLoggedOutToSignup, render as clientRender } from 'calypso/controller';
import { updateLastRoute, blogDiscoveryByFeedId, sidebar } from 'calypso/reader/controller';
import { updateLastRoute, blogDiscoveryByFeedId } from 'calypso/reader/controller';
import { blogPost, feedPost } from './controller';

export default function () {
Expand All @@ -10,7 +10,6 @@ export default function () {
blogDiscoveryByFeedId,
redirectLoggedOutToSignup,
updateLastRoute,
sidebar,
feedPost,
makeLayout,
clientRender
Expand All @@ -21,7 +20,6 @@ export default function () {
'/read/blogs/:blog/posts/:post',
redirectLoggedOutToSignup,
updateLastRoute,
sidebar,
blogPost,
makeLayout,
clientRender
Expand Down
3 changes: 2 additions & 1 deletion client/reader/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ export class ReaderSidebar extends Component {
onClick: this.handleClick,
requireBackLink: true,
siteTitle: i18n.translate( 'Reader' ),
backLinkHref: '/sites',
backLinkHref: this.props.returnPath || '/sites',
onClose: this.props.onClose,
};
return (
<GlobalSidebar { ...props }>
Expand Down

0 comments on commit 95c269f

Please sign in to comment.