feat(ai写作): 历史回看右侧成稿可编辑并保存回历史记录
- 后端新增 PUT /api/ai-writing/sessions/{id}/draft(属主校验,draft_title 可选)
- 前端历史模式放开只读,工具栏新增「保存」按钮持久化修改
- 实时写作完成态保持原样(仅导出,不落库)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
304e1b637a
commit
42f55251f2
7 files changed
+126
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { createContext, useCallback, useContext, useMemo, useState, type ReactNode } from 'react';
|
||||
|
||||
import { getAIWritingSession } from '../api/ai-writing-sessions';
|
||||
import { getAIWritingSession, updateAIWritingDraft } from '../api/ai-writing-sessions';
|
||||
import type { AIWritingSessionSummary } from '../api/ai-writing-sessions';
|
||||
import { useCanvasGraphContext } from './CanvasGraphContext';
|
||||
import { useCanvasUIContext } from './CanvasUIContext';
|
||||
@@ -10,6 +10,8 @@ type AIWritingHistoryContextValue = {
|
||||
isHistoryMode: boolean;
|
||||
openHistory: (session: AIWritingSessionSummary) => Promise<void>;
|
||||
closeHistory: () => void;
|
||||
/** 历史回看时把用户修改后的正文保存回该会话(持久化到后端)。 */
|
||||
saveHistoryDraft: (markdown: string, title?: string) => Promise<void>;
|
||||
};
|
||||
|
||||
const AIWritingHistoryContext = createContext<AIWritingHistoryContextValue | null>(null);
|
||||
@@ -52,14 +54,25 @@ export function AIWritingHistoryProvider({ children }: { children: ReactNode })
|
||||
setIsDraftEditable(true);
|
||||
}, [setArtifact, setIsDraftEditable]);
|
||||
|
||||
const saveHistoryDraft = useCallback(
|
||||
async (markdown: string, title?: string) => {
|
||||
if (!historySession) return;
|
||||
const updated = await updateAIWritingDraft(historySession.id, markdown, title);
|
||||
// 回写本地会话,保证后续重开/重命名读到最新成稿
|
||||
setHistorySession((prev) => (prev && prev.id === updated.id ? updated : prev));
|
||||
},
|
||||
[historySession],
|
||||
);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
historySession,
|
||||
isHistoryMode: historySession !== null,
|
||||
openHistory,
|
||||
closeHistory,
|
||||
saveHistoryDraft,
|
||||
}),
|
||||
[historySession, openHistory, closeHistory],
|
||||
[historySession, openHistory, closeHistory, saveHistoryDraft],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user