Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* WordPress dependencies
*/
import { Tooltip, __experimentalVStack as VStack } from '@wordpress/components';
import {
Tooltip,
__experimentalVStack as VStack,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { __, _x } from '@wordpress/i18n';
import {
dateI18n,
Expand All @@ -18,7 +22,14 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
*/
import { getAvatarBorderColor } from './utils';

function CommentAuthorInfo( { avatar, name, date, userId } ) {
function CommentAuthorInfo( {
avatar,
name,
date,
userId,
showUserInfo = true,
variant = 'default',
} ) {
const hasAvatar = !! avatar;
const dateSettings = getDateSettings();
const {
Expand Down Expand Up @@ -81,29 +92,46 @@ function CommentAuthorInfo( { avatar, name, date, userId } ) {
className="editor-collab-sidebar-panel__user-avatar"
// translators: alt text for user avatar image
alt={ __( 'User avatar' ) }
width={ 32 }
height={ 32 }
width={ variant === 'compact' ? 24 : 32 }
height={ variant === 'compact' ? 24 : 32 }
style={ {
borderColor: getAvatarBorderColor(
userId ?? currentUserId
),
} }
/>
<VStack spacing="0">
<span className="editor-collab-sidebar-panel__user-name">
{ name ?? currentUserName }
</span>
{ date && (
<Tooltip text={ tooltipText }>
{ showUserInfo && variant === 'default' && (
<VStack spacing="0">
<span className="editor-collab-sidebar-panel__user-name">
{ name ?? currentUserName }
</span>
{ date && (
<Tooltip text={ tooltipText }>
<time
dateTime={ commentDateTime }
className="editor-collab-sidebar-panel__user-time"
>
{ commentDateText }
</time>
</Tooltip>
) }
</VStack>
) }
{ showUserInfo && variant === 'compact' && (
<HStack spacing="2" alignment="left">
<span className="editor-collab-sidebar-panel__user-name">
{ name ?? currentUserName }
</span>
{ date && (
<time
dateTime={ commentDateTime }
className="editor-collab-sidebar-panel__user-time"
>
{ commentDateText }
</time>
</Tooltip>
) }
</VStack>
) }
</HStack>
) }
</>
);
}
Expand Down
83 changes: 60 additions & 23 deletions packages/editor/src/components/collab-sidebar/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function Comments( {
reflowComments,
isFloating = false,
commentLastUpdated,
isCompactNote = false,
} ) {
const [ heights, setHeights ] = useState( {} );
const [ boardOffsets, setBoardOffsets ] = useState( {} );
Expand Down Expand Up @@ -326,6 +327,7 @@ export function Comments( {
threads,
selectedNote,
setCanvasMinHeight,
isCompactNote,
] );

const handleThreadNavigation = ( event, thread, isSelected ) => {
Expand Down Expand Up @@ -438,6 +440,7 @@ export function Comments( {
selectedNote === thread.id
)
}
isCompactNote={ isCompactNote }
/>
) ) }
</>
Expand All @@ -458,7 +461,10 @@ function Thread( {
setBlockRef,
commentLastUpdated,
onKeyDown,
isCompactNote = false,
} ) {
const [ isHovered, setIsHovered ] = useState( false );
const [ isFocused, setIsFocused ] = useState( false );
const { toggleBlockHighlight, selectBlock, toggleBlockSpotlight } = unlock(
useDispatch( blockEditorStore )
);
Expand All @@ -479,22 +485,27 @@ function Thread( {
setBlockRef,
selectedThread: selectedNote,
commentLastUpdated,
isCompactNote,
} );
const isKeyboardTabbingRef = useRef( false );

const onMouseEnter = () => {
setIsHovered( true );
debouncedToggleBlockHighlight( thread.blockClientId, true );
};

const onMouseLeave = () => {
setIsHovered( false );
debouncedToggleBlockHighlight( thread.blockClientId, false );
};

const onFocus = () => {
setIsFocused( true );
toggleBlockHighlight( thread.blockClientId, true );
};

const onBlur = ( event ) => {
setIsFocused( false );
const isNoteFocused = event.relatedTarget?.closest(
'.editor-collab-sidebar-panel__thread'
);
Expand Down Expand Up @@ -578,6 +589,8 @@ function Thread( {
className={ clsx( 'editor-collab-sidebar-panel__thread', {
'is-selected': isSelected,
'is-floating': isFloating,
'is-compact-width':
! isSelected && isCompactNote && ! isHovered && ! isFocused,
} ) }
id={ `comment-thread-${ thread.id }` }
spacing="3"
Expand Down Expand Up @@ -624,26 +637,34 @@ function Thread( {
{ __( 'Original block deleted.' ) }
</Text>
) }
<CommentBoard
thread={ thread }
isExpanded={ isSelected }
onEdit={ ( params = {} ) => {
onEditComment( params );
if ( params.status === 'approved' ) {
unselectThread();
if ( isFloating ) {
relatedBlockElement?.focus();
} else {
focusCommentThread(
thread.id,
commentSidebarRef.current
);
{ ( isSelected || ! isCompactNote ) && (
<CommentBoard
thread={ thread }
isExpanded={ isSelected }
onEdit={ ( params = {} ) => {
onEditComment( params );
if ( params.status === 'approved' ) {
unselectThread();
if ( isFloating ) {
relatedBlockElement?.focus();
} else {
focusCommentThread(
thread.id,
commentSidebarRef.current
);
}
}
}
} }
onDelete={ onCommentDelete }
reflowComments={ reflowComments }
/>
} }
onDelete={ onCommentDelete }
reflowComments={ reflowComments }
/>
) }
{ ! isSelected && isCompactNote && (
<CommentBoardCompact
thread={ thread }
showUserInfo={ isHovered || isFocused }
/>
) }
{ isSelected &&
allReplies.map( ( reply ) => (
<CommentBoard
Expand All @@ -656,7 +677,7 @@ function Thread( {
reflowComments={ reflowComments }
/>
) ) }
{ ! isSelected && restReplies.length > 0 && (
{ ! isSelected && restReplies.length > 0 && ! isCompactNote && (
<HStack className="editor-collab-sidebar-panel__more-reply-separator">
<Button
size="compact"
Expand All @@ -682,7 +703,7 @@ function Thread( {
</Button>
</HStack>
) }
{ ! isSelected && lastReply && (
{ ! isSelected && lastReply && ! isCompactNote && (
<CommentBoard
thread={ lastReply }
parent={ thread }
Expand Down Expand Up @@ -906,7 +927,7 @@ const CommentBoard = ( {
</FlexItem>
) }
</HStack>
{ 'edit' === actionState ? (
{ 'edit' === actionState && (
<CommentForm
onSubmit={ ( value ) => {
onEdit( {
Expand All @@ -927,7 +948,8 @@ const CommentBoard = ( {
) }
reflowComments={ reflowComments }
/>
) : (
) }
{ 'edit' !== actionState && (
<RawHTML
className={ clsx(
'editor-collab-sidebar-panel__user-comment',
Expand Down Expand Up @@ -977,4 +999,19 @@ const CommentBoard = ( {
);
};

const CommentBoardCompact = ( { thread, showUserInfo = false } ) => {
return (
<HStack role={ thread.parent !== 0 ? 'treeitem' : undefined }>
<CommentAuthorInfo
avatar={ thread?.author_avatar_urls?.[ 48 ] }
name={ thread?.author_name }
date={ thread?.date }
userId={ thread?.author }
showUserInfo={ showUserInfo }
variant="compact"
/>
</HStack>
);
};

export default Comments;
4 changes: 3 additions & 1 deletion packages/editor/src/components/collab-sidebar/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export function useFloatingThread( {
selectedThread,
setBlockRef,
commentLastUpdated,
variant = 'default',
} ) {
const blockElement = useBlockElement( thread.blockClientId );
const updateHeight = useCallback(
Expand Down Expand Up @@ -412,7 +413,7 @@ export function useFloatingThread( {
}
}, [ blockElement, thread.id, refs.floating, setBlockRef ] );

// When the selected thread changes, update heights, triggering offset recalculation.
// When the selected thread or variant changes, update heights, triggering offset recalculation.
useEffect( () => {
if ( refs.floating?.current ) {
const newHeight = refs.floating.current.scrollHeight;
Expand All @@ -424,6 +425,7 @@ export function useFloatingThread( {
refs.floating,
selectedThread,
commentLastUpdated,
variant,
] );

return {
Expand Down
Loading
Loading