Skip to content

Commit 35c2063

Browse files
Mamadukajasmussent-hamanoadamsilverstein
authored andcommitted
Notes: Fix block toolbar indicator logic (#72736)
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
1 parent 8e47792 commit 35c2063

File tree

4 files changed

+7
-49
lines changed

4 files changed

+7
-49
lines changed

packages/editor/src/components/collab-sidebar/comment-indicator-toolbar.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import { __, _n, sprintf } from '@wordpress/i18n';
66
import { useMemo } from '@wordpress/element';
77
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
88

9-
/**
10-
* External dependencies
11-
*/
12-
import clsx from 'clsx';
13-
149
/**
1510
* Internal dependencies
1611
*/
@@ -19,7 +14,7 @@ import { getAvatarBorderColor } from './utils';
1914

2015
const { CommentIconToolbarSlotFill } = unlock( blockEditorPrivateApis );
2116

22-
const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
17+
const CommentAvatarIndicator = ( { onClick, thread } ) => {
2318
const threadParticipants = useMemo( () => {
2419
if ( ! thread ) {
2520
return [];
@@ -34,15 +29,13 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
3429
allComments.forEach( ( comment ) => {
3530
// Track thread participants (original commenter + repliers).
3631
if ( comment.author_name && comment.author_avatar_urls ) {
37-
const authorKey = `${ comment.author }-${ comment.author_name }`;
38-
if ( ! participantsMap.has( authorKey ) ) {
39-
participantsMap.set( authorKey, {
32+
if ( ! participantsMap.has( comment.author ) ) {
33+
participantsMap.set( comment.author, {
4034
name: comment.author_name,
4135
avatar:
4236
comment.author_avatar_urls?.[ '48' ] ||
4337
comment.author_avatar_urls?.[ '96' ],
4438
id: comment.author,
45-
isOriginalCommenter: comment.id === thread.id,
4639
date: comment.date,
4740
} );
4841
}
@@ -52,14 +45,6 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
5245
return Array.from( participantsMap.values() );
5346
}, [ thread ] );
5447

55-
const hasUnresolved = thread?.status !== 'approved';
56-
57-
// Check if this specific thread has more participants due to pagination.
58-
// If we have pagination AND this thread + its replies equals or exceeds the API limit,
59-
// then this thread likely has more participants that weren't loaded.
60-
const threadHasMoreParticipants =
61-
hasMoreComments && thread?.reply && 1 + thread.reply.length >= 100;
62-
6348
if ( ! threadParticipants.length ) {
6449
return null;
6550
}
@@ -68,6 +53,7 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
6853
const maxAvatars = 3;
6954
const visibleParticipants = threadParticipants.slice( 0, maxAvatars );
7055
const overflowCount = Math.max( 0, threadParticipants.length - maxAvatars );
56+
const threadHasMoreParticipants = threadParticipants.length > 100;
7157

7258
// If we hit the comment limit, show "100+" instead of exact overflow count.
7359
const overflowText =
@@ -95,17 +81,15 @@ const CommentAvatarIndicator = ( { onClick, thread, hasMoreComments } ) => {
9581
return (
9682
<CommentIconToolbarSlotFill.Fill>
9783
<ToolbarButton
98-
className={ clsx( 'comment-avatar-indicator', {
99-
'has-unresolved': hasUnresolved,
100-
} ) }
84+
className="comment-avatar-indicator"
10185
label={ __( 'View notes' ) }
10286
onClick={ onClick }
10387
showTooltip
10488
>
10589
<div className="comment-avatar-stack">
10690
{ visibleParticipants.map( ( participant, index ) => (
10791
<img
108-
key={ participant.name + index }
92+
key={ participant.id }
10993
src={ participant.avatar }
11094
alt={ participant.name }
11195
className="comment-avatar"

packages/editor/src/components/collab-sidebar/hooks.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function useBlockComments( postId ) {
5353
per_page: -1,
5454
};
5555

56-
const { records: threads, totalPages } = useEntityRecords(
56+
const { records: threads } = useEntityRecords(
5757
'root',
5858
'comment',
5959
queryArgs,
@@ -160,7 +160,6 @@ export function useBlockComments( postId ) {
160160
return {
161161
resultComments,
162162
unresolvedSortedThreads,
163-
totalPages,
164163
reflowComments,
165164
commentLastUpdated,
166165
};

packages/editor/src/components/collab-sidebar/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ function NotesSidebar( { postId, mode } ) {
9797
const {
9898
resultComments,
9999
unresolvedSortedThreads,
100-
totalPages,
101100
reflowComments,
102101
commentLastUpdated,
103102
} = useBlockComments( postId );
@@ -106,8 +105,6 @@ function NotesSidebar( { postId, mode } ) {
106105
( unresolvedSortedThreads.length > 0 || showCommentBoard )
107106
);
108107

109-
const hasMoreComments = totalPages && totalPages > 1;
110-
111108
// Get the global styles to set the background color of the sidebar.
112109
const { merged: GlobalStyles } = useGlobalStylesContext();
113110
const backgroundColor = GlobalStyles?.styles?.color?.background;
@@ -152,7 +149,6 @@ function NotesSidebar( { postId, mode } ) {
152149
{ blockCommentId && (
153150
<CommentAvatarIndicator
154151
thread={ currentThread }
155-
hasMoreComments={ hasMoreComments }
156152
onClick={ openTheSidebar }
157153
/>
158154
) }

packages/editor/src/components/collab-sidebar/style.scss

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,6 @@
161161
min-width: auto;
162162
background: transparent;
163163
border: none;
164-
165-
&:hover::before {
166-
background: rgba(0, 0, 0, 0.04);
167-
}
168-
169-
&.has-unresolved {
170-
.comment-avatar-stack {
171-
&::after {
172-
content: "";
173-
position: absolute;
174-
top: -2px;
175-
right: -2px;
176-
width: $grid-unit-10;
177-
height: $grid-unit-10;
178-
background: #d63638;
179-
border-radius: $radius-round;
180-
border: $border-width solid $white;
181-
z-index: 10;
182-
}
183-
}
184-
}
185164
}
186165

187166
.comment-avatar-stack {

0 commit comments

Comments
 (0)