fix(notebook): preserve selected notebook/docs when switching material source with studioToken
- Initialize materialSource via WritingFormProvider initialMaterialSource prop - Don't clear selectedNotebookId/selectedDocumentIds on source switch when studioToken is set Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
c577833e7c
commit
9adb0fee28
3 files changed
+10
-13
No files matched your search
@@ -97,10 +97,6 @@ export function AIWritingForm({
|
|||||||
[models, modelName],
|
[models, modelName],
|
||||||
);
|
);
|
||||||
|
|
||||||
// studioToken / initialNotebookId 存在时强制使用「我的笔记」
|
|
||||||
const effectiveMaterialSource: MaterialSource = studioToken ?? initialNotebookId != null
|
|
||||||
? 'notebook'
|
|
||||||
: materialSource;
|
|
||||||
|
|
||||||
// 初始化时加载文章类型
|
// 初始化时加载文章类型
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -143,7 +139,8 @@ export function AIWritingForm({
|
|||||||
|
|
||||||
function handleMaterialSourceChange(val: MaterialSource) {
|
function handleMaterialSourceChange(val: MaterialSource) {
|
||||||
setMaterialSource(val);
|
setMaterialSource(val);
|
||||||
if (val !== 'notebook') {
|
// studioToken 模式下笔记本和文档已锁定,切换素材来源时不清空
|
||||||
|
if (val !== 'notebook' && !studioToken) {
|
||||||
setSelectedNotebookId(null);
|
setSelectedNotebookId(null);
|
||||||
setSelectedDocumentIds([]);
|
setSelectedDocumentIds([]);
|
||||||
}
|
}
|
||||||
@@ -169,11 +166,11 @@ export function AIWritingForm({
|
|||||||
wordCountTarget: wordCount,
|
wordCountTarget: wordCount,
|
||||||
keywordCount: DEFAULT_KEYWORD_COUNT,
|
keywordCount: DEFAULT_KEYWORD_COUNT,
|
||||||
writingMode: hideAdvancedFields ? 'loose' : strictMode ? 'strict' : 'loose',
|
writingMode: hideAdvancedFields ? 'loose' : strictMode ? 'strict' : 'loose',
|
||||||
materialSource: effectiveMaterialSource,
|
materialSource: materialSource,
|
||||||
modelName: selectedModel?.name || modelName || undefined,
|
modelName: selectedModel?.name || modelName || undefined,
|
||||||
// 只有选了"我的笔记"才传笔记参数
|
// 只有选了"我的笔记"才传笔记参数
|
||||||
noteSearchSpaceId: effectiveMaterialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined,
|
noteSearchSpaceId: materialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined,
|
||||||
noteSourceIds: effectiveMaterialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined,
|
noteSourceIds: materialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,7 +279,7 @@ export function AIWritingForm({
|
|||||||
<div className="mt-4 space-y-2">
|
<div className="mt-4 space-y-2">
|
||||||
<label className={FIELD_LABEL_CLASS}>素材来源</label>
|
<label className={FIELD_LABEL_CLASS}>素材来源</label>
|
||||||
<Select
|
<Select
|
||||||
value={effectiveMaterialSource}
|
value={materialSource}
|
||||||
onValueChange={(v) => handleMaterialSourceChange(v as MaterialSource)}
|
onValueChange={(v) => handleMaterialSourceChange(v as MaterialSource)}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
>
|
>
|
||||||
@@ -300,7 +297,7 @@ export function AIWritingForm({
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
{/* 选了"我的笔记"才展示笔记本 / 文档选择器 */}
|
{/* 选了"我的笔记"才展示笔记本 / 文档选择器 */}
|
||||||
{effectiveMaterialSource === 'notebook' && (
|
{materialSource === 'notebook' && (
|
||||||
<div className="mt-2 space-y-2">
|
<div className="mt-2 space-y-2">
|
||||||
{/* studioToken 模式:笔记本已锁定,不展示选择器 */}
|
{/* studioToken 模式:笔记本已锁定,不展示选择器 */}
|
||||||
{!studioToken && (
|
{!studioToken && (
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export function useWritingFormOptional(): WritingFormValue | null {
|
|||||||
return useContext(WritingFormContext);
|
return useContext(WritingFormContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function WritingFormProvider({ children }: { children: ReactNode }) {
|
export function WritingFormProvider({ children, initialMaterialSource }: { children: ReactNode; initialMaterialSource?: 'knowledge_base' | 'skill' | 'notebook' }) {
|
||||||
const [intent, setIntent] = useState('');
|
const [intent, setIntent] = useState('');
|
||||||
const [showOutline, setShowOutline] = useState(false);
|
const [showOutline, setShowOutline] = useState(false);
|
||||||
const [outlineText, setOutlineText] = useState('');
|
const [outlineText, setOutlineText] = useState('');
|
||||||
@@ -61,7 +61,7 @@ export function WritingFormProvider({ children }: { children: ReactNode }) {
|
|||||||
const [wordCountInput, setWordCountInput] = useState('800');
|
const [wordCountInput, setWordCountInput] = useState('800');
|
||||||
const [audience, setAudience] = useState('普通读者');
|
const [audience, setAudience] = useState('普通读者');
|
||||||
const [strictMode, setStrictMode] = useState(false);
|
const [strictMode, setStrictMode] = useState(false);
|
||||||
const [materialSource, setMaterialSource] = useState<'knowledge_base' | 'skill' | 'notebook'>('knowledge_base');
|
const [materialSource, setMaterialSource] = useState<'knowledge_base' | 'skill' | 'notebook'>(initialMaterialSource ?? 'knowledge_base');
|
||||||
const [modelName, setModelName] = useState('');
|
const [modelName, setModelName] = useState('');
|
||||||
|
|
||||||
const applyProposal = useCallback((payload: SetupWritingApprovalPayload) => {
|
const applyProposal = useCallback((payload: SetupWritingApprovalPayload) => {
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ export default function AIWritingPage({
|
|||||||
<CanvasUIProvider>
|
<CanvasUIProvider>
|
||||||
<AIWritingHistoryProvider>
|
<AIWritingHistoryProvider>
|
||||||
<AIWritingProvider>
|
<AIWritingProvider>
|
||||||
<WritingFormProvider>
|
<WritingFormProvider initialMaterialSource={studioToken ?? initialNotebookId != null ? 'notebook' : undefined}>
|
||||||
<TooltipProvider delayDuration={300}>
|
<TooltipProvider delayDuration={300}>
|
||||||
<div className="h-full flex flex-col overflow-hidden bg-background">
|
<div className="h-full flex flex-col overflow-hidden bg-background">
|
||||||
<div className="flex-1 min-h-0 overflow-hidden">
|
<div className="flex-1 min-h-0 overflow-hidden">
|
||||||
|
|||||||
Reference in new issue
Block a user