Skip to content

Commit

Permalink
Hide regular close button if nav sidebar is active
Browse files Browse the repository at this point in the history
  • Loading branch information
p-jackson committed Jul 2, 2020
1 parent 873e7cb commit ce71022
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { wordpress } from '@wordpress/icons';
import { Component, useEffect, useState } from 'react';
import tinymce from 'tinymce/tinymce';
import debugFactory from 'debug';
import { STORE_KEY as NAV_SIDEBAR_STORE_KEY } from '../../../../full-site-editing/full-site-editing-plugin/wpcom-block-editor-nav-sidebar/src/constants';

/**
* Internal dependencies
Expand Down Expand Up @@ -586,6 +587,10 @@ function handleCloseEditor( calypsoPort ) {
doAction( 'a8c.wpcom-block-editor.closeEditor' );
};

if ( isNavSidebarPresent() ) {
return;
}

registerPlugin( 'a8c-wpcom-block-editor-close-button-override', {
render: function CloseWpcomBlockEditor() {
const [ closeUrl, setCloseUrl ] = useState( calypsoifyGutenberg.closeUrl );
Expand Down Expand Up @@ -624,6 +629,16 @@ function handleCloseEditor( calypsoPort ) {
} );
}

/**
* Uses presence of data store to detect whether the nav sidebar has been loaded.
* Could run into timing issues, but the nav sidebar's data store is currently
* loaded early enough that this works for our needs.
*/
function isNavSidebarPresent() {
const selectors = select( NAV_SIDEBAR_STORE_KEY );
return !! selectors;
}

/**
* Modify links in order to open them in parent window and not in a child iframe.
*
Expand Down

0 comments on commit ce71022

Please sign in to comment.