-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reader: Update action button link of an empty list of a user profile (#…
…98706) The issue was that on an empty list page, the "Back to Following" button with link `/read` was being displayed even when navigating from a user profile. This PR fixes this by updating the implementation to display a "Back to User Profile" button with link `/read/users/:id/lists` instead, allowing users to easily navigate back to the user profile.
- Loading branch information
Showing
5 changed files
with
47 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useSelector } from 'react-redux'; | ||
import EmptyContent from 'calypso/components/empty-content'; | ||
import getPreviousRoute from 'calypso/state/selectors/get-previous-route'; | ||
|
||
export default function ListEmptyContent(): JSX.Element { | ||
const translate = useTranslate(); | ||
const previousRoute: string = useSelector( getPreviousRoute ); | ||
|
||
function previousRouteIsUserProfileLists(): boolean { | ||
return /^\/read\/users\/[a-z0-9]+\/lists\??$/.test( previousRoute ); | ||
} | ||
|
||
function getActionBtnLink(): string { | ||
return previousRouteIsUserProfileLists() ? previousRoute : '/read'; | ||
} | ||
|
||
function getActionBtnText(): string { | ||
return previousRouteIsUserProfileLists() | ||
? translate( 'Back to User Profile' ) | ||
: translate( 'Back to Following' ); | ||
} | ||
|
||
const action = ( | ||
<a className="empty-content__action button is-primary" href={ getActionBtnLink() }> | ||
{ getActionBtnText() } | ||
</a> | ||
); | ||
|
||
return ( | ||
<EmptyContent | ||
title={ translate( 'No recent posts' ) } | ||
line={ translate( 'The sites in this list have not posted anything recently.' ) } | ||
action={ action } | ||
illustration="/calypso/images/illustrations/illustration-empty-results.svg" | ||
illustrationWidth={ 400 } | ||
/> | ||
); | ||
} |
13 changes: 7 additions & 6 deletions
13
client/state/selectors/get-previous-route.js → client/state/selectors/get-previous-route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import { stringify } from 'qs'; | ||
import getPreviousPath from 'calypso/state/selectors/get-previous-path'; | ||
import getPreviousQuery from 'calypso/state/selectors/get-previous-query'; | ||
import { AppState } from 'calypso/types'; | ||
|
||
/** | ||
* Gets the previous route set by a ROUTE_SET action | ||
* @param {Object} state - global redux state | ||
* @param {AppState} state - global redux state | ||
* @returns {string} previous route value | ||
*/ | ||
|
||
export const getPreviousRoute = ( state ) => { | ||
export default function getPreviousRoute( state: AppState ): string { | ||
const previousPath = getPreviousPath( state ); | ||
const previousQuery = getPreviousQuery( state ); | ||
let query = ''; | ||
|
||
if ( previousQuery ) { | ||
query = '?' + stringify( previousQuery ); | ||
} | ||
return previousPath + query; | ||
}; | ||
|
||
export default getPreviousRoute; | ||
return previousPath + query; | ||
} |
File renamed without changes.