Skip to content
Open
Show file tree
Hide file tree
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
34 changes: 34 additions & 0 deletions assets/js/review-post-notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* review-post-notes script.
*
* Auto-opens the Notes sidebar in the block editor when a post is opened
* via the "Review with Notes" task action, so the injected review notes
* are immediately visible.
*
* Dependencies: wp-data, wp-dom-ready, wp-editor
*/

wp.domReady( () => {
// The "All notes" sidebar registered by WordPress 6.9+.
const NOTES_SIDEBAR = 'edit-post/collab-history-sidebar';

const openNotesSidebar = () =>
wp.data
.dispatch( 'core/interface' )
.enableComplementaryArea( 'core', NOTES_SIDEBAR );

// Wait for the editor to finish initializing, otherwise the sidebar
// restored from user preferences would override ours.
if ( wp.data.select( 'core/editor' ).__unstableIsEditorReady() ) {
openNotesSidebar();
return;
}

const unsubscribe = wp.data.subscribe( () => {
if ( ! wp.data.select( 'core/editor' ).__unstableIsEditorReady() ) {
return;
}
unsubscribe();
openNotesSidebar();
} );
} );
Loading
Loading