Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/editor/src/components/collab-sidebar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { store as interfaceStore } from '@wordpress/interface';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { sidebars as DEFAULT_SIDEBARS } from '../sidebar/constants';
import { FLOATING_NOTES_SIDEBAR } from './constants';
import { unlock } from '../../lock-unlock';
import { noop } from './utils';
Expand Down Expand Up @@ -348,19 +349,28 @@ export function useEnableFloatingSidebar( enabled = false ) {
const { disableComplementaryArea, enableComplementaryArea } =
registry.dispatch( interfaceStore );

let wasHiddenByUser = false;
const unsubscribe = registry.subscribe( () => {
// Return `null` to indicate the user hid the complementary area.
if ( getActiveComplementaryArea( 'core' ) === null ) {
wasHiddenByUser = true;
enableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );
}
} );

return () => {
unsubscribe();
if (
getActiveComplementaryArea( 'core' ) === FLOATING_NOTES_SIDEBAR
) {
disableComplementaryArea( 'core', FLOATING_NOTES_SIDEBAR );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disableComplementaryArea only accepts one argument, which I forgot. Should be fixed now.

const activeArea = getActiveComplementaryArea( 'core' );
if ( activeArea === FLOATING_NOTES_SIDEBAR ) {
if ( wasHiddenByUser ) {
disableComplementaryArea( 'core' );
} else {
// Restore the default sidebar if user didn't explicitly hide it.
enableComplementaryArea(
'core',
DEFAULT_SIDEBARS.document
);
}
}
};
}, [ enabled, registry ] );
Expand Down
Loading