Repository navigation
Editor: Add compact notes mode for Notes sidebar #74985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9e93c62
Editor: Add compact notes mode for Notes sidebar
annezazu 98c1794
Editor: Address PR feedback for compact notes mode
annezazu b4815c0
Refactor and simplify
Mamaduka b5610de
Editor: Replace compact notes menu toggle with Notes dropdown
annezazu 46f02df
Merge branch 'trunk' into add/compact-notes-mode
t-hamano 2e0ca55
Make all notes sidebar pinable to access all notes on mobile screen
t-hamano 4dba71c
Make all note sidebars pinnable on mobile only
t-hamano 3a95262
Fix focus loss
t-hamano 46844da
Remove unused styles
t-hamano 6508260
Improve code readability
t-hamano 5ae45e3
Merge branch 'trunk' into add/compact-notes-mode
t-hamano 6c6b7a1
Fix e2e test
t-hamano 7c400b8
Merge branch 'trunk' into add/compact-notes-mode
t-hamano 10d05b0
Change preference name
t-hamano 0519d95
Merge branch 'trunk' into add/compact-notes-mode
t-hamano 60f6167
Don't persist notes mode
t-hamano 7d8dbae
Add "Hide notes" mode
t-hamano aaf9f0e
Enable "EXpand" mode when "Show all notes" is clicked
t-hamano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/editor/src/components/collab-sidebar/minified-thread-indicator.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { useMemo, useState } from '@wordpress/element'; | ||
| import { __unstableStripHTML as stripHTML } from '@wordpress/dom'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { store as coreStore } from '@wordpress/core-data'; | ||
| import { dateI18n, getDate } from '@wordpress/date'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getAvatarBorderColor, getCommentExcerpt } from './utils'; | ||
|
|
||
| /** | ||
| * A compact avatar indicator for a note thread. | ||
| * Shows a single avatar that expands on hover to show author details. | ||
| * | ||
| * @param {Object} props Component props. | ||
| * @param {Object} props.thread The thread data. | ||
| * @param {number} props.y The vertical position from floating-ui. | ||
| * @param {Object} props.refs The refs object from floating-ui. | ||
| * @param {Function} props.onExpand Callback when indicator is clicked/activated. | ||
| * @param {Function} props.onKeyDown Callback for keyboard navigation. | ||
| */ | ||
| export default function MinifiedThreadIndicator( { | ||
| thread, | ||
| y, | ||
| refs, | ||
| onExpand, | ||
| onKeyDown, | ||
| } ) { | ||
| const [ isHovered, setIsHovered ] = useState( false ); | ||
|
|
||
| const currentUserId = useSelect( ( select ) => { | ||
| return select( coreStore ).getCurrentUser()?.id; | ||
| }, [] ); | ||
|
|
||
| // Get the last comment (most recent reply, or the thread itself if no replies). | ||
| const lastComment = useMemo( () => { | ||
| const replies = thread?.reply || []; | ||
| if ( replies.length > 0 ) { | ||
| return replies[ replies.length - 1 ]; | ||
| } | ||
| return thread; | ||
| }, [ thread ] ); | ||
|
|
||
| const commentExcerpt = getCommentExcerpt( | ||
| stripHTML( thread.content?.rendered ), | ||
| 10 | ||
| ); | ||
|
|
||
| // Show unread indicator if last comment is from another user. | ||
| const hasUnread = | ||
| currentUserId && lastComment?.author !== currentUserId; | ||
|
annezazu marked this conversation as resolved.
Resolved
|
||
|
|
||
| // Format the time for display (e.g., "12:42 PM"). | ||
| const formattedTime = lastComment?.date | ||
| ? dateI18n( 'g:i A', getDate( lastComment.date ) ) | ||
|
annezazu marked this conversation as resolved.
Resolved
|
||
| : ''; | ||
|
|
||
| const handleClick = ( event ) => { | ||
| event.stopPropagation(); | ||
| onExpand(); | ||
| }; | ||
|
|
||
| const handleKeyDown = ( event ) => { | ||
| if ( event.key === 'Enter' || event.key === ' ' ) { | ||
| event.preventDefault(); | ||
| onExpand(); | ||
| } else if ( onKeyDown ) { | ||
| // Handle arrow key navigation. | ||
| onKeyDown( event ); | ||
| } | ||
| }; | ||
|
|
||
| if ( ! lastComment?.author_avatar_urls ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className={ `editor-collab-sidebar-panel__minified-indicator${ | ||
| isHovered ? ' is-expanded' : '' | ||
| }` } | ||
| id={ `comment-thread-${ thread.id }` } | ||
| onClick={ handleClick } | ||
| onKeyDown={ handleKeyDown } | ||
| onMouseEnter={ () => setIsHovered( true ) } | ||
| onMouseLeave={ () => setIsHovered( false ) } | ||
| onFocus={ () => setIsHovered( true ) } | ||
| onBlur={ () => setIsHovered( false ) } | ||
| tabIndex={ 0 } | ||
| role="treeitem" | ||
| aria-label={ sprintf( | ||
| // translators: %s: note excerpt | ||
| __( 'Note: %s' ), | ||
| commentExcerpt | ||
| ) } | ||
| aria-expanded={ isHovered } | ||
| ref={ refs?.setFloating } | ||
| style={ { top: y } } | ||
| > | ||
| <img | ||
| src={ lastComment?.author_avatar_urls?.[ 48 ] } | ||
| alt={ lastComment?.author_name } | ||
| className="editor-collab-sidebar-panel__minified-avatar" | ||
| style={ { | ||
| borderColor: getAvatarBorderColor( lastComment?.author ), | ||
| } } | ||
| /> | ||
| { isHovered && ( | ||
| <> | ||
| <span className="editor-collab-sidebar-panel__minified-author-name"> | ||
| { lastComment?.author_name } | ||
| </span> | ||
| <span className="editor-collab-sidebar-panel__minified-time"> | ||
| { formattedTime } | ||
| </span> | ||
| </> | ||
| ) } | ||
| { hasUnread && ( | ||
| <span className="editor-collab-sidebar-panel__minified-unread-dot" /> | ||
| ) } | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.