Skip to content

Commit

Permalink
Extract method to goto overlay template part
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Nov 27, 2023
1 parent 92c0079 commit 918487f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions packages/block-library/src/navigation/edit/edit-overlay-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function EditOverlayButton( { navRef } ) {
const { baseOverlay, customOverlay } = useSelect(
( select ) => {
const themeSlug = select( coreStore ).getCurrentTheme()?.stylesheet;
console.log( 'themeSlug', themeSlug );

const _baseOverlay = themeSlug
? select( coreStore ).getEntityRecord(
'postType',
Expand Down Expand Up @@ -66,6 +66,14 @@ export default function EditOverlayButton( { navRef } ) {
return null;
}

function goToEditOverlay( overlayId ) {
history.push( {
postId: overlayId,
postType: 'wp_template_part',
canvas: 'edit',
} );
}

if ( ! history && ! baseOverlay && ! customOverlay ) {
return null;
}
Expand All @@ -79,11 +87,7 @@ export default function EditOverlayButton( { navRef } ) {
// If there is an overlay already
// then just show it.
if ( customOverlay ) {
history.push( {
postId: customOverlay.id,
postType: 'wp_template_part',
canvas: 'edit',
} );
goToEditOverlay( customOverlay.id );
return;
}

Expand All @@ -110,12 +114,7 @@ export default function EditOverlayButton( { navRef } ) {
{ throwOnError: true }
);

// 2. Redirect to template editor
history.push( {
postId: newOverlay.id,
postType: 'wp_template_part',
canvas: 'edit',
} );
goToEditOverlay( newOverlay );
} }
>
{ __( 'Edit Overlay' ) }
Expand Down

0 comments on commit 918487f

Please sign in to comment.