fix: polish compact workspace controls
This commit is contained in:
1 parent
eb61b332a2
commit
210cb5117f
13 files changed
+516
-274
No files matched your search
@@ -81,7 +81,7 @@
|
||||
* -d '{"retention_days": 0}'
|
||||
* ──────────────────────────────────────────────────────────────────────────
|
||||
*/
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||
import {
|
||||
ArrowLeft,
|
||||
History,
|
||||
@@ -113,6 +113,10 @@ import StudioNotebookDetailPage from '@/pages/StudioNotebookDetailPage';
|
||||
import StudioNotebooksPage from '@/pages/StudioNotebooksPage';
|
||||
import AgentChatPage from '@/pages/AgentChatPage';
|
||||
import { ChatRuntime } from '@/pages/WorkspaceRoutes';
|
||||
import {
|
||||
LayoutModeSwitcher,
|
||||
ThemeSwitcher,
|
||||
} from '@/components/workspace/appearance-controls';
|
||||
import {
|
||||
AgentModuleSidebar,
|
||||
useAgentModuleSidebarData,
|
||||
@@ -137,10 +141,20 @@ const WRITING_ID = 'aw-writing';
|
||||
const DRAFT_ID = 'aw-draft';
|
||||
const AI_WRITING_AGENT_MODULE_KEY = 'ai-writing';
|
||||
const AI_WRITING_AGENT_MODULE_TITLE = 'AI 写作智能体';
|
||||
const AI_WRITING_LAST_AGENT_KEY = `agent-module:${AI_WRITING_AGENT_MODULE_KEY}:last-agent`;
|
||||
|
||||
// Match the original canvas page proportions (chat=35, artifact=65)
|
||||
const DEFAULT_LAYOUT = { [WRITING_ID]: 35, [DRAFT_ID]: 65 };
|
||||
|
||||
function AIWritingCompactAppearanceActions() {
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<ThemeSwitcher tone="content" />
|
||||
<LayoutModeSwitcher tone="content" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function useAIWritingRouteBase() {
|
||||
const { pathname } = useLocation();
|
||||
return useMemo(() => {
|
||||
@@ -170,7 +184,15 @@ function useAIWritingAgentRouteState(base: string) {
|
||||
|
||||
function AIWritingAgentDefaultRedirect() {
|
||||
const { groups, isLoading } = useAgentModuleSidebarData(AI_WRITING_AGENT_MODULE_KEY);
|
||||
const firstAgent = groups.flatMap((group) => group.agents)[0];
|
||||
const agents = groups.flatMap((group) => group.agents);
|
||||
const lastAgentId = (() => {
|
||||
try {
|
||||
return sessionStorage.getItem(AI_WRITING_LAST_AGENT_KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
const targetAgent = agents.find((agent) => agent.id === lastAgentId) ?? agents[0];
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
@@ -180,7 +202,7 @@ function AIWritingAgentDefaultRedirect() {
|
||||
);
|
||||
}
|
||||
|
||||
if (!firstAgent) {
|
||||
if (!targetAgent) {
|
||||
return (
|
||||
<div className="flex size-full items-center justify-center px-6 text-center text-sm text-muted-foreground">
|
||||
暂无可用智能体,请先在模块设置中配置或创建智能体。
|
||||
@@ -188,24 +210,44 @@ function AIWritingAgentDefaultRedirect() {
|
||||
);
|
||||
}
|
||||
|
||||
return <Navigate to={`agents/${firstAgent.id}/chats/new`} replace />;
|
||||
return <Navigate to={`agents/${targetAgent.id}/chats/new`} replace />;
|
||||
}
|
||||
|
||||
function AIWritingAgentChatRoute() {
|
||||
function AIWritingAgentChatRoute({
|
||||
compactAppearanceActions,
|
||||
}: {
|
||||
compactAppearanceActions?: ReactNode;
|
||||
}) {
|
||||
const { agent_id } = useParams<{ agent_id: string }>();
|
||||
return (
|
||||
<ChatRuntime>
|
||||
<AgentChatPage key={agent_id} />
|
||||
<AgentChatPage
|
||||
key={agent_id}
|
||||
compactAppearanceActions={compactAppearanceActions}
|
||||
/>
|
||||
</ChatRuntime>
|
||||
);
|
||||
}
|
||||
|
||||
function AIWritingAgentRoutes({ base }: { base: string }) {
|
||||
function AIWritingAgentRoutes({
|
||||
base,
|
||||
compactAppearanceActions,
|
||||
}: {
|
||||
base: string;
|
||||
compactAppearanceActions?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<RouteBaseProvider value={base}>
|
||||
<Routes>
|
||||
<Route index element={<AIWritingAgentDefaultRedirect />} />
|
||||
<Route path="agents/:agent_id/chats/:thread_id" element={<AIWritingAgentChatRoute />} />
|
||||
<Route
|
||||
path="agents/:agent_id/chats/:thread_id"
|
||||
element={
|
||||
<AIWritingAgentChatRoute
|
||||
compactAppearanceActions={compactAppearanceActions}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</RouteBaseProvider>
|
||||
);
|
||||
@@ -220,11 +262,26 @@ interface NotebookProps {
|
||||
studioToken?: string;
|
||||
}
|
||||
|
||||
function WritingFormPanel({ hideAdvancedFields, initialNotebookId, initialDocumentIds, studioToken }: { hideAdvancedFields: boolean } & NotebookProps) {
|
||||
function WritingFormPanel({
|
||||
hideAdvancedFields,
|
||||
initialNotebookId,
|
||||
initialDocumentIds,
|
||||
studioToken,
|
||||
headerActionsBeforeCollapse,
|
||||
}: {
|
||||
hideAdvancedFields: boolean;
|
||||
headerActionsBeforeCollapse?: ReactNode;
|
||||
} & NotebookProps) {
|
||||
return (
|
||||
// 与原布局保持相同的 flex-1 min-h-0 包裹,确保内部 h-full 正确解析
|
||||
<div className="flex-1 min-h-0 overflow-hidden">
|
||||
<AIWritingPanel hideAdvancedFields={hideAdvancedFields} initialNotebookId={initialNotebookId} initialDocumentIds={initialDocumentIds} studioToken={studioToken} />
|
||||
<AIWritingPanel
|
||||
hideAdvancedFields={hideAdvancedFields}
|
||||
initialNotebookId={initialNotebookId}
|
||||
initialDocumentIds={initialDocumentIds}
|
||||
studioToken={studioToken}
|
||||
headerActionsBeforeCollapse={headerActionsBeforeCollapse}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -234,7 +291,16 @@ function WritingFormPanel({ hideAdvancedFields, initialNotebookId, initialDocume
|
||||
* - idle(初始问答阶段):左=「写作助手 Q&A」,右=「写作配置选项」表单;
|
||||
* - 开始写作后:回到原布局——左=写作配置/时间线面板,右=草稿预览。
|
||||
*/
|
||||
function AIWritingLayout({ hideAdvancedFields, initialNotebookId, initialDocumentIds, studioToken }: { hideAdvancedFields: boolean } & NotebookProps) {
|
||||
function AIWritingLayout({
|
||||
hideAdvancedFields,
|
||||
initialNotebookId,
|
||||
initialDocumentIds,
|
||||
studioToken,
|
||||
compactAppearanceActions,
|
||||
}: {
|
||||
hideAdvancedFields: boolean;
|
||||
compactAppearanceActions?: ReactNode;
|
||||
} & NotebookProps) {
|
||||
const layoutRef = useRef<GroupImperativeHandle>(null);
|
||||
const { state } = useAIWriting();
|
||||
const { isHistoryMode } = useAIWritingHistory();
|
||||
@@ -262,19 +328,28 @@ function AIWritingLayout({ hideAdvancedFields, initialNotebookId, initialDocumen
|
||||
formExpanded ? 'w-[36%] min-w-[340px] max-w-[600px] border-l' : 'w-0 min-w-0',
|
||||
)}
|
||||
>
|
||||
<WritingFormPanel hideAdvancedFields={hideAdvancedFields} initialNotebookId={initialNotebookId} initialDocumentIds={initialDocumentIds} studioToken={studioToken} />
|
||||
<WritingFormPanel
|
||||
hideAdvancedFields={hideAdvancedFields}
|
||||
initialNotebookId={initialNotebookId}
|
||||
initialDocumentIds={initialDocumentIds}
|
||||
studioToken={studioToken}
|
||||
headerActionsBeforeCollapse={compactAppearanceActions}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 收起态:右上角浮动展开图标按钮(与展开态头部的收起按钮位置呼应) */}
|
||||
{!formExpanded && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setFormExpanded(true)}
|
||||
title="展开写作配置"
|
||||
className="absolute right-3 top-2 z-10 flex h-7 w-7 items-center justify-center rounded-md border bg-background text-muted-foreground shadow-sm transition-colors hover:bg-muted hover:text-foreground"
|
||||
>
|
||||
<PanelRightOpen className="size-4" />
|
||||
</button>
|
||||
<div className="absolute right-3 top-2 z-10 flex items-center gap-1">
|
||||
{compactAppearanceActions}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setFormExpanded(true)}
|
||||
title="展开写作配置"
|
||||
className="flex h-7 w-7 items-center justify-center rounded-md border bg-background text-muted-foreground shadow-sm transition-colors hover:bg-muted hover:text-foreground"
|
||||
>
|
||||
<PanelRightOpen className="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
@@ -322,7 +397,16 @@ function AIWritingLayout({ hideAdvancedFields, initialNotebookId, initialDocumen
|
||||
* 写作页主体(侧栏 + 内容区)。放在 Provider 内部,以便读 useAIWriting 状态:
|
||||
* 进入写作(status !== idle 或查看历史)后自动收起左侧研究模板栏,让写作区更宽。
|
||||
*/
|
||||
function AIWritingBody({ hideAdvancedFields, initialNotebookId, initialDocumentIds, studioToken }: { hideAdvancedFields: boolean } & NotebookProps) {
|
||||
function AIWritingBody({
|
||||
hideAdvancedFields,
|
||||
initialNotebookId,
|
||||
initialDocumentIds,
|
||||
studioToken,
|
||||
compactChrome = false,
|
||||
}: {
|
||||
hideAdvancedFields: boolean;
|
||||
compactChrome?: boolean;
|
||||
} & NotebookProps) {
|
||||
const { state } = useAIWriting();
|
||||
const { isHistoryMode } = useAIWritingHistory();
|
||||
const location = useLocation();
|
||||
@@ -354,6 +438,9 @@ function AIWritingBody({ hideAdvancedFields, initialNotebookId, initialDocumentI
|
||||
// 历史内容显示到右侧区域);写作进行中收起;嵌入态(studioToken)始终不展示。
|
||||
const showSidebar =
|
||||
!studioToken && (state.status === 'idle' || isHistoryMode || agentsActive);
|
||||
const compactAppearanceActions = compactChrome ? (
|
||||
<AIWritingCompactAppearanceActions />
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<div className="flex-1 min-h-0 overflow-hidden flex">
|
||||
@@ -459,7 +546,13 @@ function AIWritingBody({ hideAdvancedFields, initialNotebookId, initialDocumentI
|
||||
查看笔记本 / 所有空间时在其上叠加内嵌页。 */}
|
||||
<div className="relative flex-1 min-h-0 overflow-hidden">
|
||||
<div className={cn('absolute inset-0', (overlayActive || agentsActive) && 'hidden')}>
|
||||
<AIWritingLayout hideAdvancedFields={hideAdvancedFields} initialNotebookId={initialNotebookId} initialDocumentIds={initialDocumentIds} studioToken={studioToken} />
|
||||
<AIWritingLayout
|
||||
hideAdvancedFields={hideAdvancedFields}
|
||||
initialNotebookId={initialNotebookId}
|
||||
initialDocumentIds={initialDocumentIds}
|
||||
studioToken={studioToken}
|
||||
compactAppearanceActions={compactAppearanceActions}
|
||||
/>
|
||||
</div>
|
||||
{overlayActive && !agentsActive && (
|
||||
<div className="absolute inset-0 flex flex-col bg-background">
|
||||
@@ -500,7 +593,10 @@ function AIWritingBody({ hideAdvancedFields, initialNotebookId, initialDocumentI
|
||||
)}
|
||||
{agentsActive && (
|
||||
<div className="absolute inset-0 bg-background">
|
||||
<AIWritingAgentRoutes base={routeBase} />
|
||||
<AIWritingAgentRoutes
|
||||
base={routeBase}
|
||||
compactAppearanceActions={compactAppearanceActions}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -521,11 +617,13 @@ export default function AIWritingPage({
|
||||
initialNotebookId,
|
||||
initialDocumentIds,
|
||||
studioToken,
|
||||
compactChrome = false,
|
||||
}: {
|
||||
hideAdvancedFields?: boolean;
|
||||
initialNotebookId?: number;
|
||||
initialDocumentIds?: number[];
|
||||
studioToken?: string;
|
||||
compactChrome?: boolean;
|
||||
} = {}) {
|
||||
return (
|
||||
<CanvasThreadProvider>
|
||||
@@ -545,6 +643,7 @@ export default function AIWritingPage({
|
||||
initialNotebookId={initialNotebookId}
|
||||
initialDocumentIds={initialDocumentIds}
|
||||
studioToken={studioToken}
|
||||
compactChrome={compactChrome}
|
||||
/>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
|
||||
Reference in new issue
Block a user