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.

✨ feat(favorites): add topics to Favorites (#21950)

Rdmclin2be87b3d8fd90
diff --git a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx
index e37a007ec68..77ae2b088c5 100644
--- a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx
+++ b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.test.tsx
@@ -7,6 +7,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { buildTopicPrompt } from './buildTopicPrompt';
import { useTopicItemDropdownMenu } from './useDropdownMenu';
+const favoriteMenuItemMock = vi.hoisted(() =>
+ vi.fn((target?: unknown) => (target ? { key: 'toggleFavorite', label: 'favorite.add' } : null)),
+);
+vi.mock('@/features/Favorites', () => ({ useFavoriteMenuItem: favoriteMenuItemMock }));
+
const locationFixture = vi.hoisted(() => ({ pathname: '/project/project-1/topic/topic-1' }));
const removeMock = vi.hoisted(() => vi.fn());
const confirmDeleteMock = vi.hoisted(() => vi.fn());
@@ -382,6 +387,7 @@ describe('useTopicItemDropdownMenu', () => {
expect(items.map((item) => (item && 'key' in item ? item.key : 'divider'))).toEqual([
'markCompleted',
'favorite',
+ 'toggleFavorite',
'divider',
'autoRename',
'rename',
@@ -504,4 +510,37 @@ describe('useTopicItemDropdownMenu', () => {
expect(result.current.canInlineArchive).toBe(false);
});
});
+
+ it('offers Favorites beside Pin, linking the row topic under its agent', () => {
+ const { result } = renderHook(() =>
+ useTopicItemDropdownMenu({ fav: true, id: 'topic-1', title: 'Topic 1' }),
+ );
+
+ const keys = result.current
+ .dropdownMenu()
+ .map((item) => (item && 'key' in item ? item.key : 'divider'));
+ expect(keys.slice(keys.indexOf('favorite'), keys.indexOf('favorite') + 2)).toEqual([
+ 'favorite',
+ 'toggleFavorite',
+ ]);
+ expect(favoriteMenuItemMock).toHaveBeenLastCalledWith(
+ {
+ path: '/agent/agent-1/topic-1',
+ snapshotReady: true,
+ targetId: 'topic-1',
+ title: 'Topic 1',
+ type: 'topic',
+ },
+ { showHotkey: false },
+ );
+ });
+
+ it('holds the favorite add until a placeholder topic title is replaced', () => {
+ renderHook(() => useTopicItemDropdownMenu({ id: 'topic-1', title: '...' }));
+
+ expect(favoriteMenuItemMock).toHaveBeenLastCalledWith(
+ expect.objectContaining({ snapshotReady: false }),
+ { showHotkey: false },
+ );
+ });
});
diff --git a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx
index dad76d93f52..f3605e03c2d 100644
--- a/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx
+++ b/src/features/AgentSidebar/Topic/List/Item/useDropdownMenu.tsx
@@ -34,6 +34,7 @@ import { isDesktop } from '@/const/version';
import { createMoveTopicsModal } from '@/features/AgentTopicManager/MoveTopicsModal';
import { createTopicForwardModal } from '@/features/Conversation/MessageForward/TopicForwardModal';
import { confirmRemoveTopic } from '@/features/DeleteTopicConfirm';
+import { useFavoriteMenuItem } from '@/features/Favorites';
import { getProjectTopicPath } from '@/features/Projects/Layout/navigation';
import { openShareModal } from '@/features/ShareModal';
import { openTopicDoctorModal } from '@/features/TopicDoctorModal';
@@ -102,6 +103,21 @@ export const useTopicItemDropdownMenu = ({
const appOrigin = useAppOrigin();
const enableTopicBugReport = useUserStore(labPreferSelectors.enableTopicBugReport);
const bugReportItem = useTopicBugReportMenuItem({ agentId: activeAgentId, topicId: id });
+ // Pin (`fav`) orders the topic list; a favorite adds the topic to the home
+ // sidebar's Favorites section. A topic still titled `...` is being named, so
+ // it waits for its real title before it can be added.
+ const favoriteMenuItem = useFavoriteMenuItem(
+ id && activeAgentId
+ ? {
+ path: AGENT_CHAT_TOPIC_URL(activeAgentId, id),
+ snapshotReady: !!title && title !== '...',
+ targetId: id,
+ title,
+ type: 'topic',
+ }
+ : undefined,
+ { showHotkey: false },
+ );
const [
autoRenameTopicTitle,
@@ -174,6 +190,7 @@ export const useTopicItemDropdownMenu = ({
},
sfSymbol: fav ? 'pin.slash' : 'pin',
},
+ ...(favoriteMenuItem ? [favoriteMenuItem] : []),
{
type: 'divider' as const,
},
@@ -407,6 +424,7 @@ export const useTopicItemDropdownMenu = ({
enableTopicBugReport,
autoRenameTopicTitle,
duplicateTopic,
+ favoriteMenuItem,
favoriteTopic,
toggleCompleted,
removeTopic,
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
index bdfefe3626b..3ba33aa98cc 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.test.tsx
@@ -6,6 +6,11 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import { useMenu } from './useMenu';
+const favoriteMenuItemMock = vi.hoisted(() =>
+ vi.fn((target?: unknown) => (target ? { key: 'toggleFavorite', label: 'favorite.add' } : null)),
+);
+vi.mock('@/features/Favorites', () => ({ useFavoriteMenuItem: favoriteMenuItemMock }));
+
const messageSuccessMock = vi.hoisted(() => vi.fn());
const modalConfirmMock = vi.hoisted(() => vi.fn());
const openTopicInNewWindowMock = vi.hoisted(() => vi.fn());
@@ -231,4 +236,23 @@ describe('Conversation header action menu', () => {
topicId: 'topic-1',
});
});
+
+ it('offers Favorites for the open topic beside Pin, without the hotkey', () => {
+ const { result } = renderHook(() => useMenu());
+
+ const keys = result.current
+ .menuItems()
+ .map((item) => (item && 'key' in item ? item.key : undefined));
+ expect(keys.slice(0, 2)).toEqual(['favorite', 'toggleFavorite']);
+ expect(favoriteMenuItemMock).toHaveBeenLastCalledWith(
+ {
+ path: '/agent/agent-1/topic-1',
+ snapshotReady: true,
+ targetId: 'topic-1',
+ title: 'Topic 1',
+ type: 'topic',
+ },
+ { showHotkey: false },
+ );
+ });
});
diff --git a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
index 3c77dc7ba29..8165e976991 100644
--- a/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
+++ b/src/routes/(main)/agent/features/Conversation/Header/HeaderActions/useMenu.tsx
@@ -1,5 +1,6 @@
'use client';
+import { AGENT_CHAT_TOPIC_URL } from '@lobechat/const';
import {
Block,
confirmModal,
@@ -35,6 +36,7 @@ import { DOCUMENT_HISTORY_QUERY_LIST_LIMIT } from '@/const/documentHistory';
import { isDesktop } from '@/const/version';
import { useAgentContext } from '@/features/Conversation/useAgentContext';
import { confirmRemoveTopic } from '@/features/DeleteTopicConfirm';
+import { useFavoriteMenuItem } from '@/features/Favorites';
import { openDocumentCompareModal } from '@/features/PageEditor/History/CompareModal';
import { formatHistoryAbsoluteTime } from '@/features/PageEditor/History/formatHistoryDate';
import type {
@@ -197,6 +199,20 @@ export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownIt
const topicId = activeTopic?.id;
const topicTitle = activeTopic?.title ?? '';
const isFavorite = !!activeTopic?.favorite;
+ // `isFavorite` above is the topic's Pin; this adds it to the home sidebar's
+ // Favorites section. No star button owns the hotkey here, so none is shown.
+ const favoriteMenuItem = useFavoriteMenuItem(
+ topicId && activeAgentId
+ ? {
+ path: AGENT_CHAT_TOPIC_URL(activeAgentId, topicId),
+ snapshotReady: !!topicTitle && topicTitle !== '...',
+ targetId: topicId,
+ title: topicTitle,
+ type: 'topic',
+ }
+ : undefined,
+ { showHotkey: false },
+ );
const enableTopicBugReport = useUserStore(labPreferSelectors.enableTopicBugReport);
const bugReportItem = useTopicBugReportMenuItem({
@@ -244,6 +260,7 @@ export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownIt
favoriteTopic(topicId, !isFavorite);
},
},
+ ...(favoriteMenuItem ? [favoriteMenuItem] : []),
{ type: 'divider' as const },
{
icon: <Icon icon={Wand2} />,
@@ -359,6 +376,7 @@ export const useMenu = (): { menuHeader?: ReactNode; menuItems: () => DropdownIt
bugReportItem,
enableTopicBugReport,
isFavorite,
+ favoriteMenuItem,
activeAgentId,
pathname,
workingDirectory,
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
index bc8042f943c..31e8919085e 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/index.tsx
@@ -189,6 +189,7 @@ const TopicItem = memo<TopicItemProps>(({ id, title, fav, active, threadId, stat
const dropdownMenu = useTopicItemDropdownMenu({
id,
status,
+ title,
toggleEditing,
});
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
index e95606bc257..3a1776c738f 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.test.tsx
@@ -6,6 +6,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import { useTopicItemDropdownMenu } from './useDropdownMenu';
+const favoriteMenuItemMock = vi.hoisted(() =>
+ vi.fn((target?: unknown) => (target ? { key: 'toggleFavorite', label: 'favorite.add' } : null)),
+);
+vi.mock('@/features/Favorites', () => ({ useFavoriteMenuItem: favoriteMenuItemMock }));
+
const permissionMock = vi.hoisted(() => ({
create_content: true,
edit_own_content: true,
@@ -100,6 +105,7 @@ describe('group useTopicItemDropdownMenu', () => {
const { result } = renderHook(() =>
useTopicItemDropdownMenu({
id: 'topic-1',
+ title: 'Topic 1',
toggleEditing: vi.fn(),
}),
);
@@ -123,7 +129,7 @@ describe('group useTopicItemDropdownMenu', () => {
const writeText = vi.fn();
vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
const { result } = renderHook(() =>
- useTopicItemDropdownMenu({ id: 'topic-1', toggleEditing: vi.fn() }),
+ useTopicItemDropdownMenu({ id: 'topic-1', title: 'Topic 1', toggleEditing: vi.fn() }),
);
copyLink(result.current());
@@ -136,11 +142,31 @@ describe('group useTopicItemDropdownMenu', () => {
const writeText = vi.fn();
vi.spyOn(navigator, 'clipboard', 'get').mockReturnValue({ writeText } as unknown as Clipboard);
const { result } = renderHook(() =>
- useTopicItemDropdownMenu({ id: 'topic-1', toggleEditing: vi.fn() }),
+ useTopicItemDropdownMenu({ id: 'topic-1', title: 'Topic 1', toggleEditing: vi.fn() }),
);
copyLink(result.current());
expect(writeText).toHaveBeenCalledWith('https://example.com/lobehub/group/group-1/topic-1');
});
+
+ it('favorites the topic by its group chat link', () => {
+ const { result } = renderHook(() =>
+ useTopicItemDropdownMenu({ id: 'topic-1', title: 'Topic 1', toggleEditing: vi.fn() }),
+ );
+
+ expect(result.current().map((item) => item && 'key' in item && item.key)).toContain(
+ 'toggleFavorite',
+ );
+ expect(favoriteMenuItemMock).toHaveBeenLastCalledWith(
+ {
+ path: '/group/group-1/topic-1',
+ snapshotReady: true,
+ targetId: 'topic-1',
+ title: 'Topic 1',
+ type: 'topic',
+ },
+ { showHotkey: false },
+ );
+ });
});
diff --git a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
index 44a890ef48e..b9d5a90acf5 100644
--- a/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
+++ b/src/routes/(main)/group/_layout/Sidebar/Topic/List/Item/useDropdownMenu.tsx
@@ -20,6 +20,7 @@ import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import { isDesktop } from '@/const/version';
import { confirmRemoveTopic } from '@/features/DeleteTopicConfirm';
+import { useFavoriteMenuItem } from '@/features/Favorites';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
import { useAppOrigin } from '@/hooks/useAppOrigin';
@@ -32,12 +33,14 @@ import { useGlobalStore } from '@/store/global';
interface TopicItemDropdownMenuProps {
id?: string;
status?: ChatTopicStatus | null;
+ title: string;
toggleEditing: (visible?: boolean) => void;
}
export const useTopicItemDropdownMenu = ({
id,
status,
+ title,
toggleEditing,
}: TopicItemDropdownMenuProps): (() => DropdownItem[]) => {
const { t } = useTranslation(['topic', 'common']);
@@ -51,6 +54,20 @@ export const useTopicItemDropdownMenu = ({
const activeGroupId = useAgentGroupStore((s) => s.activeGroupId);
const addTab = useElectronStore((s) => s.addTab);
const appOrigin = useAppOrigin();
+ // A favorite adds the topic to the home sidebar's Favorites section. A topic
+ // still titled `...` is being named, so it waits for its real title.
+ const favoriteMenuItem = useFavoriteMenuItem(
+ id && activeGroupId
+ ? {
+ path: GROUP_CHAT_TOPIC_URL(activeGroupId, id),
+ snapshotReady: !!title && title !== '...',
+ targetId: id,
+ title,
+ type: 'topic',
+ }
+ : undefined,
+ { showHotkey: false },
+ );
const [
autoRenameTopicTitle,
@@ -86,6 +103,7 @@ export const useTopicItemDropdownMenu = ({
},
sfSymbol: isCompleted ? 'tray.and.arrow.up' : 'archivebox',
},
+ ...(favoriteMenuItem ? [favoriteMenuItem] : []),
{
type: 'divider' as const,
},
@@ -203,6 +221,7 @@ export const useTopicItemDropdownMenu = ({
appOrigin,
autoRenameTopicTitle,
duplicateTopic,
+ favoriteMenuItem,
markTopicCompleted,
unmarkTopicCompleted,
removeTopic,