Skip to content

Commit

Permalink
Site Editor Pages: load the appropriate template if posts page set (#…
Browse files Browse the repository at this point in the history
…52266)

* This commit:
- links the posts page to the homepage template when a post page is set
- abstracts logic to get page item props

* The Posts Page resolves to display the Home or Index template only. Adding a check to skip the Front Page

* Showing homepage settings for posts pages that are set as the post page in reading settings

* Post pages that have been set to display posts will redirect to first the home template, then the index template. The fallback is the post id of the page.

* Reverted refactor of packages/edit-site/src/components/sidebar-navigation-screen-page/index.js
Will do it in a follow up
  • Loading branch information
ramonjd authored Jul 10, 2023
1 parent ac57a48 commit 38fca8a
Showing 1 changed file with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export default function SidebarNavigationScreenPages() {
templates?.find( ( template ) => template.slug === 'home' ) ||
templates?.find( ( template ) => template.slug === 'index' );

const getPostsPageTemplate = () =>
templates?.find( ( template ) => template.slug === 'home' ) ||
templates?.find( ( template ) => template.slug === 'index' );

const pagesAndTemplates = pages?.concat( dynamicPageTemplates, [
homeTemplate,
] );

const { frontPage, postsPage } = useSelect( ( select ) => {
const { getEntityRecord } = select( coreStore );

const siteSettings = getEntityRecord( 'root', 'site' );
return {
frontPage: siteSettings?.page_on_front,
Expand Down Expand Up @@ -106,6 +109,27 @@ export default function SidebarNavigationScreenPages() {
setShowAddPage( false );
};

const getPageProps = ( id ) => {
let itemIcon = page;
const postsPageTemplateId =
postsPage && postsPage === id ? getPostsPageTemplate()?.id : null;

switch ( id ) {
case frontPage:
itemIcon = home;
break;
case postsPage:
itemIcon = verse;
break;
}

return {
icon: itemIcon,
postType: postsPageTemplateId ? 'wp_template' : 'page',
postId: postsPageTemplateId || id,
};
};

return (
<>
{ showAddPage && (
Expand Down Expand Up @@ -152,34 +176,20 @@ export default function SidebarNavigationScreenPages() {
</Truncate>
</PageItem>
) }
{ reorderedPages?.map( ( item ) => {
let itemIcon;
switch ( item.id ) {
case frontPage:
itemIcon = home;
break;
case postsPage:
itemIcon = verse;
break;
default:
itemIcon = page;
}
return (
<PageItem
postId={ item.id }
key={ item.id }
icon={ itemIcon }
withChevron
>
<Truncate numberOfLines={ 1 }>
{ decodeEntities(
item?.title?.rendered ||
__( '(no title)' )
) }
</Truncate>
</PageItem>
);
} ) }
{ reorderedPages?.map( ( { id, title } ) => (
<PageItem
{ ...getPageProps( id ) }
key={ id }
withChevron
>
<Truncate numberOfLines={ 1 }>
{ decodeEntities(
title?.rendered ||
__( '(no title)' )
) }
</Truncate>
</PageItem>
) ) }
</ItemGroup>
) }
</>
Expand Down

0 comments on commit 38fca8a

Please sign in to comment.