Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(topic-comment): polish the comment list and thread panel (#22814)

AmAzing-1fde6bbb23b5
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 0d7b6ac2152..574428c5df1 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -3137,7 +3137,6 @@
"topicComment.removed": "This comment was removed by a Workspace Owner.",
"topicComment.removedOwn": "Your comment was removed by a Workspace Owner.",
"topicComment.removedOwnerView": "Removed by a Workspace Owner. This content is visible only to Workspace Owners during the recovery period.",
- "topicComment.repliesTitle": "Replies",
"topicComment.replies_one": "{{count}} reply",
"topicComment.replies_other": "{{count}} replies",
"topicComment.reply": "Reply",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index d3365ea0b54..8d576ff0851 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -3137,7 +3137,6 @@
"topicComment.removed": "此评论已被 Workspace Owner 移除。",
"topicComment.removedOwn": "你的评论已被 Workspace Owner 移除。",
"topicComment.removedOwnerView": "此评论已被 Workspace Owner 移除。恢复期内,只有 Workspace Owner 可以查看原内容。",
- "topicComment.repliesTitle": "回复",
"topicComment.replies_one": "{{count}} 条回复",
"topicComment.replies_other": "{{count}} 条回复",
"topicComment.reply": "回复",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index a3182125f95..65b8c0d8ed2 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -3591,7 +3591,6 @@ export default {
'topicComment.notFound': 'This comment no longer exists',
'topicComment.openMessageComments': 'Open {{count}} message comments',
'topicComment.placeholder': 'Add a comment…',
- 'topicComment.repliesTitle': 'Replies',
'topicComment.replies_one': '{{count}} reply',
'topicComment.replies_other': '{{count}} replies',
'topicComment.reply': 'Reply',
diff --git a/src/features/Portal/TopicComments/Body.tsx b/src/features/Portal/TopicComments/Body.tsx
index fb796db318d..2ee67012be4 100644
--- a/src/features/Portal/TopicComments/Body.tsx
+++ b/src/features/Portal/TopicComments/Body.tsx
@@ -65,6 +65,7 @@ const Body = memo(() => {
const pending = pendingCommentIds.has(root.id);
return (
<CommentCard
+ divided
comment={root}
key={root.id}
pending={pending}
diff --git a/src/features/Portal/TopicComments/CommentCard.tsx b/src/features/Portal/TopicComments/CommentCard.tsx
index 8616179ddfa..a0e6568b6d9 100644
--- a/src/features/Portal/TopicComments/CommentCard.tsx
+++ b/src/features/Portal/TopicComments/CommentCard.tsx
@@ -5,6 +5,7 @@ import {
Avatar,
Button,
confirmModal,
+ cx,
DropdownMenu,
Flexbox,
Icon,
@@ -21,6 +22,7 @@ import RichTextMessage from '@/features/Conversation/Messages/User/components/Ri
import MemberProfilePopup from '@/features/MemberProfileCard/MemberProfilePopup';
import { useTopicCommentMutations } from '@/features/TopicComment/hooks';
import { useActivityTime } from '@/hooks/useActivityTime';
+import { useEnterToSend } from '@/hooks/useEnterToSend';
import AnchorPreview from './AnchorPreview';
import { createTopicCommentUpdateInput, hasTopicCommentEditorData } from './commentContent';
@@ -32,25 +34,28 @@ import TopicCommentEditor, {
interface CommentCardProps {
comment: TopicCommentItem;
+ /** A thread in the comment list: separated from its neighbours by a hairline. */
+ divided?: boolean;
onDeleted?: (mode: 'hard' | 'moderated' | 'soft') => void;
onMutated?: () => void;
onOpenThread?: () => void;
pending?: boolean;
replyCount?: number;
- replyStyle?: boolean;
rootReplyCount?: number;
}
const CommentContent = memo<Pick<TopicCommentItem, 'content' | 'editorData'>>(
- ({ content, editorData }) => {
- return hasTopicCommentEditorData(editorData) ? (
- <RichTextMessage editorState={editorData} />
- ) : (
- <Markdown fontSize={14} variant={'chat'}>
- {content}
- </Markdown>
- );
- },
+ ({ content, editorData }) => (
+ <div className={styles.content}>
+ {hasTopicCommentEditorData(editorData) ? (
+ <RichTextMessage editorState={editorData} />
+ ) : (
+ <Markdown fontSize={14} variant={'chat'}>
+ {content}
+ </Markdown>
+ )}
+ </div>
+ ),
);
CommentContent.displayName = 'TopicCommentContent';
@@ -58,15 +63,16 @@ CommentContent.displayName = 'TopicCommentContent';
const CommentCard = memo<CommentCardProps>(
({
comment,
+ divided,
onDeleted,
onMutated,
onOpenThread,
pending,
replyCount,
- replyStyle,
rootReplyCount,
}) => {
- const { t } = useTranslation('chat');
+ const { t } = useTranslation(['chat', 'common']);
+ const shouldSendOnEnter = useEnterToSend();
const { text: time, title: timeTitle } = useActivityTime(comment.createdAt);
const { mutatingIds, remove, restore, update } = useTopicCommentMutations();
@@ -158,7 +164,7 @@ const CommentCard = memo<CommentCardProps>(
return (
<Flexbox
- className={`${styles.card} ${replyStyle ? styles.reply : ''}`}
+ className={cx(styles.card, divided && styles.cardDivided)}
data-topic-comment-id={comment.id}
gap={8}
>
@@ -239,6 +245,11 @@ const CommentCard = memo<CommentCardProps>(
setNextContent(content);
setNextEditorData(editorData);
}}
+ onPressEnter={(event) => {
+ if (!shouldSendOnEnter(event)) return;
+ void handleUpdate();
+ return true;
+ }}
/>
</div>
<Flexbox horizontal gap={8} justify={'flex-end'}>
@@ -255,8 +266,9 @@ const CommentCard = memo<CommentCardProps>(
)}
{onOpenThread && (
- <Flexbox horizontal justify={'flex-end'}>
+ <Flexbox horizontal>
<Button
+ className={styles.cardFooter}
icon={<Icon icon={MessageCircle} />}
size={'small'}
type={'text'}
@@ -272,7 +284,12 @@ const CommentCard = memo<CommentCardProps>(
{!editing && menuItems.length > 0 && (
<div className={`${styles.cardActions} topic-comment-actions`}>
<DropdownMenu items={menuItems}>
- <ActionIcon icon={MoreHorizontal} loading={mutating} size={'small'} />
+ <ActionIcon
+ icon={MoreHorizontal}
+ loading={mutating}
+ size={'small'}
+ title={t('more', { ns: 'common' })}
+ />
</DropdownMenu>
</div>
)}
diff --git a/src/features/Portal/TopicComments/Composer.tsx b/src/features/Portal/TopicComments/Composer.tsx
index a492aef73d3..848e6343821 100644
--- a/src/features/Portal/TopicComments/Composer.tsx
+++ b/src/features/Portal/TopicComments/Composer.tsx
@@ -1,4 +1,4 @@
-import { ChatInput, ChatInputActionBar, SendButton } from '@lobehub/editor/react';
+import { ChatInput, SendButton } from '@lobehub/editor/react';
import { Flexbox, toast } from '@lobehub/ui';
import { memo, useCallback, useRef } from 'react';
import { useTranslation } from 'react-i18next';
@@ -18,6 +18,8 @@ import TopicCommentEditor, { type TopicCommentEditorRef } from './TopicCommentEd
import { useComposerSubmit } from './useComposerSubmit';
interface ComposerProps {
+ /** Focus the input on mount: the user opened this view to write. */
+ autoFocus?: boolean;
messageId?: string;
onCreated?: () => void;
parentCommentId?: string;
@@ -26,7 +28,7 @@ interface ComposerProps {
}
const Composer = memo<ComposerProps>(
- ({ messageId, onCreated, parentCommentId, rootReplyCount, topicId }) => {
+ ({ autoFocus, messageId, onCreated, parentCommentId, rootReplyCount, topicId }) => {
const { t } = useTranslation('chat');
const workspaceId = useActiveWorkspaceId();
@@ -67,44 +69,46 @@ const Composer = memo<ComposerProps>(
if (!workspaceId || !canUseResource) return null;
+ const busy = creating || submitting;
+ const placeholder = parentCommentId
+ ? t('topicComment.replyPlaceholder')
+ : messageId
+ ? t('topicComment.messagePlaceholder')
+ : t('topicComment.placeholder');
+
return (
<Flexbox className={styles.composer}>
- <ChatInput
- resize={false}
- styles={{ body: { padding: 8 } }}
- footer={
- <ChatInputActionBar
- justify={'flex-end'}
- right={
- <SendButton
- disabled={creating || submitting || !content.trim()}
- loading={creating || submitting}
- shape={'round'}
- title={t('input.send')}
- type={'text'}
- onClick={submit}
- />
- }
- />
- }
- >
- <TopicCommentEditor
- disabled={creating || submitting}
- initialContent={content}
- initialEditorData={draft?.editorData}
- ref={editorRef}
- placeholder={
- parentCommentId
- ? t('topicComment.replyPlaceholder')
- : messageId
- ? t('topicComment.messagePlaceholder')
- : t('topicComment.placeholder')
- }
- onPressEnter={onPressEnter}
- onChange={({ content: nextContent, editorData }) =>
- setDraftContent(key, nextContent, editorData)
- }
- />
+ <ChatInput minHeight={0} resize={false} styles={{ body: { padding: 0 } }}>
+ <div className={styles.composerRow}>
+ <div className={styles.composerEditor}>
+ <TopicCommentEditor
+ compact
+ autoFocus={autoFocus}
+ disabled={busy}
+ initialContent={content}
+ initialEditorData={draft?.editorData}
+ placeholder={placeholder}
+ ref={editorRef}
+ onPressEnter={onPressEnter}
+ onChange={({ content: nextContent, editorData }) =>
+ setDraftContent(key, nextContent, editorData)
+ }
+ />
+ </div>
+ {/* Enter sends; like the Channel composer, Send appears once there is something to send. */}
+ {(busy || Boolean(content.trim())) && (
+ <SendButton
+ aria-label={t('input.send')}
+ disabled={busy}
+ loading={busy}
+ shape={'round'}
+ size={28}
+ title={t('input.send')}
+ type={'primary'}
+ onClick={submit}
+ />
+ )}
+ </div>
</ChatInput>
</Flexbox>
);
diff --git a/src/features/Portal/TopicComments/Sidebar.tsx b/src/features/Portal/TopicComments/Sidebar.tsx
index 6b3a1da3f5f..64c03f528d2 100644
--- a/src/features/Portal/TopicComments/Sidebar.tsx
+++ b/src/features/Portal/TopicComments/Sidebar.tsx
@@ -26,7 +26,7 @@ const styles = createStaticStyles(({ css }) => ({
}));
const TopicCommentsSidebar = memo(() => {
- const { t } = useTranslation('chat');
+ const { t } = useTranslation(['chat', 'common']);
const view = useChatStore(chatPortalSelectors.currentView);
const [goBack, openTopicComments] = useChatStore((s) => [s.goBack, s.openTopicComments]);
@@ -48,6 +48,7 @@ const TopicCommentsSidebar = memo(() => {
<ActionIcon
icon={ArrowLeft}
size={DESKTOP_HEADER_ICON_SMALL_SIZE}
+ title={t('back', { ns: 'common' })}
onClick={isThread ? goBack : () => openTopicComments(view.topicId)}
/>
<Text fontSize={13} weight={500}>
diff --git a/src/features/Portal/TopicComments/ThreadBody.tsx b/src/features/Portal/TopicComments/ThreadBody.tsx
index 32147a74a5e..8a08e007b6a 100644
--- a/src/features/Portal/TopicComments/ThreadBody.tsx
+++ b/src/features/Portal/TopicComments/ThreadBody.tsx
@@ -1,4 +1,4 @@
-import { Button, Center, Empty, Flexbox, Text } from '@lobehub/ui';
+import { Button, Center, Empty, Flexbox, Skeleton } from '@lobehub/ui';
import { MessageCircle } from 'lucide-react';
import { memo, useCallback, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
@@ -20,6 +20,9 @@ import { styles } from './styles';
import { resolveTopicCommentThreadState } from './threadState';
import { useTopicCommentEvents } from './useTopicCommentEvents';
+/** At most this many placeholder rows while the replies load. */
+const REPLY_SKELETON_MAX = 3;
+
const ThreadBody = memo(() => {
const { t } = useTranslation('chat');
const view = useChatStore(chatPortalSelectors.topicCommentThreadView);
@@ -80,6 +83,19 @@ const ThreadBody = memo(() => {
);
}, [focusedReply.data, replies.items, root.data, view?.focusCommentId]);
+ // The viewer's own reply lands at the end of the list; bring it into view once it is posted.
+ const lastReplyId = visibleReplies.at(-1)?.id;
+ const lastReplyIsOwnPending = Boolean(lastReplyId && replies.pendingCommentIds.has(lastReplyId));
+ useEffect(() => {
+ if (!lastReplyIsOwnPending) return;
+ const list = listRef.current;
+ if (!list) return;
+ const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
+ requestAnimationFrame(() =>
+ list.scrollTo({ behavior: reduceMotion ? 'auto' : 'smooth', top: list.scrollHeight }),
+ );
+ }, [lastReplyId, lastReplyIsOwnPending]);
+
if (!view) return null;
const state = resolveTopicCommentThreadState({
error: root.error,
@@ -107,6 +123,10 @@ const ThreadBody = memo(() => {
}
if (!root.data) return null;
+ // No heading for a thread nobody has replied to: the composer already says what to do.
+ const shownReplyCount = Math.max(replyCount, visibleReplies.length);
+ const repliesLoading = replies.isLoadingInitial && visibleReplies.length === 0;
+
return (
<Flexbox className={styles.body}>
<Flexbox className={styles.list} ref={listRef}>
@@ -120,12 +140,28 @@ const ThreadBody = memo(() => {
void root.mutate();
}}
/>
- <Text fontSize={12} style={{ marginTop: 16 }} type={'secondary'} weight={500}>
- {t('topicComment.repliesTitle')}
- </Text>
+ {shownReplyCount > 0 && (
+ <div className={styles.repliesDivider}>
+ {t('topicComment.replies', { count: shownReplyCount })}
+ </div>
+ )}
+ {repliesLoading && (
+ <Flexbox gap={16} paddingBlock={12}>
+ {Array.from({ length: Math.min(shownReplyCount, REPLY_SKELETON_MAX) }).map(
+ (_, index) => (
+ <Flexbox gap={8} key={index}>
+ <Flexbox horizontal align={'center'} gap={8}>
+ <Skeleton height={24} radius={12} width={24} />
+ <Skeleton height={14} width={96 + (index % 2) * 24} />
+ </Flexbox>
+ <Skeleton height={14} width={`${48 + (index % 3) * 14}%`} />
+ </Flexbox>
+ ),
+ )}
+ </Flexbox>
+ )}
{visibleReplies.map((reply) => (
<CommentCard
- replyStyle
comment={reply}
key={reply.id}
pending={replies.pendingCommentIds.has(reply.id)}
@@ -155,6 +191,7 @@ const ThreadBody = memo(() => {
)}
</Flexbox>
<Composer
+ autoFocus={view.initialReplyCount === 0}
parentCommentId={root.data.id}
rootReplyCount={replyCount}
topicId={view.topicId}
diff --git a/src/features/Portal/TopicComments/styles.ts b/src/features/Portal/TopicComments/styles.ts
index 5ecf7ea86d6..09ee6fdac4b 100644
--- a/src/features/Portal/TopicComments/styles.ts
+++ b/src/features/Portal/TopicComments/styles.ts
@@ -34,16 +34,16 @@ export const styles = createStaticStyles(({ css }) => ({
`,
card: css`
position: relative;
- padding-block: 14px;
- border-block-end: 1px solid ${cssVar.colorBorderSecondary};
+ padding-block: 12px;
- &:hover .topic-comment-actions {
+ &:hover .topic-comment-actions,
+ &:focus-within .topic-comment-actions {
opacity: 1;
}
`,
cardActions: css`
position: absolute;
- inset-block-start: 8px;
+ inset-block-start: 12px;
inset-inline-end: 0;
opacity: 1;
@@ -54,11 +54,49 @@ export const styles = createStaticStyles(({ css }) => ({
opacity: 0;
}
`,
+ /** Independent threads in the list: a hairline between neighbours, none after the last. */
+ cardDivided: css`
+ & + & {
+ border-block-start: 1px solid ${cssVar.colorBorderSecondary};
+ }
+ `,
+ /** Left-aligned under the content; pulled out so the icon lines up with the text column. */
+ cardFooter: css`
+ margin-inline-start: -8px;
+ color: ${cssVar.colorTextSecondary};
+ `,
composer: css`
flex-shrink: 0;
- margin-block: 12px 16px;
+ margin-block: 8px 16px;
margin-inline: 16px;
`,
+ composerEditor: css`
+ flex: 1;
+ min-width: 0;
+ padding-block: 2px;
+ `,
+ /** One row like a chat app: the input grows with its content, Send sits at its last line. */
+ composerRow: css`
+ display: flex;
+ gap: 8px;
+ align-items: flex-end;
+
+ min-height: 44px;
+ padding-block: 8px;
+ padding-inline: 12px 8px;
+ `,
+ /**
+ * Mentions render as plain coloured text here, so the chip's own inset would
+ * push a line-leading mention off the text column.
+ */
+ content: css`
+ min-width: 0;
+
+ .editor_mention {
+ margin-inline: 0;
+ padding-inline: 0;
+ }
+ `,
deleted: css`
font-style: italic;
color: ${cssVar.colorTextTertiary};
@@ -93,9 +131,22 @@ export const styles = createStaticStyles(({ css }) => ({
moderatedContent: css`
opacity: 0.62;
`,
- reply: css`
- margin-inline-start: 20px;
- padding-inline-start: 12px;
- border-inline-start: 1px solid ${cssVar.colorBorderSecondary};
+ /** "3 replies" followed by a rule: the one line that separates the comment from its replies. */
+ repliesDivider: css`
+ display: flex;
+ gap: 12px;
+ align-items: center;
+
+ margin-block: 4px;
+
+ font-size: 12px;
+ color: ${cssVar.colorTextTertiary};
+
+ &::after {
+ content: '';
+ flex: 1;
+ height: 1px;
+ background: ${cssVar.colorBorderSecondary};
+ }
`,
}));