Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Keep collab sidebar open when comments are available
  • Loading branch information
akasunil committed Nov 29, 2024
commit c60972c05820b8cca22a2dd919bb39827b1e5f4c
27 changes: 25 additions & 2 deletions packages/editor/src/components/collab-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch, resolveSelect } from '@wordpress/data';
import {
useSelect,
useDispatch,
resolveSelect,
subscribe,
} from '@wordpress/data';
import { useState, useMemo } from '@wordpress/element';
import { comment as commentIcon } from '@wordpress/icons';
import { addFilter } from '@wordpress/hooks';
Expand All @@ -22,6 +27,7 @@ import { store as editorStore } from '../../store';
import AddCommentButton from './comment-button';
import AddCommentToolbarButton from './comment-button-toolbar';
import { getEditorCanvasBackgroundColor } from './utils';
import { useGlobalStylesContext } from '../global-styles-provider';

const isBlockCommentExperimentEnabled =
window?.__experimentalEnableBlockComment;
Expand Down Expand Up @@ -213,6 +219,7 @@ function CollabSidebarContent( {
export default function CollabSidebar() {
const [ showCommentBoard, setShowCommentBoard ] = useState( false );
const { enableComplementaryArea } = useDispatch( interfaceStore );
const { getActiveComplementaryArea } = useSelect( interfaceStore );

const { postStatus } = useSelect( ( select ) => {
return {
Expand Down Expand Up @@ -285,6 +292,21 @@ export default function CollabSidebar() {
return result;
}, [ threads ] );

// Get the global styles to set the background color of the sidebar.
const { merged: GlobalStyles } = useGlobalStylesContext();
const backgroundColor = GlobalStyles?.styles?.color?.background;

if ( 0 < resultComments.length ) {
const unsubscribe = subscribe( () => {
Copy link
Member

Choose a reason for hiding this comment

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

Can you change this to an effect? We shouldn't subscribe on render.

Copy link
Member Author

Choose a reason for hiding this comment

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

useEffect won't work in this case, as the component doesn't re-render when another sidebar is toggled from outside the editor.

const activeSidebar = getActiveComplementaryArea( 'core' );

if ( ! activeSidebar ) {
enableComplementaryArea( 'core', 'edit-post/collab-sidebar' );
unsubscribe();
}
} );
Copy link
Member

Choose a reason for hiding this comment

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

We could probably create an option for PluginSidebar to use the sidebar as a fallback sidebar that is always open instead of this, but it's fine as a temporary solution.

}

// Check if the experimental flag is enabled.
if ( ! isBlockCommentExperimentEnabled || postStatus === 'publish' ) {
return null; // or maybe return some message indicating no threads are available.
Expand Down Expand Up @@ -321,7 +343,8 @@ export default function CollabSidebar() {
showCommentBoard={ showCommentBoard }
setShowCommentBoard={ setShowCommentBoard }
styles={ {
backgroundColor: getEditorCanvasBackgroundColor(),
backgroundColor:
backgroundColor ?? getEditorCanvasBackgroundColor(),
} }
/>
</PluginSidebar>
Expand Down
Loading