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): one-click collapse/expand all topic groups (#15484)

Arvin Xu64b7ab2f1753
diff --git a/locales/en-US/topic.json b/locales/en-US/topic.json
index b83fa293169..1282b80e905 100644
--- a/locales/en-US/topic.json
+++ b/locales/en-US/topic.json
@@ -135,6 +135,8 @@
"renameModal.title": "Rename Topic",
"searchPlaceholder": "Search Topics...",
"searchResultEmpty": "No search results found.",
+ "sidebar.collapseAll": "Collapse all groups",
+ "sidebar.expandAll": "Expand all groups",
"sidebar.title": "Topics",
"taskManager.agent": "Task Agent",
"taskManager.welcome": "Ask me about your tasks",
diff --git a/locales/zh-CN/topic.json b/locales/zh-CN/topic.json
index 619a2acf2a3..ed9032264ab 100644
--- a/locales/zh-CN/topic.json
+++ b/locales/zh-CN/topic.json
@@ -135,6 +135,8 @@
"renameModal.title": "重命名话题",
"searchPlaceholder": "搜索话题…",
"searchResultEmpty": "暂无搜索结果",
+ "sidebar.collapseAll": "折叠所有分组",
+ "sidebar.expandAll": "展开所有分组",
"sidebar.title": "话题",
"taskManager.agent": "任务助手",
"taskManager.welcome": "问我关于你的任务",
diff --git a/src/locales/default/topic.ts b/src/locales/default/topic.ts
index 6def1e0ff25..0de5df0d2af 100644
--- a/src/locales/default/topic.ts
+++ b/src/locales/default/topic.ts
@@ -142,6 +142,8 @@ export default {
'renameModal.title': 'Rename Topic',
'searchPlaceholder': 'Search Topics...',
'searchResultEmpty': 'No search results found.',
+ 'sidebar.collapseAll': 'Collapse all groups',
+ 'sidebar.expandAll': 'Expand all groups',
'sidebar.title': 'Topics',
'taskManager.agent': 'Task Agent',
'taskManager.welcome': 'Ask me about your tasks',
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx
new file mode 100644
index 00000000000..8cdd9d31dcd
--- /dev/null
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/ToggleGroups.tsx
@@ -0,0 +1,52 @@
+import { ActionIcon } from '@lobehub/ui';
+import isEqual from 'fast-deep-equal';
+import { Maximize2, Minimize2 } from 'lucide-react';
+import { memo, useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { useChatStore } from '@/store/chat';
+import { topicSelectors } from '@/store/chat/selectors';
+import { useGlobalStore } from '@/store/global';
+import { systemStatusSelectors } from '@/store/global/selectors';
+import { useUserStore } from '@/store/user';
+import { preferenceSelectors } from '@/store/user/selectors';
+
+import { useAgentTopicGroupMode } from './hooks/useAgentTopicGroupMode';
+
+const ToggleGroups = memo(() => {
+ const { t } = useTranslation('topic');
+ const topicPageSize = useGlobalStore(systemStatusSelectors.topicPageSize);
+ const topicSortBy = useUserStore(preferenceSelectors.topicSortBy);
+ const { topicGroupMode } = useAgentTopicGroupMode();
+
+ const groupSelector = useMemo(
+ () => topicSelectors.groupedTopicsForSidebar(topicPageSize, topicSortBy, topicGroupMode),
+ [topicPageSize, topicSortBy, topicGroupMode],
+ );
+ const groupTopics = useChatStore(groupSelector, isEqual);
+
+ const [topicGroupKeys, updateSystemStatus] = useGlobalStore((s) => [
+ systemStatusSelectors.topicGroupKeys(s),
+ s.updateSystemStatus,
+ ]);
+
+ const groupIds = useMemo(() => groupTopics.map((group) => group.id), [groupTopics]);
+ // undefined means "default all expanded", so treat it as fully expanded
+ const expandedKeys = topicGroupKeys ?? groupIds;
+ const isAllCollapsed = expandedKeys.length === 0;
+
+ // flat mode renders FlatMode (no accordion), so the toggle has nothing to affect;
+ // also hide when there is at most one group, where toggling is meaningless
+ if (topicGroupMode === 'flat' || groupIds.length < 2) return null;
+
+ return (
+ <ActionIcon
+ icon={isAllCollapsed ? Maximize2 : Minimize2}
+ size={'small'}
+ title={isAllCollapsed ? t('sidebar.expandAll') : t('sidebar.collapseAll')}
+ onClick={() => updateSystemStatus({ expandTopicGroupKeys: isAllCollapsed ? groupIds : [] })}
+ />
+ );
+});
+
+export default ToggleGroups;
diff --git a/src/routes/(main)/agent/_layout/Sidebar/Topic/index.tsx b/src/routes/(main)/agent/_layout/Sidebar/Topic/index.tsx
index 269a32b5a81..14edfba52ca 100644
--- a/src/routes/(main)/agent/_layout/Sidebar/Topic/index.tsx
+++ b/src/routes/(main)/agent/_layout/Sidebar/Topic/index.tsx
@@ -13,6 +13,7 @@ import { topicSelectors } from '@/store/chat/selectors';
import Actions from './Actions';
import Filter from './Filter';
import List from './List';
+import ToggleGroups from './ToggleGroups';
import { useTopicActionsDropdownMenu } from './useDropdownMenu';
interface TopicProps {
@@ -32,6 +33,7 @@ const Topic = memo<TopicProps>(({ itemKey }) => {
paddingInline={'8px 4px'}
action={
<Flexbox horizontal align="center" gap={2}>
+ <ToggleGroups />
<Filter />
<Actions />
</Flexbox>