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],
|
||||
);
|
||||
|
||||
// studioToken / initialNotebookId 存在时强制使用「我的笔记」
|
||||
const effectiveMaterialSource: MaterialSource = studioToken ?? initialNotebookId != null
|
||||
? 'notebook'
|
||||
: materialSource;
|
||||
|
||||
// 初始化时加载文章类型
|
||||
useEffect(() => {
|
||||
@@ -143,7 +139,8 @@ export function AIWritingForm({
|
||||
|
||||
function handleMaterialSourceChange(val: MaterialSource) {
|
||||
setMaterialSource(val);
|
||||
if (val !== 'notebook') {
|
||||
// studioToken 模式下笔记本和文档已锁定,切换素材来源时不清空
|
||||
if (val !== 'notebook' && !studioToken) {
|
||||
setSelectedNotebookId(null);
|
||||
setSelectedDocumentIds([]);
|
||||
}
|
||||
@@ -169,11 +166,11 @@ export function AIWritingForm({
|
||||
wordCountTarget: wordCount,
|
||||
keywordCount: DEFAULT_KEYWORD_COUNT,
|
||||
writingMode: hideAdvancedFields ? 'loose' : strictMode ? 'strict' : 'loose',
|
||||
materialSource: effectiveMaterialSource,
|
||||
materialSource: materialSource,
|
||||
modelName: selectedModel?.name || modelName || undefined,
|
||||
// 只有选了"我的笔记"才传笔记参数
|
||||
noteSearchSpaceId: effectiveMaterialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined,
|
||||
noteSourceIds: effectiveMaterialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined,
|
||||
noteSearchSpaceId: materialSource === 'notebook' ? (selectedNotebookId ?? undefined) : undefined,
|
||||
noteSourceIds: materialSource === 'notebook' && selectedNotebookId != null ? selectedDocumentIds : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -282,7 +279,7 @@ export function AIWritingForm({
|
||||
<div className="mt-4 space-y-2">
|
||||
<label className={FIELD_LABEL_CLASS}>素材来源</label>
|
||||
<Select
|
||||
value={effectiveMaterialSource}
|
||||
value={materialSource}
|
||||
onValueChange={(v) => handleMaterialSourceChange(v as MaterialSource)}
|
||||
disabled={disabled}
|
||||
>
|
||||
@@ -300,7 +297,7 @@ export function AIWritingForm({
|
||||
</Select>
|
||||
|
||||
{/* 选了"我的笔记"才展示笔记本 / 文档选择器 */}
|
||||
{effectiveMaterialSource === 'notebook' && (
|
||||
{materialSource === 'notebook' && (
|
||||
<div className="mt-2 space-y-2">
|
||||
{/* studioToken 模式:笔记本已锁定,不展示选择器 */}
|
||||
{!studioToken && (
|
||||
|
||||
Reference in new issue
Block a user