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(home): refine dashboard layout and rail (#17756)

Inneid5eeb8e5f01d
diff --git a/e2e/src/features/home/layout.feature b/e2e/src/features/home/layout.feature
index 6393a623fc0..7ff38d06a52 100644
--- a/e2e/src/features/home/layout.feature
+++ b/e2e/src/features/home/layout.feature
@@ -1,11 +1,13 @@
@journey @home @layout @regression
-Feature: Home Dashboard 右栏布局
- 作为桌面端用户,我希望窗口变窄时右栏卡片、滚动条与页面边缘仍保持清晰分隔
+Feature: Home Dashboard 双列布局
+ 作为桌面端用户,我希望主列与右栏的滚动条始终位于各自的独立间距内
Background:
Given 用户已登录系统
@HOME-LAYOUT-RAIL-001 @P1
- Scenario: 受限桌面宽度下滚动条位于卡片外侧且保留页面右边距
+ Scenario: 受限桌面宽度下双列滚动条不覆盖内容
Given 用户在受限宽度下打开 Home 页面
- Then Home 右栏应保持卡片、滚动条轨道与页面边缘的分层间距
+ Then Home 主列滚动条应位于双列间距中央
+ And Home 右栏折叠控制应贴合双列边界
+ And Home 右栏应保持卡片、滚动条轨道与页面边缘的分层间距
diff --git a/e2e/src/steps/home/layout.steps.ts b/e2e/src/steps/home/layout.steps.ts
index d56ebc79985..ffa7cc99e56 100644
--- a/e2e/src/steps/home/layout.steps.ts
+++ b/e2e/src/steps/home/layout.steps.ts
@@ -15,6 +15,60 @@ Given('用户在受限宽度下打开 Home 页面', async function (this: Custom
});
});
+Then('Home 主列滚动条应位于双列间距中央', async function (this: CustomWorld) {
+ const main = this.page.locator('[data-testid="home-main"]:visible');
+ const rail = this.page.locator('[data-testid="home-rail"]:visible');
+ const scrollbar = main.locator('[data-orientation="vertical"]').first();
+
+ const [mainBox, railBox, scrollbarBox] = await Promise.all([
+ main.boundingBox(),
+ rail.boundingBox(),
+ scrollbar.boundingBox(),
+ ]);
+
+ expect(mainBox).not.toBeNull();
+ expect(railBox).not.toBeNull();
+ expect(scrollbarBox).not.toBeNull();
+
+ const mainRight = mainBox!.x + mainBox!.width;
+ const railLeft = railBox!.x;
+ const scrollbarCenter = scrollbarBox!.x + scrollbarBox!.width / 2;
+ const columnGapCenter = mainRight + (railLeft - mainRight) / 2;
+
+ expect(scrollbarBox!.x).toBeGreaterThanOrEqual(mainRight);
+ expect(scrollbarBox!.x + scrollbarBox!.width).toBeLessThanOrEqual(railLeft);
+ expect(scrollbarCenter).toBeCloseTo(columnGapCenter, 0);
+});
+
+Then('Home 右栏折叠控制应贴合双列边界', async function (this: CustomWorld) {
+ const main = this.page.locator('[data-testid="home-main"]:visible');
+ const rail = this.page.locator('[data-testid="home-rail"]:visible');
+ const desktopToggle = this.page.getByTestId('home-rail-toggle-desktop');
+ const mobileToggle = this.page.getByTestId('home-rail-toggle-mobile');
+
+ await expect(desktopToggle).toBeVisible({ timeout: WAIT_TIMEOUT });
+ await expect(mobileToggle).toBeHidden();
+
+ const [mainBox, railBox, toggleBox] = await Promise.all([
+ main.boundingBox(),
+ rail.boundingBox(),
+ desktopToggle.boundingBox(),
+ ]);
+
+ expect(mainBox).not.toBeNull();
+ expect(railBox).not.toBeNull();
+ expect(toggleBox).not.toBeNull();
+
+ const mainRight = mainBox!.x + mainBox!.width;
+ const railLeft = railBox!.x;
+ const toggleCenter = toggleBox!.x + toggleBox!.width / 2;
+ const columnGapCenter = mainRight + (railLeft - mainRight) / 2;
+
+ expect(toggleBox!.x).toBeGreaterThanOrEqual(mainRight);
+ expect(toggleBox!.x + toggleBox!.width).toBeLessThanOrEqual(railLeft);
+ expect(toggleCenter).toBeCloseTo(columnGapCenter, 0);
+});
+
Then('Home 右栏应保持卡片、滚动条轨道与页面边缘的分层间距', async function (this: CustomWorld) {
const rail = this.page.locator('[data-testid="home-rail"]:visible');
const card = rail.getByTestId('home-rail-card').first();
diff --git a/locales/en-US/home.json b/locales/en-US/home.json
index b58a17f3924..a75c3b6dd69 100644
--- a/locales/en-US/home.json
+++ b/locales/en-US/home.json
@@ -63,14 +63,17 @@
"dashboard.greeting.morning": "Good morning, {{name}}.",
"dashboard.greeting.morningGuest": "Good morning.",
"dashboard.greeting.subtitle": "What would you like to work on?",
- "dashboard.mode.chat": "Chat",
+ "dashboard.mode.chat": "Agent",
"dashboard.mode.task": "Task",
+ "dashboard.modeDesc.task": "Create a task, start it now, and track its progress",
"dashboard.placeholder.chat": "Ask, create, or start a task",
"dashboard.placeholder.task": "Describe a task to start right away",
+ "dashboard.rail.hide": "Hide activity",
+ "dashboard.rail.show": "Show activity",
"dashboard.submitFailed": "Could not submit. Your draft has been kept.",
"dashboard.task.empty": "No tasks yet",
"dashboard.task.title": "Tasks",
- "dashboard.task.unsupportedContext": "Task mode does not support attachments or selected context yet. Remove them or switch to Chat; your draft has been kept.",
+ "dashboard.task.unsupportedContext": "Task mode does not support attachments or selected context yet. Remove them or switch to Agent mode; your draft has been kept.",
"homePromoBanner.cta": "Try now",
"homePromoBanner.dismiss": "Dismiss",
"homePromoBanner.label": "{{model}} is now available",
diff --git a/locales/zh-CN/home.json b/locales/zh-CN/home.json
index 4917a70923c..ad95254abec 100644
--- a/locales/zh-CN/home.json
+++ b/locales/zh-CN/home.json
@@ -63,14 +63,17 @@
"dashboard.greeting.morning": "早上好,{{name}}。",
"dashboard.greeting.morningGuest": "早上好。",
"dashboard.greeting.subtitle": "你想处理什么?",
- "dashboard.mode.chat": "对话",
+ "dashboard.mode.chat": "Agent",
"dashboard.mode.task": "任务",
+ "dashboard.modeDesc.task": "创建任务并立即执行,持续跟踪进度",
"dashboard.placeholder.chat": "提问、创建内容或启动任务",
"dashboard.placeholder.task": "描述要立即开始的任务",
+ "dashboard.rail.hide": "隐藏动态",
+ "dashboard.rail.show": "显示动态",
"dashboard.submitFailed": "提交失败,草稿已保留。",
"dashboard.task.empty": "暂无任务",
"dashboard.task.title": "任务",
- "dashboard.task.unsupportedContext": "任务模式暂不支持附件或已选上下文。请移除它们或切换到对话模式;草稿已保留。",
+ "dashboard.task.unsupportedContext": "任务模式暂不支持附件或已选上下文。请移除它们或切换到 Agent 模式;草稿已保留。",
"homePromoBanner.cta": "立即体验",
"homePromoBanner.dismiss": "关闭",
"homePromoBanner.label": "{{model}} 现已上线",
diff --git a/packages/locales/src/default/home.ts b/packages/locales/src/default/home.ts
index d45c8e36a99..61363ae8907 100644
--- a/packages/locales/src/default/home.ts
+++ b/packages/locales/src/default/home.ts
@@ -69,15 +69,18 @@ export default {
'dashboard.greeting.morning': 'Good morning, {{name}}.',
'dashboard.greeting.morningGuest': 'Good morning.',
'dashboard.greeting.subtitle': 'What would you like to work on?',
- 'dashboard.mode.chat': 'Chat',
+ 'dashboard.mode.chat': 'Agent',
'dashboard.mode.task': 'Task',
+ 'dashboard.modeDesc.task': 'Create a task, start it now, and track its progress',
'dashboard.placeholder.chat': 'Ask, create, or start a task',
'dashboard.placeholder.task': 'Describe a task to start right away',
+ 'dashboard.rail.hide': 'Hide activity',
+ 'dashboard.rail.show': 'Show activity',
'dashboard.submitFailed': 'Could not submit. Your draft has been kept.',
'dashboard.task.empty': 'No tasks yet',
'dashboard.task.title': 'Tasks',
'dashboard.task.unsupportedContext':
- 'Task mode does not support attachments or selected context yet. Remove them or switch to Chat; your draft has been kept.',
+ 'Task mode does not support attachments or selected context yet. Remove them or switch to Agent mode; your draft has been kept.',
'inbox.author.scheduled': 'Scheduled',
'inbox.error.title': 'Run failed',
'inbox.needsYou.title': 'Needs you',
diff --git a/packages/utils/src/localStorage.ts b/packages/utils/src/localStorage.ts
index b6698a12188..7b846cce7ab 100644
--- a/packages/utils/src/localStorage.ts
+++ b/packages/utils/src/localStorage.ts
@@ -32,7 +32,17 @@ export class AsyncLocalStorage<State> {
localStorage.setItem(this.storageKey, JSON.stringify({ ...data, ...state }));
}
+ getFromLocalStorageSync(key: StorageKey = this.storageKey): State {
+ if (typeof localStorage === 'undefined') return {} as State;
+
+ try {
+ return JSON.parse(localStorage.getItem(key) || '{}');
+ } catch {
+ return {} as State;
+ }
+ }
+
async getFromLocalStorage(key: StorageKey = this.storageKey): Promise<State> {
- return JSON.parse(localStorage.getItem(key) || '{}');
+ return this.getFromLocalStorageSync(key);
}
}
diff --git a/src/features/Home/HomeHeader.tsx b/src/features/Home/HomeHeader.tsx
index 62cc38ec9f2..82b81fe7592 100644
--- a/src/features/Home/HomeHeader.tsx
+++ b/src/features/Home/HomeHeader.tsx
@@ -10,6 +10,7 @@ import { authSelectors, userProfileSelectors } from '@/store/user/slices/auth/se
import AgentSelect from './AgentSelect';
import GreetingLine from './GreetingLine';
+import RailToggle from './RailToggle';
import { parseGreetingLine } from './welcomeText';
const styles = createStaticStyles(({ css }) => ({
@@ -36,6 +37,13 @@ const styles = createStaticStyles(({ css }) => ({
display: none;
}
`,
+ railToggle: css`
+ display: none;
+
+ @media (width <= 1100px) {
+ display: block;
+ }
+ `,
toolbar: css`
container-type: inline-size;
width: 100%;
@@ -53,7 +61,12 @@ const getGreetingKey = (hour: number): 'afternoon' | 'evening' | 'morning' => {
/** CJK greetings already end on a full-width stop, which carries its own trailing space. */
const greetingSeparator = (greeting: string) => (/[。!?]$/.test(greeting) ? '' : ' ');
-const HomeHeader = memo(() => {
+interface HomeHeaderProps {
+ onToggleRail?: () => void;
+ railVisible: boolean;
+}
+
+const HomeHeader = memo<HomeHeaderProps>(({ onToggleRail, railVisible }) => {
const { t } = useTranslation('home');
const displayName = useUserStore(userProfileSelectors.displayUserName);
const isLogin = useUserStore(authSelectors.isLogin);
@@ -67,7 +80,6 @@ const HomeHeader = memo(() => {
// Falls back to the static line until the daily brief lands — or forever, for
// an account the generator has not run for yet.
const parsed = currentPair?.welcome ? parseGreetingLine(currentPair.welcome) : undefined;
-
return (
<Flexbox gap={16} justify={'center'}>
<Flexbox
@@ -78,9 +90,20 @@ const HomeHeader = memo(() => {
justify={'space-between'}
>
<AgentSelect />
- <div className={styles.promo}>
- <HomePromoBanner />
- </div>
+ <Flexbox horizontal align={'center'} flex={'none'} gap={4}>
+ <div className={styles.promo}>
+ <HomePromoBanner />
+ </div>
+ {isLogin && onToggleRail && (
+ <div className={styles.railToggle}>
+ <RailToggle
+ railVisible={railVisible}
+ testId={'home-rail-toggle-mobile'}
+ onToggle={onToggleRail}
+ />
+ </div>
+ )}
+ </Flexbox>
</Flexbox>
<Text as={'h1'} className={styles.greeting} weight={600}>
{greeting}
diff --git a/src/features/Home/InputArea/ModeSelect.tsx b/src/features/Home/InputArea/ModeSelect.tsx
index ef870a949db..fa57c9437cb 100644
--- a/src/features/Home/InputArea/ModeSelect.tsx
+++ b/src/features/Home/InputArea/ModeSelect.tsx
@@ -94,13 +94,9 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
`,
}));
-/**
- * The two modes are the runtime's existing chat / agent split, so they borrow
- * that copy rather than restating it.
- */
const MODES = [
- { descKey: 'chatMode.chatDesc', icon: MessageCircleIcon, key: 'chat' },
- { descKey: 'chatMode.agentDesc', icon: InfinityIcon, key: 'task' },
+ { icon: MessageCircleIcon, key: 'chat' },
+ { icon: InfinityIcon, key: 'task' },
] as const;
interface ModeSelectProps {
@@ -132,7 +128,7 @@ const ModeSelect = memo<ModeSelectProps>(({ onChange, value }) => {
const content = (
<Flexbox gap={4} role={'menu'} style={{ maxWidth: 320, minWidth: 280 }}>
- {MODES.map(({ descKey, icon, key }) => {
+ {MODES.map(({ icon, key }) => {
const disabled = isHomeModeDisabled(key, canCreateContent);
return (
@@ -158,7 +154,9 @@ const ModeSelect = memo<ModeSelectProps>(({ onChange, value }) => {
</Flexbox>
<Flexbox className={styles.optionText} flex={1}>
<div className={styles.optionTitle}>{t(`dashboard.mode.${key}`)}</div>
- <div className={styles.optionDesc}>{tChat(descKey)}</div>
+ <div className={styles.optionDesc}>
+ {key === 'chat' ? tChat('chatMode.agentDesc') : t('dashboard.modeDesc.task')}
+ </div>
</Flexbox>
</Flexbox>
</Button>
diff --git a/src/features/Home/RailToggle.tsx b/src/features/Home/RailToggle.tsx
new file mode 100644
index 00000000000..372b273ff15
--- /dev/null
+++ b/src/features/Home/RailToggle.tsx
@@ -0,0 +1,84 @@
+import { ActionIcon } from '@lobehub/ui';
+import { createStaticStyles, cx } from 'antd-style';
+import {
+ ChevronLeftIcon,
+ ChevronRightIcon,
+ PanelRightCloseIcon,
+ PanelRightOpenIcon,
+} from 'lucide-react';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ edge: css`
+ color: ${cssVar.colorTextQuaternary};
+ opacity: 0.56;
+ background: ${cssVar.colorFillQuaternary};
+ transition:
+ color ${cssVar.motionDurationFast} ${cssVar.motionEaseOut},
+ background ${cssVar.motionDurationFast} ${cssVar.motionEaseOut},
+ opacity ${cssVar.motionDurationFast} ${cssVar.motionEaseOut};
+
+ &[aria-expanded='false'] {
+ opacity: 0.8;
+ }
+
+ &:hover,
+ &:focus-visible {
+ color: ${cssVar.colorTextSecondary};
+ opacity: 1;
+ background: ${cssVar.colorFillSecondary};
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+ `,
+ root: css`
+ &:dir(rtl) svg {
+ transform: scaleX(-1);
+ }
+ `,
+}));
+
+const EDGE_SIZE = { blockSize: 40, borderRadius: 999, size: 14, strokeWidth: 2 } as const;
+const EDGE_STYLE = { width: 18 } as const;
+
+interface RailToggleProps {
+ edge?: boolean;
+ onToggle: () => void;
+ railVisible: boolean;
+ testId: string;
+}
+
+const RailToggle = memo<RailToggleProps>(({ edge, onToggle, railVisible, testId }) => {
+ const { t } = useTranslation('home');
+ const label = railVisible ? t('dashboard.rail.hide') : t('dashboard.rail.show');
+ const icon = edge
+ ? railVisible
+ ? ChevronRightIcon
+ : ChevronLeftIcon
+ : railVisible
+ ? PanelRightCloseIcon
+ : PanelRightOpenIcon;
+
+ return (
+ <ActionIcon
+ aria-controls={'home-rail'}
+ aria-expanded={railVisible}
+ aria-label={label}
+ className={cx(styles.root, edge && styles.edge)}
+ data-testid={testId}
+ icon={icon}
+ size={edge ? EDGE_SIZE : 'small'}
+ style={edge ? EDGE_STYLE : undefined}
+ title={label}
+ variant={'borderless'}
+ onClick={onToggle}
+ />
+ );
+});
+
+RailToggle.displayName = 'RailToggle';
+
+export default RailToggle;
diff --git a/src/features/Home/index.tsx b/src/features/Home/index.tsx
index f03af32aca9..1ca1946c546 100644
--- a/src/features/Home/index.tsx
+++ b/src/features/Home/index.tsx
@@ -2,11 +2,13 @@
import { Flexbox } from '@lobehub/ui';
import { ScrollArea } from '@lobehub/ui/base-ui';
-import { createStaticStyles } from 'antd-style';
+import { createStaticStyles, cx } from 'antd-style';
import { memo, useCallback, useState } from 'react';
import HomeInbox from '@/features/HomeInbox';
import { useChatStore } from '@/store/chat';
+import { useGlobalStore } from '@/store/global';
+import { systemStatusSelectors } from '@/store/global/selectors';
import { useUserStore } from '@/store/user';
import { authSelectors } from '@/store/user/slices/auth/selectors';
@@ -14,6 +16,7 @@ import HomeHeader from './HomeHeader';
import HomeModeContent from './HomeModeContent';
import HomePortrait from './HomePortrait';
import InputArea from './InputArea';
+import RailToggle from './RailToggle';
import type { HomeMode } from './types';
/** Mirrors the row hover bleed in HomeModeContent; the viewport would clip it. */
@@ -31,10 +34,15 @@ const scrollContent = {
/** Gutter the rail's scrollbar lives in, so it never sits over a card. */
const RAIL_GUTTER = 14;
const RAIL_CARD_WIDTH = 380;
+const RAIL_COLUMN_GAP = 28;
+/** Keep the main scrollbar off the content edge and centered in the column gap. */
+const MAIN_SCROLLBAR_OFFSET = RAIL_COLUMN_GAP / 2;
+const RAIL_EXIT_OFFSET = 24;
+const RAIL_TRANSITION_DURATION = 220;
+const COLLAPSED_CONTENT_OFFSET = (RAIL_CARD_WIDTH + RAIL_GUTTER + RAIL_COLUMN_GAP) / 2;
const MAIN_CONTENT_STYLE = { ...scrollContent, paddingInline: ROW_BLEED };
const RAIL_CONTENT_STYLE = { ...scrollContent, paddingInlineEnd: RAIL_GUTTER };
-const SINGLE_COLUMN_STYLE = { gridTemplateColumns: 'minmax(0, 1fr)' } as const;
const styles = createStaticStyles(({ css }) => ({
// Row 1 (greeting + portrait) is fixed; row 2 gives each column its own
@@ -44,7 +52,7 @@ const styles = createStaticStyles(({ css }) => ({
grid-template-columns: minmax(0, 1fr) ${RAIL_CARD_WIDTH + RAIL_GUTTER}px;
grid-template-rows: auto minmax(0, 1fr);
flex: 1;
- gap: 24px 28px;
+ gap: 24px ${RAIL_COLUMN_GAP}px;
width: 100%;
min-height: 0;
@@ -55,14 +63,46 @@ const styles = createStaticStyles(({ css }) => ({
grid-template-rows: auto auto auto;
}
`,
+ content: css`
+ transition: transform ${RAIL_TRANSITION_DURATION}ms ease-out;
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+ `,
+ contentCentered: css`
+ @media (width > 1100px) {
+ transform: translateX(${COLLAPSED_CONTENT_OFFSET}px);
+
+ &:dir(rtl) {
+ transform: translateX(-${COLLAPSED_CONTENT_OFFSET}px);
+ }
+ }
+ `,
header: css`
grid-area: 1 / 1;
`,
+ inputArea: css`
+ position: relative;
+ min-width: 0;
+ `,
main: css`
+ position: relative;
grid-area: 2 / 1;
min-width: 0;
min-height: 0;
`,
+ railToggle: css`
+ position: absolute;
+ z-index: 3;
+ inset-block-start: 50%;
+ inset-inline-end: -23px;
+ transform: translateY(-50%);
+
+ @media (width <= 1100px) {
+ display: none;
+ }
+ `,
mainScroll: css`
flex: 1;
min-height: 0;
@@ -72,6 +112,15 @@ const styles = createStaticStyles(({ css }) => ({
flex: none;
}
`,
+ mainScrollbar: css`
+ @media (width > 1100px) {
+ transform: translateX(${MAIN_SCROLLBAR_OFFSET}px);
+
+ &:dir(rtl) {
+ transform: translateX(-${MAIN_SCROLLBAR_OFFSET}px);
+ }
+ }
+ `,
portrait: css`
grid-area: 1 / 2;
@@ -79,6 +128,40 @@ const styles = createStaticStyles(({ css }) => ({
display: none;
}
`,
+ railSurface: css`
+ transform: translateX(0);
+ visibility: visible;
+ opacity: 1;
+ transition:
+ opacity ${RAIL_TRANSITION_DURATION}ms ease-out,
+ transform ${RAIL_TRANSITION_DURATION}ms ease-out,
+ visibility 0s linear;
+
+ &[data-collapsed='true'] {
+ pointer-events: none;
+
+ transform: translateX(${RAIL_EXIT_OFFSET}px);
+
+ visibility: hidden;
+ opacity: 0;
+
+ transition-delay: 0s, 0s, ${RAIL_TRANSITION_DURATION}ms;
+
+ &:dir(rtl) {
+ transform: translateX(-${RAIL_EXIT_OFFSET}px);
+ }
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+
+ @media (width <= 1100px) {
+ &[data-collapsed='true'] {
+ display: none;
+ }
+ }
+ `,
// Above the portrait so the agent stands behind the glass, not on top of it.
rail: css`
position: relative;
@@ -110,8 +193,15 @@ const styles = createStaticStyles(({ css }) => ({
const Home = memo(() => {
const isLogin = useUserStore(authSelectors.isLogin);
+ const [showHomeRail, toggleHomeRail, isStatusInit] = useGlobalStore((s) => [
+ systemStatusSelectors.showHomeRail(s),
+ s.toggleHomeRail,
+ systemStatusSelectors.isStatusInit(s),
+ ]);
const [mode, setMode] = useState<HomeMode>('chat');
const [inputValue, setInputValue] = useState('');
+ const railVisible = Boolean(isLogin && showHomeRail);
+ const railCollapsed = !railVisible;
const handleInputValueChange = useCallback((value: string) => {
setInputValue(value);
@@ -130,36 +220,67 @@ const Home = memo(() => {
);
return (
- <Flexbox className={styles.grid} style={isLogin ? undefined : SINGLE_COLUMN_STYLE}>
- <div className={styles.header}>
- <HomeHeader />
+ <Flexbox className={styles.grid}>
+ <div className={cx(styles.header, styles.content, railCollapsed && styles.contentCentered)}>
+ <HomeHeader
+ railVisible={railVisible}
+ onToggleRail={isStatusInit ? toggleHomeRail : undefined}
+ />
</div>
{isLogin && (
- <div className={styles.portrait}>
+ <div
+ aria-hidden={railCollapsed}
+ className={cx(styles.portrait, styles.railSurface)}
+ data-collapsed={railCollapsed}
+ >
<HomePortrait />
</div>
)}
- <Flexbox className={styles.main} gap={24}>
- <InputArea
- inputValue={inputValue}
- mode={mode}
- onInputValueChange={handleInputValueChange}
- onModeChange={setMode}
- />
+ <Flexbox
+ className={cx(styles.main, styles.content, railCollapsed && styles.contentCentered)}
+ data-testid={'home-main'}
+ gap={24}
+ >
+ <div className={styles.inputArea}>
+ {isLogin && isStatusInit && (
+ <div className={styles.railToggle}>
+ <RailToggle
+ edge
+ railVisible={railVisible}
+ testId={'home-rail-toggle-desktop'}
+ onToggle={toggleHomeRail}
+ />
+ </div>
+ )}
+ <InputArea
+ inputValue={inputValue}
+ mode={mode}
+ onInputValueChange={handleInputValueChange}
+ onModeChange={setMode}
+ />
+ </div>
<ScrollArea
disableContentFit
scrollFade
className={styles.mainScroll}
contentProps={{ style: MAIN_CONTENT_STYLE }}
+ scrollbarProps={{ className: styles.mainScrollbar }}
>
<HomeModeContent mode={mode} onSuggestionSelect={handleSuggestionSelect} />
</ScrollArea>
</Flexbox>
{isLogin && (
- <aside className={styles.rail} data-testid={'home-rail'}>
+ <aside
+ aria-hidden={railCollapsed}
+ className={cx(styles.rail, styles.railSurface)}
+ data-collapsed={railCollapsed}
+ data-testid={'home-rail'}
+ id={'home-rail'}
+ inert={railCollapsed}
+ >
{/* No scrollFade: its mask would make the viewport a backdrop root
and the cards' glass would stop sampling the portrait behind it. */}
<ScrollArea
diff --git a/src/store/chat/agents/__tests__/clientRuntimeExecutors/call-tool.test.ts b/src/store/chat/agents/__tests__/clientRuntimeExecutors/call-tool.test.ts
index bd1b30d5355..933286ccfd4 100644
--- a/src/store/chat/agents/__tests__/clientRuntimeExecutors/call-tool.test.ts
+++ b/src/store/chat/agents/__tests__/clientRuntimeExecutors/call-tool.test.ts
@@ -17,6 +17,10 @@ import {
vi.mock('@/utils/localStorage', () => {
class AsyncLocalStorage<State> {
+ getFromLocalStorageSync(): State {
+ return {} as State;
+ }
+
async getFromLocalStorage(): Promise<State> {
return {} as State;
}
diff --git a/src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts
index eda1a9d4f9a..5ab36f9716a 100644
--- a/src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/conversationControl.test.ts
@@ -33,6 +33,10 @@ vi.mock('@/services/agentRuntime', () => ({
vi.mock('@/utils/localStorage', () => {
class AsyncLocalStorage<State> {
+ getFromLocalStorageSync(): State {
+ return {} as State;
+ }
+
async getFromLocalStorage(): Promise<State> {
return {} as State;
}
diff --git a/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts b/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
index 6eb89a788d3..f5c60551210 100644
--- a/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
+++ b/src/store/chat/slices/agentRun/actions/__tests__/streamingExecutor.test.ts
@@ -32,6 +32,10 @@ const agentSignalBridgeMock = vi.hoisted(() => ({
vi.mock('@/utils/localStorage', () => {
class AsyncLocalStorage<State> {
+ getFromLocalStorageSync(): State {
+ return {} as State;
+ }
+
async getFromLocalStorage(): Promise<State> {
return {} as State;
}
diff --git a/src/store/chat/slices/plugin/action.test.ts b/src/store/chat/slices/plugin/action.test.ts
index e662e46e63a..96997db9a7a 100644
--- a/src/store/chat/slices/plugin/action.test.ts
+++ b/src/store/chat/slices/plugin/action.test.ts
@@ -17,6 +17,10 @@ import { useToolStore } from '@/store/tool';
vi.mock('@/utils/localStorage', () => {
class AsyncLocalStorage<State> {
+ getFromLocalStorageSync(): State {
+ return {} as State;
+ }
+
async getFromLocalStorage(): Promise<State> {
return {} as State;
}
diff --git a/src/store/global/action.test.ts b/src/store/global/action.test.ts
index dcc39daf7fd..3f8a0e7ab32 100644
--- a/src/store/global/action.test.ts
+++ b/src/store/global/action.test.ts
@@ -6,7 +6,7 @@ import * as activeWorkspaceModule from '@/business/client/hooks/useActiveWorkspa
import { CURRENT_VERSION } from '@/const/version';
import { globalService } from '@/services/global';
import { useGlobalStore } from '@/store/global/index';
-import { initialState } from '@/store/global/initialState';
+import { createInitialSystemStatus, initialState } from '@/store/global/initialState';
import { withSWR } from '~test-utils';
vi.mock('zustand/traditional');
@@ -32,6 +32,41 @@ afterEach(() => {
});
describe('createPreferenceSlice', () => {
+ describe('toggleHomeRail', () => {
+ it('should persist the Home rail visibility for the next page startup', async () => {
+ const previousStatus = localStorage.getItem('LOBE_SYSTEM_STATUS');
+ localStorage.removeItem('LOBE_SYSTEM_STATUS');
+ const { result } = renderHook(() => useGlobalStore());
+
+ try {
+ act(() => {
+ useGlobalStore.setState({
+ isStatusInit: true,
+ status: { ...initialState.status, showHomeRail: true },
+ });
+ result.current.toggleHomeRail();
+ });
+
+ expect(result.current.status.showHomeRail).toBe(false);
+ await waitFor(() => {
+ expect(createInitialSystemStatus().showHomeRail).toBe(false);
+ });
+
+ act(() => {
+ result.current.toggleHomeRail(true);
+ });
+
+ expect(result.current.status.showHomeRail).toBe(true);
+ await waitFor(() => {
+ expect(createInitialSystemStatus().showHomeRail).toBe(true);
+ });
+ } finally {
+ if (previousStatus === null) localStorage.removeItem('LOBE_SYSTEM_STATUS');
+ else localStorage.setItem('LOBE_SYSTEM_STATUS', previousStatus);
+ }
+ });
+ });
+
describe('toggleRightPanel', () => {
it('should toggle chat sidebar', () => {
const { result } = renderHook(() => useGlobalStore());
diff --git a/src/store/global/actions/workspacePane.ts b/src/store/global/actions/workspacePane.ts
index 763f8eea48d..0fe152ef0e9 100644
--- a/src/store/global/actions/workspacePane.ts
+++ b/src/store/global/actions/workspacePane.ts
@@ -98,6 +98,13 @@ export class GlobalWorkspacePaneActionImpl {
);
};
+ toggleHomeRail = (newValue?: boolean): void => {
+ const currentValue = this.#get().status.showHomeRail ?? true;
+ const showHomeRail = typeof newValue === 'boolean' ? newValue : !currentValue;
+
+ this.#get().updateSystemStatus({ showHomeRail }, n('toggleHomeRail', newValue));
+ };
+
togglePageAgentPanel = (newValue?: boolean): void => {
const showPageAgentPanel =
typeof newValue === 'boolean' ? newValue : !this.#get().status.showPageAgentPanel;
diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.ts
index 5c27847b75c..03396ab76bb 100644
--- a/src/store/global/initialState.ts
+++ b/src/store/global/initialState.ts
@@ -278,6 +278,11 @@ export interface SystemStatus {
showAgentBuilderPanel?: boolean;
showCommandMenu?: boolean;
showFilePanel?: boolean;
+ /**
+ * Visibility of the Home dashboard's activity and recommendations rail.
+ * Independent from `showRightPanel` so Home preferences do not affect chat pages.
+ */
+ showHomeRail?: boolean;
showHotkeyHelper?: boolean;
showImagePanel?: boolean;
showImageTopicPanel?: boolean;
@@ -507,6 +512,7 @@ export const INITIAL_STATUS = {
showCommandMenu: false,
showFilePanel: true,
showHotkeyHelper: false,
+ showHomeRail: true,
showImagePanel: true,
showImageTopicPanel: true,
showAgentBuilderPanel: false,
@@ -531,12 +537,32 @@ export const INITIAL_STATUS = {
workingSidebarWidth: 360,
} satisfies SystemStatus;
+const statusStorage = new AsyncLocalStorage<SystemStatus>('LOBE_SYSTEM_STATUS');
+
+/**
+ * Restore the Home rail before React's first render. The remaining system
+ * status still follows the existing async initialization path, but this
+ * layout-affecting preference must not briefly render its default value after
+ * a page reload.
+ */
+export const createInitialSystemStatus = (): SystemStatus => {
+ const persistedStatus = statusStorage.getFromLocalStorageSync();
+
+ return {
+ ...INITIAL_STATUS,
+ showHomeRail:
+ typeof persistedStatus.showHomeRail === 'boolean'
+ ? persistedStatus.showHomeRail
+ : INITIAL_STATUS.showHomeRail,
+ };
+};
+
export const initialState: GlobalState = {
initClientDBStage: DatabaseLoadingState.Idle,
isMobile: false,
isStatusInit: false,
navigationRef: createNavigationRef(),
sidebarKey: SidebarTabKey.Chat,
- status: INITIAL_STATUS,
- statusStorage: new AsyncLocalStorage('LOBE_SYSTEM_STATUS'),
+ status: createInitialSystemStatus(),
+ statusStorage,
};
diff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.ts
index dfc06282d6d..51615f28ca9 100644
--- a/src/store/global/selectors/systemStatus.ts
+++ b/src/store/global/selectors/systemStatus.ts
@@ -367,6 +367,7 @@ const showSystemRole = (s: GlobalState) => s.status.showSystemRole;
const mobileShowTopic = (s: GlobalState) => s.status.mobileShowTopic;
const mobileShowPortal = (s: GlobalState) => s.status.mobileShowPortal;
const showAgentBuilderPanel = (s: GlobalState) => s.status.showAgentBuilderPanel;
+const showHomeRail = (s: GlobalState) => s.status.showHomeRail ?? true;
const showRightPanel = (s: GlobalState) => s.status.showRightPanel;
const showLeftPanel = (s: GlobalState) => s.status.showLeftPanel;
const showPageAgentPanel = (s: GlobalState) => s.status.showPageAgentPanel;
@@ -486,6 +487,7 @@ export const systemStatusSelectors = {
sessionGroupKeys,
showAgentBuilderPanel,
showFilePanel,
+ showHomeRail,
showImagePanel,
showImageTopicPanel,
showLeftPanel,