Skip to content

Commit

Permalink
Consolidate activePage?.path
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen committed Jul 9, 2020
1 parent 7f3579c commit f1b2f06
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/edit-site/src/components/page-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,25 @@ export default function PageSwitcher( {
].find( ( choice ) => choice.value === newPath );
onActivePageChange( { ...rest, path } );
};

const onPostSelect = ( post ) =>
onActivePageChange( {
type: 'post',
slug: post.slug,
path: getPathAndQueryString( post.url ),
context: { postType: post.type, postId: post.id },
} );

const activePath = activePage?.path;
return (
<DropdownMenu
icon={ null }
label={ __( 'Switch Page' ) }
toggleProps={ {
children:
[ ...pages, ...categories, ...posts ].find(
( choice ) => choice.value === activePage?.path
)?.label || activePage?.path,
( choice ) => choice.value === activePath
)?.label || activePath,
} }
menuProps={ { className: 'edit-site-page-switcher__menu' } }
>
Expand All @@ -121,21 +124,21 @@ export default function PageSwitcher( {
<MenuGroup label={ __( 'Pages' ) }>
<MenuItemsChoice
choices={ pages }
value={ activePage?.path }
value={ activePath }
onSelect={ onPageSelect }
/>
</MenuGroup>
<MenuGroup label={ __( 'Categories' ) }>
<MenuItemsChoice
choices={ categories }
value={ activePage?.path }
value={ activePath }
onSelect={ onPageSelect }
/>
</MenuGroup>
<MenuGroup label={ __( 'Posts' ) }>
<MenuItemsChoice
choices={ posts }
value={ activePage?.path }
value={ activePath }
onSelect={ onPageSelect }
/>
<LinkControl
Expand Down

0 comments on commit f1b2f06

Please sign in to comment.