Преглед изворни кода

fix(chat): clear chapter save status on new send and conversation switch

Updated chat components to ensure that the chapter save status is cleared when a new message is sent or when switching conversations. Adjusted the rendering logic to display the save status only for the last assistant message. Added tests to verify the new behavior.
darknessomi пре 2 месеци
родитељ
комит
1c3a2c2d59

+ 11 - 0
src/components/chat/chat-message.spec.tsx

@@ -76,6 +76,17 @@ describe("chapter save preview sync regression", () => {
     expect(source).not.toContain("applyPendingChapterSave")
     expect(source).not.toContain("保存到章节后面")
   })
+
+  it("clears chapter save status on new send and conversation switch", () => {
+    const panelSource = readFileSync(resolve(__dirname, "chat-panel.tsx"), "utf8")
+    const messageSource = readFileSync(resolve(__dirname, "chat-message.tsx"), "utf8")
+
+    expect(panelSource).toContain('setChapterSaveStatus("")')
+    expect(panelSource).toMatch(/setDeAiSkillWarningMessage\(""\)[\s\S]*?setChapterSaveStatus\(""\)/)
+    expect(panelSource).toMatch(/userScrolledUpRef\.current = false[\s\S]*?setChapterSaveStatus\(""\)[\s\S]*?\}, \[activeConversationId\]\)/)
+    expect(panelSource).toContain("saveStatus={isLastAssistant ? chapterSaveStatus : undefined}")
+    expect(messageSource).toContain("isLastAssistant && saveStatus")
+  })
 })
 
 describe("deep chapter unfinished continuation action", () => {

+ 1 - 1
src/components/chat/chat-message.tsx

@@ -140,7 +140,7 @@ export function ChatMessage({ message, isLastAssistant, onRegenerate, novelMode,
             )}
           </div>
         )}
-        {saveStatus && (
+        {isLastAssistant && saveStatus && (
           <p className="mt-1 text-xs text-muted-foreground">{saveStatus}</p>
         )}
       </div>

+ 5 - 1
src/components/chat/chat-panel.tsx

@@ -351,6 +351,8 @@ export function ChatPanel() {
 
   useEffect(() => {
     userScrolledUpRef.current = false
+    // 切换会话时清空上一会话的章节保存状态,避免「已保存为第X章」残留
+    setChapterSaveStatus("")
   }, [activeConversationId])
 
   // 加载故事框架绑定状态
@@ -390,6 +392,8 @@ export function ChatPanel() {
     async (text: string) => {
       // Auto-create a conversation if none is active
       setDeAiSkillWarningMessage("")
+      // 新一轮对话清空上一轮的章节保存提示,避免「已保存为第X章」残留在新消息下方
+      setChapterSaveStatus("")
       let convId = useChatStore.getState().activeConversationId
       if (!convId) {
         convId = createConversation()
@@ -1504,7 +1508,7 @@ export function ChatPanel() {
                       onSaveAsChapter={handleSaveAsChapter}
                       onContinueNextChapter={isLastAssistant ? handleContinueNextChapter : undefined}
                       onContinueUnfinished={isLastAssistant ? () => handleContinueUnfinished(msg) : undefined}
-                      saveStatus={chapterSaveStatus}
+                      saveStatus={isLastAssistant ? chapterSaveStatus : undefined}
                       isSaving={isSavingChapter}
                     />
                   )