Skip to content

Commit

Permalink
fix(comments): nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Mar 11, 2024
1 parent 55f85b4 commit 398a1bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const EMPTY_ARRAY: [] = []

const MAX_COLLAPSED_REPLIES = 5

const DEFAULT_AVATAR_CONFIG: CommentsListItemProps['avatarConfig'] = {
avatarSize: 1,
parentCommentAvatar: true,
replyAvatar: true,
threadCommentsAvatar: true,
}

// data-active = when the comment is selected
// data-hovered = when the mouse is over the comment
const StyledThreadCard = styled(ThreadCard)(() => {
Expand Down Expand Up @@ -75,6 +82,12 @@ const GhostButton = styled.button`
`

interface CommentsListItemProps {
avatarConfig?: {
avatarSize: AvatarSize
parentCommentAvatar: boolean
replyAvatar: boolean
threadCommentsAvatar: boolean
}
canReply?: boolean
currentUser: CurrentUser
hasReferencedValue?: boolean
Expand All @@ -93,20 +106,8 @@ interface CommentsListItemProps {
parentComment: CommentDocument
readOnly?: boolean
replies: CommentDocument[] | undefined
avatarConfig?: {
parentCommentAvatar: boolean
threadCommentsAvatar: boolean
replyAvatar: boolean
avatarSize: AvatarSize
}
}

const DEFAULT_AVATAR_CONFIG: CommentsListItemProps['avatarConfig'] = {
parentCommentAvatar: true,
threadCommentsAvatar: true,
replyAvatar: true,
avatarSize: 1,
}
export const CommentsListItem = React.memo(function CommentsListItem(props: CommentsListItemProps) {
const {
canReply,
Expand Down Expand Up @@ -255,14 +256,14 @@ export const CommentsListItem = React.memo(function CommentsListItem(props: Comm
splicedReplies.map((reply) => (
<Stack as="li" key={reply._id} {...applyCommentIdAttr(reply._id)}>
<CommentsListItemLayout
withAvatar={avatarConfig.threadCommentsAvatar}
avatarSize={avatarConfig.avatarSize}
canDelete={reply.authorId === currentUser.id}
canEdit={reply.authorId === currentUser.id}
comment={reply}
currentUser={currentUser}
hasError={reply._state?.type === 'createError'}
isRetrying={reply._state?.type === 'createRetrying'}
intent={commentIntentIfDiffers(parentComment, reply)}
mentionOptions={mentionOptions}
mode={mode}
onCopyLink={onCopyLink}
Expand All @@ -272,7 +273,7 @@ export const CommentsListItem = React.memo(function CommentsListItem(props: Comm
onInputKeyDown={handleInputKeyDown}
onReactionSelect={onReactionSelect}
readOnly={readOnly}
intent={commentIntentIfDiffers(parentComment, reply)}
withAvatar={avatarConfig.threadCommentsAvatar}
/>
</Stack>
)),
Expand Down Expand Up @@ -358,7 +359,6 @@ export const CommentsListItem = React.memo(function CommentsListItem(props: Comm

{canReply && (
<CommentInput
withAvatar={avatarConfig.replyAvatar}
avatarSize={avatarConfig.avatarSize}
currentUser={currentUser}
expandOnFocus
Expand All @@ -376,6 +376,7 @@ export const CommentsListItem = React.memo(function CommentsListItem(props: Comm
readOnly={readOnly || mode === 'upsell'}
ref={replyInputRef}
value={value}
withAvatar={avatarConfig.replyAvatar}
/>
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const RootStack = styled(Stack)(({theme}) => {
})

interface CommentsListItemLayoutProps {
avatarSize?: AvatarSize
canDelete?: boolean
canEdit?: boolean
comment: CommentDocument
Expand All @@ -157,13 +158,13 @@ interface CommentsListItemLayoutProps {
onStatusChange?: (id: string, status: CommentStatus) => void
readOnly?: boolean
withAvatar?: boolean
avatarSize?: AvatarSize
}

const RELATIVE_TIME_OPTIONS: RelativeTimeOptions = {useTemporalPhrase: true}

export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
const {
avatarSize = 1,
canDelete,
canEdit,
comment,
Expand All @@ -184,7 +185,6 @@ export function CommentsListItemLayout(props: CommentsListItemLayoutProps) {
onStatusChange,
readOnly,
withAvatar = true,
avatarSize = 1,
} = props
const {_createdAt, authorId, message, _id, lastEditedAt} = comment
const [user] = useUser(authorId)
Expand Down

0 comments on commit 398a1bf

Please sign in to comment.