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): one toolbar in a thread page's corner (#23560)

Lobehub Coderf4c0de59af5e
diff --git a/locales/en-US/channel.json b/locales/en-US/channel.json
index 70c440d96ad..f78e56710a5 100644
--- a/locales/en-US/channel.json
+++ b/locales/en-US/channel.json
@@ -40,6 +40,7 @@
"browse.search": "Search public channels",
"browse.title": "Browse channels",
"cancel": "Cancel",
+ "channel": "Channel",
"chooseDevice": "Choose a device",
"chooseDirectory": "Choose directory",
"closeThread": "Close thread",
diff --git a/locales/zh-CN/channel.json b/locales/zh-CN/channel.json
index bffdb081ce8..717c3e95a62 100644
--- a/locales/zh-CN/channel.json
+++ b/locales/zh-CN/channel.json
@@ -40,6 +40,7 @@
"browse.search": "搜索公开频道",
"browse.title": "浏览频道",
"cancel": "取消",
+ "channel": "频道",
"chooseDevice": "选择设备",
"chooseDirectory": "选择工作目录",
"closeThread": "关闭线程",
diff --git a/packages/locales/src/default/channel.ts b/packages/locales/src/default/channel.ts
index 08810f00ac6..716886171c1 100644
--- a/packages/locales/src/default/channel.ts
+++ b/packages/locales/src/default/channel.ts
@@ -146,6 +146,8 @@ export default {
'threadCard.messages_other': '{{count}} messages',
'closeThread': 'Close thread',
'thread': 'Thread',
+ /** Heads the Channel's own actions in a menu that also holds a thread's. */
+ 'channel': 'Channel',
'threadDivider': 'Replies in this thread',
'followers': 'Replies from: {{names}}',
'olderMessages': 'Older messages',
diff --git a/src/features/Channels/MemberStatus.test.tsx b/src/features/Channels/MemberStatus.test.tsx
index 010334a23f8..424f7269e6a 100644
--- a/src/features/Channels/MemberStatus.test.tsx
+++ b/src/features/Channels/MemberStatus.test.tsx
@@ -7,21 +7,26 @@ import { describe, expect, it, vi } from 'vitest';
import { MemberStatus } from './MemberStatus';
-const { openEnvironment } = vi.hoisted(() => ({ openEnvironment: vi.fn() }));
+const { menus, openEnvironment } = vi.hoisted(() => ({
+ menus: [] as any[][],
+ openEnvironment: vi.fn(),
+}));
vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
vi.mock('@lobehub/ui', () => ({
ActionIcon: ({ title }: { title?: string }) => createElement('button', {}, title),
Button: () => null,
// Lists the menu flat so each action can be read and clicked.
- DropdownMenu: ({ items }: { items: any[] }) =>
- createElement(
+ DropdownMenu: ({ items }: { items: any[] }) => {
+ menus.push(items);
+ return createElement(
'ul',
{},
items
.filter((item) => item.key)
.map((item) => createElement('li', { key: item.key, onClick: item.onClick }, item.key)),
- ),
+ );
+ },
Flexbox: ({ children }: { children?: unknown }) => createElement('div', {}, children as never),
Popover: () => null,
Text: () => null,
@@ -120,3 +125,40 @@ describe('MemberStatus in a group Channel', () => {
expect(menuKeys()).toEqual(['copyId']);
});
});
+
+describe('MemberStatus on a thread page', () => {
+ // The thread page header showed the thread's `…` right beside the Channel's `…`: two identical
+ // icons for two menus. The thread's actions now head the Channel's single menu.
+ it('folds the thread actions into the one Channel menu', () => {
+ menus.length = 0;
+ render(
+ createElement(MemberStatus, {
+ detail: detail({ agentId: null }),
+ threadMenu: [{ key: 'copyThreadLink' }, { key: 'deleteThread' }],
+ }),
+ );
+
+ expect(screen.getAllByRole('list')).toHaveLength(1);
+ expect(
+ menus.at(-1)!.map((item) =>
+ item.type === 'group'
+ ? {
+ [item.label]: item.children.map(
+ (child: { key?: string; type?: string }) => child.key ?? child.type,
+ ),
+ }
+ : item.type,
+ ),
+ ).toEqual([
+ { thread: ['copyThreadLink', 'deleteThread'] },
+ 'divider',
+ { channel: ['copyId', 'divider', 'settings'] },
+ ]);
+ });
+
+ it('keeps the plain Channel menu when the thread offers no actions', () => {
+ render(createElement(MemberStatus, { detail: detail({ agentId: null }), threadMenu: [] }));
+
+ expect(menuKeys()).toEqual(['copyId', 'settings']);
+ });
+});
diff --git a/src/features/Channels/MemberStatus.tsx b/src/features/Channels/MemberStatus.tsx
index 3355c40bfce..294f77d281e 100644
--- a/src/features/Channels/MemberStatus.tsx
+++ b/src/features/Channels/MemberStatus.tsx
@@ -1,5 +1,6 @@
import { CHANNEL_URL } from '@lobechat/const';
import type { ChannelDetail } from '@lobechat/types';
+import type { DropdownItem } from '@lobehub/ui';
import { ActionIcon, Button, DropdownMenu, Flexbox, Popover, Text } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
import {
@@ -42,9 +43,15 @@ const DIRECT_MENU_KEYS = new Set(['copyId', 'unarchive']);
export function MemberStatus({
detail,
memberPanel,
+ threadMenu,
}: {
detail: ChannelDetail;
memberPanel?: { id: string; open: boolean; onToggle: () => void };
+ /**
+ * The open thread page's actions. They join the Channel's in one menu, titled by what each
+ * group acts on, so the header keeps a single `…`.
+ */
+ threadMenu?: DropdownItem[];
}) {
const { t } = useTranslation('channel');
const [open, setOpen] = useState(false);
@@ -108,6 +115,15 @@ export function MemberStatus({
: []),
];
+ const ownMenu = direct ? directMenu() : groupMenu();
+ const menuItems: DropdownItem[] = threadMenu?.length
+ ? [
+ { children: threadMenu, key: 'threadGroup', label: t('thread'), type: 'group' },
+ { type: 'divider' },
+ { children: ownMenu, key: 'channelGroup', label: t('channel'), type: 'group' },
+ ]
+ : ownMenu;
+
return (
<Flexbox horizontal align="center" gap={4}>
<FailureIndicator detail={detail} />
@@ -194,7 +210,7 @@ export function MemberStatus({
}
/>
)}
- <DropdownMenu items={direct ? directMenu() : groupMenu()}>
+ <DropdownMenu items={menuItems}>
<ActionIcon
aria-label={t('more', { ns: 'common' })}
icon={MoreHorizontal}
diff --git a/src/features/Channels/ThreadPageTitle.tsx b/src/features/Channels/ThreadPageTitle.tsx
index a6d4501fb03..bcbb261b2bf 100644
--- a/src/features/Channels/ThreadPageTitle.tsx
+++ b/src/features/Channels/ThreadPageTitle.tsx
@@ -1,15 +1,13 @@
import type { ChannelDetail } from '@lobechat/types';
-import { ActionIcon, cssVar, DropdownMenu, Flexbox, Icon, Text } from '@lobehub/ui';
+import { cssVar, Flexbox, Icon, Text } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
-import { ChevronRight, GitBranch, Hash, MoreHorizontal } from 'lucide-react';
+import { ChevronRight, GitBranch, Hash } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { channelSelectors, useChannelStore } from '@/store/channel';
import { styles } from './styles';
-import { ThreadFollowers } from './ThreadPanel';
import { threadTitle } from './threadTitle';
-import { useThreadMenu } from './useThreadMenu';
/** The header of a thread opened as the page: `# Channel › thread`, the Channel leading back. */
export const ThreadPageTitle = ({
@@ -49,32 +47,3 @@ export const ThreadPageTitle = ({
</Flexbox>
);
};
-
-/** Followers and the thread menu, as the side panel shows them. */
-export const ThreadPageActions = ({
- detail,
- threadId,
-}: {
- detail: ChannelDetail;
- threadId: string;
-}) => {
- const { t } = useTranslation('channel');
- const threadMenu = useThreadMenu();
- const thread = detail.threads.find((entry) => entry.id === threadId);
- const menuItems = thread ? threadMenu(detail.channel, thread) : [];
- return (
- <Flexbox horizontal align="center" gap={8}>
- <ThreadFollowers detail={detail} target={threadId} />
- {menuItems.length > 0 && (
- <DropdownMenu items={menuItems}>
- <ActionIcon
- aria-label={t('more', { ns: 'common' })}
- icon={MoreHorizontal}
- size="small"
- title={t('more', { ns: 'common' })}
- />
- </DropdownMenu>
- )}
- </Flexbox>
- );
-};
diff --git a/src/features/Channels/index.tsx b/src/features/Channels/index.tsx
index 581dea4a56c..85279446641 100644
--- a/src/features/Channels/index.tsx
+++ b/src/features/Channels/index.tsx
@@ -24,9 +24,10 @@ import { openTopic } from './openTopic';
import { CHANNEL_ENTITY_PORTAL_SCOPE, PortalPanel } from './PortalPanel';
import { type ReplyTopic, ReplyTopicPanel } from './ReplyTopicPanel';
import { styles } from './styles';
-import { ThreadPageActions, ThreadPageTitle } from './ThreadPageTitle';
-import { THREAD_FLOAT_BREAKPOINT, ThreadPanel } from './ThreadPanel';
+import { ThreadPageTitle } from './ThreadPageTitle';
+import { THREAD_FLOAT_BREAKPOINT, ThreadFollowers, ThreadPanel } from './ThreadPanel';
import { channelBrowserSessionId, usePortalPanelOpen } from './usePortalPanel';
+import { useThreadMenu } from './useThreadMenu';
import { useThreadPanel } from './useThreadPanel';
/** One Channel: the main conversation, with a thread beside it, or one thread as the page. */
@@ -56,6 +57,10 @@ function EnabledChannelPage() {
const threadId = portalOpen ? null : panel.threadId;
const threadDraft = portalOpen ? null : panel.draft;
const pageThreadId = panel.pageThreadId;
+ const threadMenu = useThreadMenu();
+ const pageThread = pageThreadId
+ ? detail?.threads.find((entry) => entry.id === pageThreadId)
+ : undefined;
// A direct conversation's side panel is its Agent's profile; a workspace group's is the roster.
const hasMemberPanel =
!!directAgent || (!!detail?.channel.workspaceId && !detail.channel.agentId);
@@ -91,9 +96,10 @@ function EnabledChannelPage() {
right={
detail && (
<Flexbox horizontal align="center" gap={8}>
- {pageThreadId && <ThreadPageActions detail={detail} threadId={pageThreadId} />}
+ {pageThreadId && <ThreadFollowers detail={detail} target={pageThreadId} />}
<MemberStatus
detail={detail}
+ threadMenu={pageThread ? threadMenu(detail.channel, pageThread) : undefined}
memberPanel={
hasMemberPanel
? {
diff --git a/src/features/Electron/connection/Connection.tsx b/src/features/Electron/connection/Connection.tsx
index 65ad3386f7b..fd89f3dc448 100644
--- a/src/features/Electron/connection/Connection.tsx
+++ b/src/features/Electron/connection/Connection.tsx
@@ -10,7 +10,8 @@ import RemoteStatus from './RemoteStatus';
const isMac = isMacOS();
-const Connection = () => {
+/** `statusHidden` drops only the title bar icon; the drawer still opens from elsewhere. */
+const Connection = ({ statusHidden }: { statusHidden?: boolean }) => {
const [isOpen, setConnectionDrawerOpen] = useElectronStore((s) => [
s.isConnectionDrawerOpen,
s.setConnectionDrawerOpen,
@@ -23,6 +24,7 @@ const Connection = () => {
return (
<>
<RemoteStatus
+ hidden={statusHidden}
onClick={() => {
setConnectionDrawerOpen(true);
}}
diff --git a/src/features/Electron/connection/DeviceGateway.tsx b/src/features/Electron/connection/DeviceGateway.tsx
index 37224e3b7c6..5190855a662 100644
--- a/src/features/Electron/connection/DeviceGateway.tsx
+++ b/src/features/Electron/connection/DeviceGateway.tsx
@@ -69,10 +69,12 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
}));
interface DeviceGatewayProps {
+ /** Keeps the status subscriptions running while a page claims the corner for its own actions. */
+ hidden?: boolean;
workspaceScoped: boolean;
}
-const DeviceGateway = memo<DeviceGatewayProps>(({ workspaceScoped }) => {
+const DeviceGateway = memo<DeviceGatewayProps>(({ hidden, workspaceScoped }) => {
const { t } = useTranslation('electron');
const navigate = useWorkspaceAwareNavigate();
const [
@@ -188,6 +190,8 @@ const DeviceGateway = memo<DeviceGatewayProps>(({ workspaceScoped }) => {
</Flexbox>
);
+ if (hidden) return null;
+
return (
<Popover
arrow={false}
@@ -216,13 +220,13 @@ const DeviceGateway = memo<DeviceGatewayProps>(({ workspaceScoped }) => {
);
});
-const DeviceGatewayWithAuth = memo(() => {
+const DeviceGatewayWithAuth = memo<{ hidden?: boolean }>(({ hidden }) => {
const isSyncActive = useElectronStore(electronSyncSelectors.isSyncActive);
const activeWorkspaceSlug = useActiveWorkspaceSlug();
if (!isSyncActive) return null;
- return <DeviceGateway workspaceScoped={!!activeWorkspaceSlug} />;
+ return <DeviceGateway hidden={hidden} workspaceScoped={!!activeWorkspaceSlug} />;
});
export default DeviceGatewayWithAuth;
diff --git a/src/features/Electron/connection/RemoteStatus.tsx b/src/features/Electron/connection/RemoteStatus.tsx
index 17491f1ec6f..46c1f9f1fca 100644
--- a/src/features/Electron/connection/RemoteStatus.tsx
+++ b/src/features/Electron/connection/RemoteStatus.tsx
@@ -7,9 +7,11 @@ import { useElectronStore } from '@/store/electron';
import { electronSyncSelectors } from '@/store/electron/selectors';
interface SyncProps {
+ /** Keeps the remote config request running while a page claims the corner for its own actions. */
+ hidden?: boolean;
onClick: () => void;
}
-const RemoteStatus = memo<SyncProps>(({ onClick }) => {
+const RemoteStatus = memo<SyncProps>(({ hidden, onClick }) => {
const { t } = useTranslation('electron');
const [isIniting, isSyncActive, useRemoteServerConfig] = useElectronStore((s) => [
@@ -21,6 +23,8 @@ const RemoteStatus = memo<SyncProps>(({ onClick }) => {
// Use useSWR to fetch the remote server configuration
useRemoteServerConfig();
+ if (hidden) return null;
+
return (
<ActionIcon
icon={isIniting ? Loader : isSyncActive ? Wifi : WifiOffIcon}
diff --git a/src/features/Electron/titlebar/TitleBar.tsx b/src/features/Electron/titlebar/TitleBar.tsx
index f4682a20cae..01ae9f61128 100644
--- a/src/features/Electron/titlebar/TitleBar.tsx
+++ b/src/features/Electron/titlebar/TitleBar.tsx
@@ -2,6 +2,7 @@ import { TITLE_BAR_HEIGHT } from '@lobechat/desktop-bridge';
import { Divider, Flexbox } from '@lobehub/ui';
import { memo } from 'react';
+import { useActiveLocation } from '@/hooks/useActiveLocation';
import { useDeferredMount } from '@/hooks/useDeferredMount';
import { electronStylish } from '@/styles/electron';
import { getPlatform } from '@/utils/platform';
@@ -13,6 +14,7 @@ import { useWatchThemeUpdate } from '../system/useWatchThemeUpdate';
import { UpdateNotification } from '../updater/UpdateNotification';
import { getTitleBarLayoutConfig } from './layout';
import NavigationBar from './NavigationBar';
+import { isStatusHidden } from './statusHidden';
import TabBar from './TabBar';
import WinControl from './WinControl';
@@ -21,6 +23,7 @@ const platform = getPlatform();
const TitleBar = memo(() => {
useWatchThemeUpdate();
const tabBarMounted = useDeferredMount();
+ const statusHidden = isStatusHidden(useActiveLocation().pathname);
const { padding, showCustomWinControl } = getTitleBarLayoutConfig(platform);
@@ -40,9 +43,9 @@ const TitleBar = memo(() => {
<Flexbox horizontal align={'center'} gap={4}>
<Flexbox horizontal className={electronStylish.nodrag} gap={8}>
<UpdateNotification />
- <DeviceGateway />
+ <DeviceGateway hidden={statusHidden} />
<AutoEnrollWorkspaceDevice />
- <Connection />
+ <Connection statusHidden={statusHidden} />
</Flexbox>
{showCustomWinControl && (
<>
diff --git a/src/features/Electron/titlebar/statusHidden.test.ts b/src/features/Electron/titlebar/statusHidden.test.ts
new file mode 100644
index 00000000000..e14ea58c8ed
--- /dev/null
+++ b/src/features/Electron/titlebar/statusHidden.test.ts
@@ -0,0 +1,18 @@
+import { describe, expect, it } from 'vitest';
+
+import { isStatusHidden } from './statusHidden';
+
+describe('isStatusHidden', () => {
+ // The thread page showed the device and cloud icons above its own header actions: two toolbars
+ // stacked in the same corner.
+ it('hides the status icons on a Channel thread page', () => {
+ expect(isStatusHidden('/lobehub/project/prj_1/channels/chn_1/threads/cht_1')).toBe(true);
+ expect(isStatusHidden('/channels/chn_1/threads/cht_1')).toBe(true);
+ });
+
+ it('keeps them on the Channel itself and every other page', () => {
+ expect(isStatusHidden('/lobehub/channels/chn_1')).toBe(false);
+ expect(isStatusHidden('/channels/chn_1/settings')).toBe(false);
+ expect(isStatusHidden('/agent/agt_1')).toBe(false);
+ });
+});
diff --git a/src/features/Electron/titlebar/statusHidden.ts b/src/features/Electron/titlebar/statusHidden.ts
new file mode 100644
index 00000000000..98a88a08ee3
--- /dev/null
+++ b/src/features/Electron/titlebar/statusHidden.ts
@@ -0,0 +1,8 @@
+import { matchChannelThread } from '@/features/Channels/paths';
+
+/**
+ * Whether the title bar drops its device and cloud status icons for this page. A Channel thread
+ * page's header carries its own row of actions right under that corner, so the two icons above
+ * it read as a second, duplicate toolbar.
+ */
+export const isStatusHidden = (pathname: string): boolean => !!matchChannelThread(pathname);