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(sidebar): compact Favorites rows and show task status (#23203)

Rdmclin2f1b367d5421f
diff --git a/packages/database/src/models/__tests__/favorite.test.ts b/packages/database/src/models/__tests__/favorite.test.ts
index c3027d98645..4593730b935 100644
--- a/packages/database/src/models/__tests__/favorite.test.ts
+++ b/packages/database/src/models/__tests__/favorite.test.ts
@@ -3,7 +3,7 @@ import { FAVORITE_LIMIT } from '@lobechat/types';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { getTestDB } from '../../core/getTestDB';
-import { userFavorites, users, workspaces } from '../../schemas';
+import { tasks, userFavorites, users, workspaces } from '../../schemas';
import type { LobeChatDatabase } from '../../type';
import { FavoriteLimitError, FavoriteModel } from '../favorite';
@@ -34,6 +34,7 @@ beforeEach(async () => {
afterEach(async () => {
await serverDB.delete(userFavorites);
+ await serverDB.delete(tasks);
await serverDB.delete(users);
await serverDB.delete(workspaces);
});
@@ -69,6 +70,77 @@ describe('FavoriteModel', () => {
});
});
+ it('carries the current status of a favorited task', async () => {
+ await serverDB.insert(tasks).values([
+ {
+ createdByUserId: userId,
+ id: 'task_personal',
+ identifier: 'T-1',
+ instruction: 'x',
+ seq: 1,
+ status: 'running',
+ },
+ {
+ createdByUserId: userId,
+ id: 'task_ws',
+ identifier: 'T-2',
+ instruction: 'x',
+ seq: 2,
+ status: 'paused',
+ workspaceId,
+ },
+ {
+ createdByUserId: otherUserId,
+ id: 'task_private',
+ identifier: 'T-3',
+ instruction: 'x',
+ seq: 3,
+ status: 'failed',
+ visibility: 'private',
+ workspaceId,
+ },
+ {
+ createdByUserId: userId,
+ id: 'task_trashed',
+ identifier: 'T-4',
+ instruction: 'x',
+ isDeleted: true,
+ seq: 4,
+ status: 'running',
+ },
+ ]);
+ const task = (id: string) => ({
+ path: `/task/${id}`,
+ targetId: id,
+ title: id,
+ type: 'task' as const,
+ });
+
+ expect(await personalModel.add(task('task_personal'))).toMatchObject({ status: 'running' });
+ await personalModel.add(topic('tpc_1'));
+ // A task from another scope, or one that no longer exists, has no status to show.
+ await personalModel.add(task('task_ws'));
+ await personalModel.add(task('task_gone'));
+ // A task in the recycle bin is not a live task either.
+ await personalModel.add(task('task_trashed'));
+ await workspaceModel.add(task('task_ws'));
+ // Another member's private task stays hidden, status included.
+ expect(await workspaceModel.add(task('task_private'))).not.toHaveProperty('status');
+
+ const items = await personalModel.query();
+ expect(items.map((item) => [item.targetId, item.status])).toEqual([
+ ['task_personal', 'running'],
+ ['tpc_1', undefined],
+ ['task_ws', undefined],
+ ['task_gone', undefined],
+ ['task_trashed', undefined],
+ ]);
+
+ await serverDB.update(tasks).set({ status: 'completed' });
+ expect((await personalModel.query())[0].status).toBe('completed');
+ expect((await workspaceModel.query())[0].status).toBe('completed');
+ });
+
it('keeps personal, workspace and other members’ favorites apart', async () => {
await personalModel.add(topic('tpc_personal'));
await workspaceModel.add(topic('tpc_ws'));
diff --git a/packages/database/src/models/favorite.ts b/packages/database/src/models/favorite.ts
index 75be5980b94..6ad4f14f53f 100644
--- a/packages/database/src/models/favorite.ts
+++ b/packages/database/src/models/favorite.ts
@@ -3,11 +3,13 @@ import {
FAVORITE_LIMIT,
type FavoriteItem,
type FavoriteType,
+ type TaskStatus,
} from '@lobechat/types';
-import { and, asc, eq, inArray, isNull, type SQL, sql } from 'drizzle-orm';
+import { and, asc, eq, inArray, isNull, or, type SQL, sql } from 'drizzle-orm';
-import { userFavorites } from '../schemas';
+import { tasks, userFavorites } from '../schemas';
import type { LobeChatDatabase } from '../type';
+import { notTrashed } from '../utils/softDelete';
import { normalizeWorkspaceId } from '../utils/workspace';
/** Adding another favorite would exceed {@link FAVORITE_LIMIT}. */
@@ -24,10 +26,14 @@ export interface UpdateFavoriteParams {
title?: string;
}
-const toFavoriteItem = (row: typeof userFavorites.$inferSelect): FavoriteItem => ({
+const toFavoriteItem = (
+ row: typeof userFavorites.$inferSelect,
+ status?: string | null,
+): FavoriteItem => ({
icon: row.icon,
id: row.id,
path: row.path,
+ ...(row.type === 'task' && status ? { status: status as TaskStatus } : {}),
targetId: row.targetId,
title: row.title,
type: row.type,
@@ -57,14 +63,34 @@ export class FavoriteModel {
: isNull(userFavorites.workspaceId),
) as SQL;
+ /**
+ * Joins a task favorite to its task, in the same scope the favorite lives
+ * in and only while the member can still see it, so the sidebar can show
+ * the task's current status instead of a snapshot. A deleted, trashed,
+ * moved or since-hidden task simply has no status.
+ */
+ private taskJoin = (): SQL =>
+ and(
+ eq(userFavorites.type, 'task'),
+ eq(tasks.id, userFavorites.targetId),
+ notTrashed(tasks.isDeleted),
+ this.workspaceId
+ ? and(
+ eq(tasks.workspaceId, this.workspaceId),
+ or(eq(tasks.visibility, 'public'), eq(tasks.createdByUserId, this.userId)),
+ )
+ : and(isNull(tasks.workspaceId), eq(tasks.createdByUserId, this.userId)),
+ ) as SQL;
+
query = async (): Promise<FavoriteItem[]> => {
const rows = await this.db
- .select()
+ .select({ favorite: userFavorites, status: tasks.status })
.from(userFavorites)
+ .leftJoin(tasks, this.taskJoin())
.where(this.scope())
.orderBy(asc(userFavorites.sortOrder), asc(userFavorites.createdAt));
- return rows.map(toFavoriteItem);
+ return rows.map((row) => toFavoriteItem(row.favorite, row.status));
};
/**
@@ -129,7 +155,16 @@ export class FavoriteModel {
})
.returning();
- return toFavoriteItem(row);
+ if (row.type !== 'task') return toFavoriteItem(row);
+
+ const [task] = await tx
+ .select({ status: tasks.status })
+ .from(userFavorites)
+ .innerJoin(tasks, this.taskJoin())
+ .where(eq(userFavorites.id, row.id))
+ .limit(1);
+
+ return toFavoriteItem(row, task?.status);
});
remove = async (id: string): Promise<void> => {
diff --git a/packages/types/src/favorite.ts b/packages/types/src/favorite.ts
index f46ee360ff0..8604b06d5e6 100644
--- a/packages/types/src/favorite.ts
+++ b/packages/types/src/favorite.ts
@@ -1,3 +1,5 @@
+import type { TaskStatus } from './task';
+
/**
* What a sidebar favorite points at. A resource type identifies the row by
* `targetId`; `route` keeps any other in-app page, identified by its path.
@@ -39,6 +41,8 @@ export interface FavoriteItem {
* client adds the active workspace prefix when it navigates.
*/
path: string;
+ /** Current status of a `task` favorite; absent for other types or when the task is gone. */
+ status?: TaskStatus;
/** Resource id for resource types, the path for `route`. */
targetId: string;
/** Title snapshot; refreshed while the favorited page is open. */
diff --git a/src/features/Home/Recents/Item.tsx b/src/features/Home/Recents/Item.tsx
index dbdab57b071..e9f45c73423 100644
--- a/src/features/Home/Recents/Item.tsx
+++ b/src/features/Home/Recents/Item.tsx
@@ -2,6 +2,7 @@ import type { RecentItem } from '@lobechat/types';
import { ActionIcon, cssVar, DropdownMenu, Flexbox, Icon } from '@lobehub/ui';
import { FileTextIcon, HashIcon, MoreHorizontalIcon } from 'lucide-react';
import { memo, useCallback } from 'react';
+import { useTranslation } from 'react-i18next';
import { getPlatformIcon } from '@/features/AgentChannel/const';
import TaskStatusIcon from '@/features/AgentTasks/features/TaskStatusIcon';
@@ -12,6 +13,9 @@ import { usePrefetchPage } from '@/hooks/usePrefetchPage';
import { useRecentItemDropdownMenu } from './useDropdownMenu';
+/** Same density as the Favorites rows above. */
+const ICON_SIZE = 14;
+
const TYPE_ICON_MAP: Partial<Record<'document' | 'task' | 'topic', typeof FileTextIcon>> = {
document: FileTextIcon,
topic: HashIcon,
@@ -19,6 +23,7 @@ const TYPE_ICON_MAP: Partial<Record<'document' | 'task' | 'topic', typeof FileTe
const RecentListItem = memo<RecentItem>((item) => {
const { title, type, agentId, id, metadata, status } = item;
+ const { t } = useTranslation('common');
const IconComponent = TYPE_ICON_MAP[type] || FileTextIcon;
const prefetchAgent = usePrefetchAgent();
const prefetchPage = usePrefetchPage();
@@ -42,31 +47,37 @@ const RecentListItem = memo<RecentItem>((item) => {
return (
<Flexbox style={{ position: 'relative' }}>
<NavItem
+ compact
contextMenuItems={dropdownMenu}
title={title}
actions={
<DropdownMenu items={dropdownMenu()}>
- <ActionIcon icon={MoreHorizontalIcon} size={'small'} style={{ flex: 'none' }} />
+ <ActionIcon
+ aria-label={t('more')}
+ icon={MoreHorizontalIcon}
+ size={'small'}
+ style={{ flex: 'none' }}
+ />
</DropdownMenu>
}
icon={(() => {
if (type === 'task') {
// Same liveness signal as running topics: an executing task wears
// the animated running mark, not the static status glyph.
- if (status === 'running') return <RunningGlyph size={16} />;
- return <TaskStatusIcon size={16} status={status ?? 'backlog'} />;
+ if (status === 'running') return <RunningGlyph size={ICON_SIZE} />;
+ return <TaskStatusIcon size={ICON_SIZE} status={status ?? 'backlog'} />;
}
if (type === 'topic' && metadata?.bot?.platform) {
const ProviderIcon = getPlatformIcon(metadata.bot.platform);
if (ProviderIcon) {
- return <ProviderIcon color={cssVar.colorTextDescription} size={16} />;
+ return <ProviderIcon color={cssVar.colorTextDescription} size={ICON_SIZE} />;
}
}
return (
<Icon
icon={IconComponent}
- size={'small'}
+ size={ICON_SIZE}
style={{ color: cssVar.colorTextDescription }}
/>
);
diff --git a/src/features/Home/Recents/List.tsx b/src/features/Home/Recents/List.tsx
index aacaad44846..87e17dc1315 100644
--- a/src/features/Home/Recents/List.tsx
+++ b/src/features/Home/Recents/List.tsx
@@ -56,7 +56,7 @@ const RecentsList = memo<RecentsListProps>(({ error, onRetry }) => {
return <ConnectedItem itemRef={itemRef} key={itemRef} queryKey={queryKey} />;
})}
{hasMore && (
- <NavItem icon={MoreHorizontalIcon} title={t('input.more')} onClick={openDrawer} />
+ <NavItem compact icon={MoreHorizontalIcon} title={t('input.more')} onClick={openDrawer} />
)}
<AllRecentsDrawer open={drawerOpen} onClose={closeDrawer} />
</Flexbox>
diff --git a/src/features/HomeSidebar/Body/Favorites/FavoriteItem.tsx b/src/features/HomeSidebar/Body/Favorites/FavoriteItem.tsx
index c0b84674019..7f79417f90b 100644
--- a/src/features/HomeSidebar/Body/Favorites/FavoriteItem.tsx
+++ b/src/features/HomeSidebar/Body/Favorites/FavoriteItem.tsx
@@ -6,11 +6,12 @@ import { MoreHorizontalIcon, StarOffIcon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
-import { FavoriteIcon } from '@/features/Favorites';
import NavItem from '@/features/NavPanel/components/NavItem';
import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
import { useHomeStore } from '@/store/home';
+import FavoriteItemIcon from './FavoriteItemIcon';
+
interface FavoriteItemProps {
active?: boolean;
item: FavoriteItemType;
@@ -37,9 +38,10 @@ const FavoriteItem = memo<FavoriteItemProps>(({ active, item }) => {
return (
<WorkspaceLink to={item.path}>
<NavItem
+ compact
active={active}
contextMenuItems={menuItems}
- icon={<FavoriteIcon icon={item.icon} title={item.title} type={item.type} />}
+ icon={<FavoriteItemIcon item={item} />}
title={item.title}
actions={() => (
<DropdownMenu items={menuItems()}>
diff --git a/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.test.tsx b/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.test.tsx
new file mode 100644
index 00000000000..52a50cc55a0
--- /dev/null
+++ b/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.test.tsx
@@ -0,0 +1,87 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import type { FavoriteItem } from '@lobechat/types';
+import { cleanup, render, screen } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import FavoriteItemIcon from './FavoriteItemIcon';
+
+const state = vi.hoisted(() => ({
+ activeDetail: undefined as { id: string; status: string } | undefined,
+}));
+
+vi.mock('@/store/task', () => ({
+ useTaskStore: (selector: (s: unknown) => unknown) => selector({}),
+}));
+vi.mock('@/store/task/selectors', () => ({
+ taskDetailSelectors: { activeTaskDetail: () => state.activeDetail },
+}));
+vi.mock('@/features/AgentTasks/features/TaskStatusIcon', () => ({
+ default: ({ status }: { status: string }) => <span data-testid="status">{status}</span>,
+}));
+vi.mock('@/features/Home/components/RunningGlyph', () => ({
+ default: () => <span data-testid="running" />,
+}));
+vi.mock('@/features/Favorites', () => ({
+ FavoriteIcon: ({ type }: { type: string }) => <span data-testid="type">{type}</span>,
+}));
+
+const task = (status?: FavoriteItem['status']): FavoriteItem => ({
+ icon: null,
+ id: 'fav_1',
+ path: '/task/T-1',
+ status,
+ targetId: 'task_1',
+ title: 'Task',
+ type: 'task',
+});
+
+describe('FavoriteItemIcon', () => {
+ beforeEach(() => {
+ state.activeDetail = undefined;
+ });
+
+ afterEach(cleanup);
+
+ it('shows a task favorite by its listed status', () => {
+ render(<FavoriteItemIcon item={task('paused')} />);
+
+ expect(screen.getByTestId('status').textContent).toBe('paused');
+ });
+
+ it('prefers the open task detail, so a change on the page shows at once', () => {
+ state.activeDetail = { id: 'task_1', status: 'completed' };
+ render(<FavoriteItemIcon item={task('paused')} />);
+
+ expect(screen.getByTestId('status').textContent).toBe('completed');
+ });
+
+ it('ignores the detail of another open task', () => {
+ state.activeDetail = { id: 'task_2', status: 'completed' };
+ render(<FavoriteItemIcon item={task('paused')} />);
+
+ expect(screen.getByTestId('status').textContent).toBe('paused');
+ });
+
+ it('marks a running task with the live running glyph', () => {
+ render(<FavoriteItemIcon item={task('running')} />);
+
+ expect(screen.getByTestId('running')).toBeTruthy();
+ });
+
+ it('falls back to the type icon when the status is unknown or the item is not a task', () => {
+ render(
+ <>
+ <FavoriteItemIcon item={task()} />
+ <FavoriteItemIcon item={{ ...task('paused'), type: 'topic' }} />
+ </>,
+ );
+
+ expect(screen.getAllByTestId('type').map((node) => node.textContent)).toEqual([
+ 'task',
+ 'topic',
+ ]);
+ expect(screen.queryByTestId('status')).toBeNull();
+ });
+});
diff --git a/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.tsx b/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.tsx
new file mode 100644
index 00000000000..a24ecfe8aec
--- /dev/null
+++ b/src/features/HomeSidebar/Body/Favorites/FavoriteItemIcon.tsx
@@ -0,0 +1,43 @@
+'use client';
+
+import type { FavoriteItem, TaskStatus } from '@lobechat/types';
+import { memo } from 'react';
+
+import TaskStatusIcon from '@/features/AgentTasks/features/TaskStatusIcon';
+import { FavoriteIcon } from '@/features/Favorites';
+import RunningGlyph from '@/features/Home/components/RunningGlyph';
+import { useTaskStore } from '@/store/task';
+import { taskDetailSelectors } from '@/store/task/selectors';
+
+const ICON_SIZE = 14;
+
+/**
+ * Leading icon of a favorite row. A task wears its status, the way Recents
+ * shows it: the open task detail wins so a change made on the page shows at
+ * once, the listed status covers every other task (kept current by
+ * `useTaskFavoritesRefresh`), and a task with neither (deleted, moved) keeps
+ * the plain type icon.
+ */
+const FavoriteItemIcon = memo<{ item: FavoriteItem }>(({ item }) => {
+ const isTask = item.type === 'task';
+ // Only the detail open right now is kept in sync; a cached one left behind
+ // after the page closed could be older than the refreshed list.
+ const liveStatus = useTaskStore((s) => {
+ if (!isTask) return undefined;
+ const detail = taskDetailSelectors.activeTaskDetail(s);
+ return detail?.id === item.targetId ? detail.status : undefined;
+ });
+ const status = (liveStatus ?? item.status) as TaskStatus | undefined;
+
+ if (isTask && status) {
+ // An executing task wears the animated running mark, not the static glyph.
+ if (status === 'running') return <RunningGlyph size={ICON_SIZE} />;
+ return <TaskStatusIcon size={ICON_SIZE} status={status} />;
+ }
+
+ return <FavoriteIcon icon={item.icon} size={ICON_SIZE} title={item.title} type={item.type} />;
+});
+
+FavoriteItemIcon.displayName = 'FavoriteItemIcon';
+
+export default FavoriteItemIcon;
diff --git a/src/features/HomeSidebar/Body/Favorites/SortableFavoriteList.tsx b/src/features/HomeSidebar/Body/Favorites/SortableFavoriteList.tsx
index 4a7c26dd202..50168e2a650 100644
--- a/src/features/HomeSidebar/Body/Favorites/SortableFavoriteList.tsx
+++ b/src/features/HomeSidebar/Body/Favorites/SortableFavoriteList.tsx
@@ -26,7 +26,6 @@ import { createPortal } from 'react-dom';
import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
-import { FavoriteIcon } from '@/features/Favorites';
import { toFavoritePath } from '@/features/Favorites/path';
import NavItem from '@/features/NavPanel/components/NavItem';
import { useActiveLocation } from '@/hooks/useActiveLocation';
@@ -41,6 +40,8 @@ import {
suppressNextClick,
} from '../sortableRow';
import FavoriteItem from './FavoriteItem';
+import FavoriteItemIcon from './FavoriteItemIcon';
+import { useTaskFavoritesRefresh } from './useTaskFavoritesRefresh';
const styles = stylex.create({
overlay: {
@@ -86,6 +87,7 @@ SortableFavoriteItem.displayName = 'SortableFavoriteItem';
const SortableFavoriteList = memo<{ items: FavoriteItemType[] }>(({ items }) => {
const { t } = useTranslation('common');
const reorderFavorites = useHomeStore((s) => s.reorderFavorites);
+ useTaskFavoritesRefresh();
const { pathname } = useActiveLocation();
const currentPath = toFavoritePath(pathname, useActiveWorkspaceSlug());
@@ -136,7 +138,8 @@ const SortableFavoriteList = memo<{ items: FavoriteItemType[] }>(({ items }) =>
{activeItem ? (
<div {...stylex.props(styles.overlay)}>
<NavItem
- icon={<FavoriteIcon icon={activeItem.icon} type={activeItem.type} />}
+ compact
+ icon={<FavoriteItemIcon item={activeItem} />}
// The card itself is the surface: no hover tint on top of the white.
style={{ backgroundColor: 'transparent' }}
title={activeItem.title}
diff --git a/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.test.ts b/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.test.ts
new file mode 100644
index 00000000000..ab11eeba8bb
--- /dev/null
+++ b/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.test.ts
@@ -0,0 +1,85 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { renderHook } from '@testing-library/react';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { RUNNING_TASK_REFRESH_MS, useTaskFavoritesRefresh } from './useTaskFavoritesRefresh';
+
+const state = vi.hoisted(() => ({
+ activeTaskId: undefined as string | undefined,
+ favoriteTaskIds: new Set<string>(),
+ list: [] as { status?: string; type: string }[],
+ refreshFavorites: vi.fn(async () => {}),
+}));
+
+vi.mock('@/store/task', () => ({
+ useTaskStore: (selector: (s: unknown) => unknown) => selector({}),
+}));
+vi.mock('@/store/task/selectors', () => ({
+ taskDetailSelectors: { activeTaskDatabaseId: () => state.activeTaskId },
+}));
+vi.mock('@/store/home', () => {
+ const useHomeStore = (selector: (s: unknown) => unknown) =>
+ selector({ refreshFavorites: state.refreshFavorites });
+ useHomeStore.getState = () => ({});
+ return { useHomeStore };
+});
+vi.mock('@/store/home/selectors', () => ({
+ favoriteSelectors: {
+ favoriteList: () => state.list,
+ isFavorite: (_type: string, id: string) => () => state.favoriteTaskIds.has(id),
+ },
+}));
+
+describe('useTaskFavoritesRefresh', () => {
+ beforeEach(() => {
+ vi.useFakeTimers();
+ state.activeTaskId = undefined;
+ state.favoriteTaskIds = new Set(['task_fav']);
+ state.list = [{ status: 'paused', type: 'task' }];
+ state.refreshFavorites.mockClear();
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ it('refreshes the favorites when a favorited task page closes', () => {
+ state.activeTaskId = 'task_fav';
+ const { rerender } = renderHook(() => useTaskFavoritesRefresh());
+ expect(state.refreshFavorites).not.toHaveBeenCalled();
+
+ state.activeTaskId = undefined;
+ rerender();
+
+ expect(state.refreshFavorites).toHaveBeenCalledTimes(1);
+ });
+
+ it('leaves the favorites alone for a task that is not favorited', () => {
+ state.activeTaskId = 'task_other';
+ const { rerender } = renderHook(() => useTaskFavoritesRefresh());
+
+ state.activeTaskId = undefined;
+ rerender();
+
+ expect(state.refreshFavorites).not.toHaveBeenCalled();
+ });
+
+ it('polls only while a favorited task is running', () => {
+ const { rerender } = renderHook(() => useTaskFavoritesRefresh());
+ vi.advanceTimersByTime(RUNNING_TASK_REFRESH_MS * 2);
+ expect(state.refreshFavorites).not.toHaveBeenCalled();
+
+ state.list = [{ status: 'running', type: 'task' }];
+ rerender();
+ vi.advanceTimersByTime(RUNNING_TASK_REFRESH_MS * 2);
+ expect(state.refreshFavorites).toHaveBeenCalledTimes(2);
+
+ // The run finished: the next list has no running task, so polling stops.
+ state.list = [{ status: 'completed', type: 'task' }];
+ rerender();
+ vi.advanceTimersByTime(RUNNING_TASK_REFRESH_MS * 2);
+ expect(state.refreshFavorites).toHaveBeenCalledTimes(2);
+ });
+});
diff --git a/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.ts b/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.ts
new file mode 100644
index 00000000000..adf3f7de267
--- /dev/null
+++ b/src/features/HomeSidebar/Body/Favorites/useTaskFavoritesRefresh.ts
@@ -0,0 +1,54 @@
+import { useEffect, useRef } from 'react';
+
+import { useHomeStore } from '@/store/home';
+import { favoriteSelectors } from '@/store/home/selectors';
+import { useTaskStore } from '@/store/task';
+import { taskDetailSelectors } from '@/store/task/selectors';
+
+/** How often the list is refetched while a favorited task is running. */
+export const RUNNING_TASK_REFRESH_MS = 30_000;
+
+const refresh = (refreshFavorites: () => Promise<void>) => {
+ refreshFavorites().catch((error) => {
+ console.error('[favorite] failed to refresh task statuses', error);
+ });
+};
+
+/**
+ * Keep the listed status of task favorites current. While a task's page is
+ * open its row follows the live detail; otherwise it shows the listed status,
+ * so the list is refetched when a favorited task's page closes (to pick up a
+ * change made there) and, while any favorited task is running, on an interval
+ * that stops once none is (a run finishes in the background).
+ */
+export const useTaskFavoritesRefresh = () => {
+ const activeTaskId = useTaskStore(taskDetailSelectors.activeTaskDatabaseId);
+ const refreshFavorites = useHomeStore((s) => s.refreshFavorites);
+ const hasRunningTask = useHomeStore(
+ (s) =>
+ favoriteSelectors
+ .favoriteList(s)
+ ?.some((item) => item.type === 'task' && item.status === 'running') ?? false,
+ );
+ const previous = useRef(activeTaskId);
+
+ useEffect(() => {
+ const left = previous.current;
+ previous.current = activeTaskId;
+ if (!left || left === activeTaskId) return;
+ if (!favoriteSelectors.isFavorite('task', left)(useHomeStore.getState())) return;
+
+ refresh(refreshFavorites);
+ }, [activeTaskId, refreshFavorites]);
+
+ useEffect(() => {
+ if (!hasRunningTask) return;
+
+ const timer = setInterval(() => {
+ // A hidden tab refetches on focus anyway.
+ if (document.visibilityState === 'visible') refresh(refreshFavorites);
+ }, RUNNING_TASK_REFRESH_MS);
+
+ return () => clearInterval(timer);
+ }, [hasRunningTask, refreshFavorites]);
+};
diff --git a/src/features/NavPanel/components/NavItem.tsx b/src/features/NavPanel/components/NavItem.tsx
index 8b58a1a24ef..328c4f67f0b 100644
--- a/src/features/NavPanel/components/NavItem.tsx
+++ b/src/features/NavPanel/components/NavItem.tsx
@@ -54,7 +54,7 @@ const styles = createStaticStyles(({ css }) => ({
.${CONTENT_CLASS_NAME} {
mask-image: linear-gradient(
to right,
- #000 calc(100% - var(--nav-item-actions-inset) - 28px),
+ black calc(100% - var(--nav-item-actions-inset) - 28px),
transparent calc(100% - var(--nav-item-actions-inset))
);
}
@@ -93,6 +93,12 @@ export interface NavItemProps extends Omit<BlockProps, 'children' | 'title'> {
*/
actions?: LazyActions;
active?: boolean;
+ /**
+ * Denser single-line row for long lists of shortcuts (e.g. Favorites): 28px
+ * tall with 13px text and a 16px icon, instead of 36px / 14px / 18px. The
+ * icon column keeps its width, so titles still line up with the other rows.
+ */
+ compact?: boolean;
contextMenuItems?: DropdownItem[] | (() => DropdownItem[]);
/**
* Optional second line rendered under the title (e.g. a topic's project
@@ -125,9 +131,10 @@ const NavItem = memo<NavItemProps>(
actions,
contextMenuItems,
active,
+ compact,
href,
icon,
- iconSize = 18,
+ iconSize = compact ? 16 : 18,
title,
titleColor,
description,
@@ -180,6 +187,8 @@ const NavItem = memo<NavItemProps>(
}
: undefined;
+ const titleFontSize = compact ? 13 : undefined;
+
const iconNode = icon && (
<Center
flex={'none'}
@@ -205,7 +214,7 @@ const NavItem = memo<NavItemProps>(
className={cx(styles.container, className)}
clickable={!disabled}
gap={8}
- height={description ? undefined : 36}
+ height={description ? undefined : compact ? 28 : 36}
paddingBlock={description ? 8 : undefined}
paddingInline={4}
style={mergedStyle}
@@ -253,7 +262,11 @@ const NavItem = memo<NavItemProps>(
{titlePrefix}
{description ? (
<Flexbox flex={1} gap={3} style={{ overflow: 'hidden' }}>
- <Text color={textColor} ellipsis={{ tooltipWhenOverflow: true }}>
+ <Text
+ color={textColor}
+ ellipsis={{ tooltipWhenOverflow: true }}
+ fontSize={titleFontSize}
+ >
{title}
</Text>
{description}
@@ -261,6 +274,7 @@ const NavItem = memo<NavItemProps>(
) : (
<Text
color={textColor}
+ fontSize={titleFontSize}
style={{ flex: 1 }}
ellipsis={{
tooltipWhenOverflow: true,