Repository navigation
feat(Comments): a renderTypingIndicator render prop shows who is typing #13741
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
base: refactor/comments-api-pass
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,21 +5,15 @@ | |
| /** | ||
| * @file CommentRow.tsx | ||
| * @input Uses React, StyleX, Astryx Card/Section/Link/Timestamp/Badge, | ||
| * useContainerReveal, useClickableContainer, ChatMessageMetadata, | ||
| * ChatTypingIndicator, and the Comments family's context and parts | ||
| * useContainerReveal, useClickableContainer, ChatMessageMetadata, the | ||
| * caller's typing indicator, and the Comments family's context and parts | ||
| * @output Exports CommentRow: a thread (its first comment, render-derived open | ||
| * replies, typing state, hidden seen metadata, and reply composer, on a | ||
| * selectable Card or Section) at depth 0, or a reply at depth 1 | ||
| * replies, typing state, and reply composer, on a selectable Card or | ||
| * Section) at depth 0, or a reply at depth 1 | ||
| * @position Internal row renderer shared by Comments and CommentThread | ||
| */ | ||
|
|
||
| import { | ||
| useCallback, | ||
| useRef, | ||
| useState, | ||
| type CSSProperties, | ||
| type ReactNode, | ||
| } from 'react'; | ||
| import {useCallback, useRef, useState, type ReactNode} from 'react'; | ||
| import * as stylex from '@stylexjs/stylex'; | ||
| import {Badge} from '@astryxdesign/core/Badge'; | ||
| import {Card} from '@astryxdesign/core/Card'; | ||
|
|
@@ -50,7 +44,6 @@ import { | |
| } from './CommentActions'; | ||
| import {CommentComposerBase} from './CommentComposer'; | ||
| import {CommentMarkdown} from './CommentMarkdown'; | ||
| import {ChatTypingIndicator} from '../Chat/ChatTypingIndicator'; | ||
| import { | ||
| AuthorName, | ||
| AvatarSpacer, | ||
|
|
@@ -80,17 +73,25 @@ import { | |
| import type { | ||
| CommentComposerContext, | ||
| CommentThreadData, | ||
| CommentTypingIndicatorRenderProps, | ||
| CommentUser, | ||
| } from './types'; | ||
|
|
||
| export type ThreadDivider = 'top' | 'bottom'; | ||
|
|
||
| /* Its own component, so the hooks of an indicator component run in their own | ||
| fiber, not in the row's render. */ | ||
| function TypingIndicatorSlot({ | ||
| render, | ||
| users, | ||
| }: CommentTypingIndicatorRenderProps & { | ||
| render: (props: CommentTypingIndicatorRenderProps) => ReactNode; | ||
| }) { | ||
| return render({users}); | ||
| } | ||
|
|
||
| /** The 28px avatar column (StyleX resolves only same-file constants). */ | ||
| const AVATAR_SIZE = `calc(${spacingVars['--spacing-6']} + ${spacingVars['--spacing-1']})`; | ||
| const TYPING_INDICATOR_STYLE: CSSProperties & | ||
| Record<'--astryx-chat-typing-indicator-dots-column-width', string> = { | ||
| '--astryx-chat-typing-indicator-dots-column-width': AVATAR_SIZE, | ||
| }; | ||
| export const THREAD_DIVIDERS: readonly ThreadDivider[] = ['top', 'bottom']; | ||
|
|
||
| const styles = stylex.create({ | ||
|
|
@@ -130,9 +131,6 @@ const styles = stylex.create({ | |
| flexBasis: 0, | ||
| minWidth: 0, | ||
| }, | ||
| typingIndicator: { | ||
| width: '100%', | ||
| }, | ||
| // Row controls carry one spacing step of inline padding. Pulling the row | ||
| // back by that step puts their glyphs on the body text line, so only their | ||
| // hover and pressed fills cross it. | ||
|
|
@@ -350,6 +348,7 @@ export function CommentRow({ | |
| replyError, | ||
| replyTarget, | ||
| selectedThreadId, | ||
| renderTypingIndicator, | ||
| } = scope; | ||
| const [isMetadataMenuOpen, setIsMetadataMenuOpen] = useState(false); | ||
| const {getContainerProps, getContentRevealProps} = useContainerReveal(); | ||
|
|
@@ -812,15 +811,17 @@ export function CommentRow({ | |
| ))} | ||
| </VStack> | ||
| )} | ||
| {depth === 0 && isThreadSelected && typingUsers.length > 0 && ( | ||
| <HStack width="100%" data-thread-typing-indicator="true"> | ||
| <ChatTypingIndicator | ||
| names={typingUsers.map(user => user.name)} | ||
| xstyle={styles.typingIndicator} | ||
| style={TYPING_INDICATOR_STYLE} | ||
| /> | ||
| </HStack> | ||
| )} | ||
| {depth === 0 && | ||
| isThreadSelected && | ||
| renderTypingIndicator != null && | ||
| typingUsers.length > 0 && ( | ||
| <HStack width="100%" data-thread-typing-indicator="true"> | ||
| <TypingIndicatorSlot | ||
| render={renderTypingIndicator} | ||
| users={typingUsers} | ||
| /> | ||
| </HStack> | ||
| )} | ||
|
Comment on lines
+814
to
+824
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Desktop behavior change needs an owner decision: with default props, an open thread whose |
||
| </VStack> | ||
|
|
||
| {depth === 0 && | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repeats
EmojiPickerSlotinCommentComposer.tsx:89-98, comment included, with other props. A later fix to how the family renders a slot, such as a caller that switches between two indicator components, would reach only one of them. Make one shared helper and use it in both places, for example:then delete
TypingIndicatorSlotandEmojiPickerSlot.