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(channel): polish the composer: docked mention picker with Agent details, round send button, plain dates (#22446)

Arvin Xu9cd8378e572d
diff --git a/src/features/Channels/ChannelConversation.tsx b/src/features/Channels/ChannelConversation.tsx
index 0a0f61c09bb..d02f4477e43 100644
--- a/src/features/Channels/ChannelConversation.tsx
+++ b/src/features/Channels/ChannelConversation.tsx
@@ -212,9 +212,7 @@ const Timeline = ({
role="separator"
{...stylex.props(styles.dateDivider)}
>
- <span {...stylex.props(styles.dateLine)} />
<time dateTime={date.toISOString()}>{timeFormats.date.format(date)}</time>
- <span {...stylex.props(styles.dateLine)} />
</div>
)}
{item.kind === 'event' ? (
diff --git a/src/features/Channels/Composer.tsx b/src/features/Channels/Composer.tsx
index e685c843e34..7d478931c0f 100644
--- a/src/features/Channels/Composer.tsx
+++ b/src/features/Channels/Composer.tsx
@@ -27,6 +27,8 @@ import { usePermission } from '@/hooks/usePermission';
import { useSingleton } from '@/hooks/useSingleton';
import { cacheScope } from '@/libs/replica';
import type { ChannelQueuedSendInput } from '@/store/channel';
+import { useHomeStore } from '@/store/home';
+import { homeAgentListSelectors } from '@/store/home/selectors';
import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';
import { useUserStore } from '@/store/user';
import { userProfileSelectors } from '@/store/user/selectors';
@@ -34,7 +36,7 @@ import { userProfileSelectors } from '@/store/user/selectors';
import { ComposerActions } from './ComposerActions';
import { MemberAvatar } from './MemberAvatar';
import { isCurrentUserMember, memberName } from './memberName';
-import { getMentionGroups } from './mentionGroups';
+import { getMentionGroups, mentionDescription } from './mentionGroups';
import type { ChannelMentionInvite } from './mentions';
import {
$insertChannelMentionBoundary,
@@ -115,6 +117,8 @@ export function Composer({
const sending = useRef(false);
const previousDocument = useRef('');
const [error, setError] = useState('');
+ /** The card the mention picker docks to, full width above the input like an IM. */
+ const [card, setCard] = useState<HTMLDivElement | null>(null);
const requests = useSingleton(createChannelSendRequest);
const attachments = useAttachments();
const { allowed } = usePermission('create_content');
@@ -248,6 +252,7 @@ export function Composer({
maxHeight={480}
minHeight={0}
resize={false}
+ slashMenuRef={setCard}
style={inputShell}
styles={{ body: { overflow: 'visible', padding: 0 } }}
header={
@@ -294,6 +299,7 @@ export function Composer({
content=""
editable={!busy}
editor={editor}
+ getPopupContainer={() => card}
placeholder={placeholder}
plugins={plugins}
slashPlacement="top"
@@ -309,12 +315,25 @@ export function Composer({
t('deletedMember'),
!!workspaceId,
).flatMap<ISlashOption>((group) => {
- const items = group.members.map((member) => ({
- icon: <MemberAvatar member={member} size={24} />,
- key: member.id,
- label: memberName(member, t('deletedMember')),
- metadata: { type: 'channel-member', id: member.id },
- }));
+ // Read when the picker opens; subscribing would rerender on every list change.
+ const agents = homeAgentListSelectors.allAgents(useHomeStore.getState());
+ const items = group.members.map((member) => {
+ const label = memberName(member, t('deletedMember'));
+ const agent = member.agentId
+ ? agents.find((item) => item.id === member.agentId)
+ : undefined;
+ return {
+ description: mentionDescription(
+ label,
+ agent?.title,
+ agent?.description || member.description,
+ ),
+ icon: <MemberAvatar member={member} size={24} />,
+ key: member.id,
+ label,
+ metadata: { type: 'channel-member', id: member.id },
+ };
+ });
return group.actorType
? [
{
@@ -385,6 +404,7 @@ export function Composer({
aria-label={t('send')}
disabled={busy || attachments.blocked}
loading={busy}
+ shape="round"
size={28}
type="primary"
onSend={() => void send()}
diff --git a/src/features/Channels/mentionGroups.test.ts b/src/features/Channels/mentionGroups.test.ts
index 39c1762ce9d..a85ccb96f59 100644
--- a/src/features/Channels/mentionGroups.test.ts
+++ b/src/features/Channels/mentionGroups.test.ts
@@ -1,7 +1,12 @@
import type { ChannelPublicMember } from '@lobechat/types';
import { describe, expect, it } from 'vitest';
-import { getMentionGroups, matchInviteAgents, MENTION_INVITE_LIMIT } from './mentionGroups';
+import {
+ getMentionGroups,
+ matchInviteAgents,
+ MENTION_INVITE_LIMIT,
+ mentionDescription,
+} from './mentionGroups';
const member = (
id: string,
@@ -129,3 +134,18 @@ describe('Agents an @mention can invite', () => {
).toHaveLength(MENTION_INVITE_LIMIT);
});
});
+
+describe('mention option description', () => {
+ it('shows the Agent role before what it does', () => {
+ expect(mentionDescription('设计助手', '界面设计', '审查界面稿')).toBe('界面设计 · 审查界面稿');
+ });
+
+ it('skips blank details and one that repeats the name', () => {
+ expect(mentionDescription('数据分析师', null, ' ', '分析指标')).toBe('分析指标');
+ expect(mentionDescription('Coder', 'Coder', 'Writes code')).toBe('Writes code');
+ });
+
+ it('gives a plain person no second line', () => {
+ expect(mentionDescription('Alice', undefined, '')).toBeUndefined();
+ });
+});
diff --git a/src/features/Channels/mentionGroups.ts b/src/features/Channels/mentionGroups.ts
index d73b18812be..d700ff9d53f 100644
--- a/src/features/Channels/mentionGroups.ts
+++ b/src/features/Channels/mentionGroups.ts
@@ -55,3 +55,16 @@ export function matchInviteAgents<T extends { id: string }>(
const { others, priority } = splitByPriority(matches, priorityIds);
return [...priority, ...others].slice(0, MENTION_INVITE_LIMIT);
}
+
+/**
+ * The second line of a mention option: an Agent's role, then what it does. Blank details and
+ * any that only repeat the shown name are dropped; nothing is left for a plain person.
+ */
+export function mentionDescription(name: string, ...details: (string | null | undefined)[]) {
+ const parts = [
+ ...new Set(
+ details.map((detail) => detail?.trim()).filter((detail) => !!detail && detail !== name),
+ ),
+ ];
+ return parts.length > 0 ? parts.join(' · ') : undefined;
+}
diff --git a/src/features/Channels/styles.ts b/src/features/Channels/styles.ts
index cfd642ecd94..26324824848 100644
--- a/src/features/Channels/styles.ts
+++ b/src/features/Channels/styles.ts
@@ -96,19 +96,15 @@ export const styles = stylex.create({
},
},
},
+ /** A plain centered date; a rule on each side read heavier than the messages it separates. */
dateDivider: {
display: 'flex',
alignItems: 'center',
- gap: 12,
+ justifyContent: 'center',
paddingBlock: 12,
fontSize: cssVar.fontSizeSM,
color: cssVar.colorTextSecondary,
},
- dateLine: {
- flex: '1',
- height: 1,
- backgroundColor: cssVar.colorBorderSecondary,
- },
/** Floats over the row's top-right corner while the row is hovered or focused. */
messageToolbar: {
position: 'absolute',
@@ -191,8 +187,9 @@ export const styles = stylex.create({
display: 'flex',
alignItems: 'flex-end',
gap: 8,
+ // 10px around the 28px buttons centers a single line in the 50px card.
minHeight: 48,
- paddingBlock: 8,
+ paddingBlock: 10,
paddingInline: 8,
},
composerEditor: {
@@ -201,8 +198,8 @@ export const styles = stylex.create({
minWidth: 0,
maxHeight: 240,
// Buttons sit on the last line; glyphs ride high in the line box, so drop the
- // text 2px to center it on the 28px icons beside it.
- marginBlockEnd: -2,
+ // text 1px to center it on the 28px icons beside it.
+ marginBlockEnd: -1,
},
/** Takes the composer's place while the channel or thread is archived. */
archivedNotice: {
diff --git a/src/features/Channels/useMentionInvites.tsx b/src/features/Channels/useMentionInvites.tsx
index d1d8dfc10a9..f3b82dfed5b 100644
--- a/src/features/Channels/useMentionInvites.tsx
+++ b/src/features/Channels/useMentionInvites.tsx
@@ -22,7 +22,7 @@ import { channelAgentIssueKey, toChannelAgentSelection } from './CreateChannel/a
import { getChannelSaveErrorKey } from './CreateChannel/saveError';
import { useChannelAgentDraft } from './CreateChannel/useChannelAgentDraft';
import { useChannelAgentOptions } from './CreateChannel/useChannelAgentOptions';
-import { matchInviteAgents, MENTION_INVITE_LIMIT } from './mentionGroups';
+import { matchInviteAgents, MENTION_INVITE_LIMIT, mentionDescription } from './mentionGroups';
import type { ChannelMentionInvite } from './mentions';
/** Like a chosen Agent in the invite dialog: it keeps its own device and directory. */
@@ -207,6 +207,7 @@ export const useMentionInvites = (
...agents.map((agent) => {
const name = agentDisplayName(agent, t('unnamedAgent'));
return {
+ description: mentionDescription(name, agent.title, agent.description),
icon: (
<AgentAvatar
agentId={agent.id}