-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix Library routing on mobile #51558
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,19 +7,30 @@ import { | |
__experimentalHeading as Heading, | ||
__experimentalText as Text, | ||
__experimentalVStack as VStack, | ||
Flex, | ||
FlexBlock, | ||
} from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { symbol } from '@wordpress/icons'; | ||
import { __, isRTL } from '@wordpress/i18n'; | ||
import { symbol, chevronLeft, chevronRight } from '@wordpress/icons'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Grid from './grid'; | ||
import NoPatterns from './no-patterns'; | ||
import usePatterns from './use-patterns'; | ||
import SidebarButton from '../sidebar-button'; | ||
import useDebouncedInput from '../../utils/use-debounced-input'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useLocation, useHistory } = unlock( routerPrivateApis ); | ||
|
||
export default function PatternsList( { categoryId, label, type } ) { | ||
const location = useLocation(); | ||
const history = useHistory(); | ||
const isMobileViewport = useViewportMatch( 'medium', '<' ); | ||
const [ filterValue, setFilterValue, delayedFilterValue ] = | ||
useDebouncedInput( '' ); | ||
|
||
|
@@ -34,13 +45,32 @@ export default function PatternsList( { categoryId, label, type } ) { | |
|
||
return ( | ||
<VStack spacing={ 6 }> | ||
<SearchControl | ||
className="edit-site-library__search" | ||
onChange={ ( value ) => setFilterValue( value ) } | ||
placeholder={ __( 'Search patterns' ) } | ||
value={ filterValue } | ||
__nextHasNoMarginBottom | ||
/> | ||
<Flex> | ||
{ isMobileViewport && ( | ||
<SidebarButton | ||
icon={ isRTL() ? chevronRight : chevronLeft } | ||
label={ __( 'Back' ) } | ||
onClick={ () => { | ||
// Go back in history if we came from the library page. | ||
// Otherwise push a stack onto the history. | ||
if ( location.state?.backPath === '/library' ) { | ||
history.back(); | ||
} else { | ||
history.push( { path: '/library' } ); | ||
} | ||
Comment on lines
+54
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason we have to do this instead of leveraging I couldn't figure out a way to do this with the Navigator approach so I fallback to the regular browser's history approach. The way it works is that we can attach a |
||
} } | ||
/> | ||
) } | ||
<FlexBlock> | ||
<SearchControl | ||
className="edit-site-library__search" | ||
onChange={ ( value ) => setFilterValue( value ) } | ||
placeholder={ __( 'Search patterns' ) } | ||
value={ filterValue } | ||
__nextHasNoMarginBottom | ||
/> | ||
</FlexBlock> | ||
</Flex> | ||
{ isResolving && __( 'Loading' ) } | ||
{ ! isResolving && !! syncedPatterns.length && ( | ||
<> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
/** | ||
* Returns if the params match the list page route. | ||
* | ||
* @param {Object} params The url params. | ||
* @param {string} params.path The current path. | ||
* @param {Object} params The url params. | ||
* @param {string} params.path The current path. | ||
* @param {string} [params.categoryType] The current category type. | ||
* @param {string} [params.categoryId] The current category id. | ||
* @param {boolean} isMobileViewport Is mobile viewport. | ||
* | ||
* @return {boolean} Is list page or not. | ||
*/ | ||
export default function getIsListPage( { path } ) { | ||
return path === '/wp_template/all' || path === '/library'; | ||
export default function getIsListPage( | ||
{ path, categoryType, categoryId }, | ||
isMobileViewport | ||
) { | ||
return ( | ||
path === '/wp_template/all' || | ||
( path === '/library' && | ||
// Don't treat "/library" without categoryType and categoryId as a list page | ||
// in mobile because the sidebar covers the whole page. | ||
( ! isMobileViewport || ( !! categoryType && !! categoryId ) ) ) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of completely avoiding rendering the sidebar, we simply hide it here, so that some routing syncing logic in the sidebar can still apply in some senerios.