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(home): polish brief recommendations layout (#14871)

YuTengjingf94f941fe85c
diff --git a/.agents/skills/react/SKILL.md b/.agents/skills/react/SKILL.md
index 9bac31b7318..b180bc1a25f 100644
--- a/.agents/skills/react/SKILL.md
+++ b/.agents/skills/react/SKILL.md
@@ -85,11 +85,12 @@ errorElement: <ErrorBoundary />;
## Common Mistakes
-| Mistake | Fix |
-| ---------------------------------------- | ------------------------------------------------------ |
-| Using `next/link` in SPA | Use `react-router-dom` `Link` |
-| Using antd directly | Use `@lobehub/ui/base-ui` first, then `@lobehub/ui` |
-| `createStyles` for static styles | Use `createStaticStyles` + `cssVar` |
-| Editing only `desktopRouter.config.tsx` | Must edit both `.tsx` and `.desktop.tsx` |
-| Using `margin` for flex spacing | Use `gap` prop on Flexbox |
-| Accessing zustand store without selector | Use selectors to access store data (see zustand skill) |
+| Mistake | Fix |
+| ----------------------------------------------------------------- | ----------------------------------------------------------------- |
+| Using `next/link` in SPA | Use `react-router-dom` `Link` |
+| Using antd directly | Use `@lobehub/ui/base-ui` first, then `@lobehub/ui` |
+| `createStyles` for static styles | Use `createStaticStyles` + `cssVar` |
+| Editing only `desktopRouter.config.tsx` | Must edit both `.tsx` and `.desktop.tsx` |
+| Using `margin` for flex spacing | Use `gap` prop on Flexbox |
+| Accessing zustand store without selector | Use selectors to access store data (see zustand skill) |
+| Text or icon-text actions built with `Flexbox`/`Text` + `onClick` | Use `Button type={'text'} size={'small'}` with `icon` when needed |
diff --git a/src/features/DailyBrief/__tests__/index.test.tsx b/src/features/DailyBrief/__tests__/index.test.tsx
new file mode 100644
index 00000000000..a6a66286df9
--- /dev/null
+++ b/src/features/DailyBrief/__tests__/index.test.tsx
@@ -0,0 +1,147 @@
+import { render, screen } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import DailyBrief from '..';
+
+interface MockBrief {
+ id: string;
+ title: string;
+}
+
+const mocks = vi.hoisted(() => ({
+ state: {
+ briefs: [] as MockBrief[],
+ isBriefsInit: true,
+ isLogin: true,
+ recommendationsVisible: true,
+ },
+ useFetchBriefs: vi.fn(),
+}));
+
+vi.mock('@lobehub/ui', () => ({
+ Button: ({ children, onClick }: { children: ReactNode; onClick?: () => void }) => (
+ <button onClick={onClick}>{children}</button>
+ ),
+ Flexbox: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+}));
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string) => {
+ const map: Record<string, string> = {
+ 'brief.title': 'Brief',
+ 'brief.viewAllTasks': 'View all tasks',
+ };
+ return map[key] || key;
+ },
+ }),
+}));
+
+vi.mock('react-router-dom', () => ({
+ useNavigate: () => vi.fn(),
+}));
+
+vi.mock('@/features/AgentTasks/AgentTaskDetail/TopicChatDrawer', () => ({
+ default: () => <div data-testid="topic-chat-drawer" />,
+}));
+
+vi.mock('@/features/DocumentModal/Preview', () => ({
+ default: () => <div data-testid="document-preview-modal" />,
+}));
+
+vi.mock('@/features/Recommendations', () => ({
+ default: () => <div>Recommendations</div>,
+ useRecommendationsVisible: () => mocks.state.recommendationsVisible,
+}));
+
+vi.mock('@/routes/(main)/home/features/components/GroupBlock', () => ({
+ default: ({
+ action,
+ children,
+ title,
+ }: {
+ action?: ReactNode;
+ children: ReactNode;
+ title?: ReactNode;
+ }) => (
+ <section data-testid="group-block">
+ <header>
+ {title}
+ {action}
+ </header>
+ {children}
+ </section>
+ ),
+}));
+
+vi.mock('@/store/brief', () => ({
+ useBriefStore: (
+ selector: (state: {
+ briefs: MockBrief[];
+ isBriefsInit: boolean;
+ useFetchBriefs: typeof mocks.useFetchBriefs;
+ }) => unknown,
+ ) =>
+ selector({
+ briefs: mocks.state.briefs,
+ isBriefsInit: mocks.state.isBriefsInit,
+ useFetchBriefs: mocks.useFetchBriefs,
+ }),
+}));
+
+vi.mock('@/store/brief/selectors', () => ({
+ briefListSelectors: {
+ briefs: (state: { briefs: MockBrief[] }) => state.briefs,
+ isBriefsInit: (state: { isBriefsInit: boolean }) => state.isBriefsInit,
+ },
+}));
+
+vi.mock('@/store/user', () => ({
+ useUserStore: (selector: (state: { isLogin: boolean }) => unknown) =>
+ selector({ isLogin: mocks.state.isLogin }),
+}));
+
+vi.mock('@/store/user/slices/auth/selectors', () => ({
+ authSelectors: {
+ isLogin: (state: { isLogin: boolean }) => state.isLogin,
+ },
+}));
+
+vi.mock('../BriefCard', () => ({
+ default: ({ brief }: { brief: MockBrief }) => <article>{brief.title}</article>,
+}));
+
+vi.mock('../BriefCardSkeleton', () => ({
+ BriefCardSkeleton: () => <div>Brief skeleton</div>,
+}));
+
+beforeEach(() => {
+ mocks.state.briefs = [];
+ mocks.state.isBriefsInit = true;
+ mocks.state.isLogin = true;
+ mocks.state.recommendationsVisible = true;
+ mocks.useFetchBriefs.mockClear();
+});
+
+describe('DailyBrief', () => {
+ it('renders recommendations without the brief group header when no briefs are available', () => {
+ render(<DailyBrief />);
+
+ expect(screen.getByText('Recommendations')).toBeInTheDocument();
+ expect(screen.queryByTestId('group-block')).not.toBeInTheDocument();
+ expect(screen.queryByText('Brief')).not.toBeInTheDocument();
+ expect(screen.queryByText('View all tasks')).not.toBeInTheDocument();
+ });
+
+ it('renders the brief group header when briefs are available', () => {
+ mocks.state.briefs = [{ id: 'brief-1', title: 'Brief item' }];
+
+ render(<DailyBrief />);
+
+ expect(screen.getByTestId('group-block')).toBeInTheDocument();
+ expect(screen.getByText('Brief')).toBeInTheDocument();
+ expect(screen.getByText('Brief item')).toBeInTheDocument();
+ expect(screen.getByText('View all tasks')).toBeInTheDocument();
+ });
+});
diff --git a/src/features/DailyBrief/index.tsx b/src/features/DailyBrief/index.tsx
index e3e4a0ca225..ae59312f2cc 100644
--- a/src/features/DailyBrief/index.tsx
+++ b/src/features/DailyBrief/index.tsx
@@ -41,21 +41,19 @@ const DailyBrief = memo(() => {
);
}
- if (briefs.length === 0 && !recommendationsVisible) return null;
-
- const showViewAllTasks = briefs.length > 0 || recommendationsVisible;
+ if (briefs.length === 0) {
+ return recommendationsVisible ? <Recommendations /> : null;
+ }
return (
<GroupBlock
- actionAlwaysVisible={showViewAllTasks}
+ actionAlwaysVisible
icon={Newspaper}
title={t('brief.title')}
action={
- showViewAllTasks ? (
- <Button size={'small'} type={'text'} onClick={() => navigate('/tasks')}>
- {t('brief.viewAllTasks')}
- </Button>
- ) : undefined
+ <Button size={'small'} type={'text'} onClick={() => navigate('/tasks')}>
+ {t('brief.viewAllTasks')}
+ </Button>
}
>
<Flexbox gap={12}>
diff --git a/src/features/Recommendations/index.tsx b/src/features/Recommendations/index.tsx
index 3290dd0ca0f..5e9df45ac11 100644
--- a/src/features/Recommendations/index.tsx
+++ b/src/features/Recommendations/index.tsx
@@ -1,5 +1,4 @@
-import { Flexbox, Icon, Text } from '@lobehub/ui';
-import { cssVar } from 'antd-style';
+import { Button, Flexbox, Text } from '@lobehub/ui';
import { RefreshCw } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
@@ -39,16 +38,14 @@ const Recommendations = memo(() => {
{t('recommendations.subtitle')}
</Text>
{taskTemplatesState.mode === 'cards' && (
- <Flexbox
- horizontal
- align={'center'}
- gap={4}
- style={{ color: cssVar.colorTextDescription, cursor: 'pointer' }}
+ <Button
+ icon={<RefreshCw size={12} />}
+ size={'small'}
+ type={'text'}
onClick={taskTemplatesState.onRefresh}
>
- <Icon icon={RefreshCw} size={12} />
- <Text fontSize={12}>{tTaskTemplate('action.refresh.button')}</Text>
- </Flexbox>
+ {tTaskTemplate('action.refresh.button')}
+ </Button>
)}
</Flexbox>
<Flexbox gap={8}>