diff --git a/apps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js b/apps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js index 822d4c6777a7e..00afb81810c5f 100644 --- a/apps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js +++ b/apps/wpcom-block-editor/src/calypso/features/iframe-bridge-server.js @@ -1075,16 +1075,16 @@ function handleAppBannerShowing( calypsoPort ) { }; } -function handlePatterns( calypsoPort ) { - const selector = `[data-value="${ __( 'Patterns' ) }"]`; +function handleWpAdminRedirect( { calypsoPort, path, title } ) { + const selector = `[data-value="${ title }"]`; const callback = ( e ) => { e.preventDefault(); calypsoPort.postMessage( { - action: 'goToPatterns', + action: 'wpAdminRedirect', payload: { - destinationUrl: '/wp-admin/site-editor.php?postType=wp_block', + destinationUrl: `/wp-admin/${ path }`, unsavedChanges: select( 'core/editor' ).isEditedPostDirty(), }, } ); @@ -1094,6 +1094,26 @@ function handlePatterns( calypsoPort ) { addCommandsInputListener( selector, callback ); } +function handlePatterns( calypsoPort ) { + handleWpAdminRedirect( { + calypsoPort, + path: 'site-editor.php?postType=wp_block', + title: __( 'Patterns' ), + } ); +} + +function handleAddPage( calypsoPort ) { + handleWpAdminRedirect( { + calypsoPort, + path: 'post-new.php?post_type=page', + title: __( 'Add new page' ), + } ); +} + +function handleAddPost( calypsoPort ) { + handleWpAdminRedirect( { calypsoPort, path: 'post-new.php', title: __( 'Add new post' ) } ); +} + function initPort( message ) { if ( 'initPort' !== message.data.action ) { return; @@ -1196,6 +1216,10 @@ function initPort( message ) { handleAppBannerShowing( calypsoPort ); handlePatterns( calypsoPort ); + + handleAddPage( calypsoPort ); + + handleAddPost( calypsoPort ); } window.removeEventListener( 'message', initPort, false ); diff --git a/client/gutenberg/editor/calypsoify-iframe.tsx b/client/gutenberg/editor/calypsoify-iframe.tsx index d884a73439ed9..6ecdbfede05b9 100644 --- a/client/gutenberg/editor/calypsoify-iframe.tsx +++ b/client/gutenberg/editor/calypsoify-iframe.tsx @@ -95,7 +95,7 @@ enum WindowActions { enum EditorActions { GoToAllPosts = 'goToAllPosts', // Unused action in favor of CloseEditor. Maintained here to support cached scripts. - GoToPatterns = 'goToPatterns', + WpAdminRedirect = 'wpAdminRedirect', CloseEditor = 'closeEditor', OpenMediaModal = 'openMediaModal', OpenCheckoutModal = 'openCheckoutModal', @@ -383,7 +383,7 @@ class CalypsoifyIframe extends Component< ComponentProps, State > { this.navigate( destinationUrl, unsavedChanges ); } - if ( EditorActions.GoToPatterns === action ) { + if ( EditorActions.WpAdminRedirect === action ) { const { destinationUrl, unsavedChanges } = payload; this.navigate( `https://${ this.props.siteSlug }${ destinationUrl }`, unsavedChanges );