Skip to content

Commit

Permalink
Add all posts
Browse files Browse the repository at this point in the history
  • Loading branch information
david-szabo97 committed Oct 12, 2020
1 parent 1b26955 commit eafc013
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { __experimentalNavigationMenu as NavigationMenu } from '@wordpress/components';
import {
__experimentalNavigationMenu as NavigationMenu,
__experimentalNavigationItem as NavigationItem,
} from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

/**
Expand All @@ -10,12 +14,39 @@ import { __ } from '@wordpress/i18n';
import NavigationEntityItems from '../navigation-entity-items';

export default function ContentPostsMenu() {
const showOnFront = useSelect(
( select ) =>
select( 'core' ).getEditedEntityRecord( 'root', 'site' )
.show_on_front,
[]
);

const { setPage } = useDispatch( 'core/edit-site' );

const onActivateFrontItem = () => {
setPage( {
type: 'page',
path: '/',
context: {
query: { categoryIds: [] },
queryContext: { page: 1 },
},
} );
};

return (
<NavigationMenu
menu="content-posts"
title={ __( 'Posts' ) }
parentMenu="root"
>
{ showOnFront === 'posts' && (
<NavigationItem
item={ 'content-/' }
title={ __( 'All Posts' ) }
onClick={ onActivateFrontItem }
/>
) }
<NavigationEntityItems kind="postType" name="post" />
</NavigationMenu>
);
Expand Down

0 comments on commit eafc013

Please sign in to comment.