diff --git a/frontend-web/src/open-canvas/hooks/useAIWriting.ts b/frontend-web/src/open-canvas/hooks/useAIWriting.ts index 996b16f6..b99ef356 100644 --- a/frontend-web/src/open-canvas/hooks/useAIWriting.ts +++ b/frontend-web/src/open-canvas/hooks/useAIWriting.ts @@ -13,6 +13,7 @@ import type { StreamingDraftSection, StreamingReviewItem, UserInterventionPayload, + WritingStatus, } from '../types/ai-writing'; const INITIAL_STATE: AIWritingState = { @@ -306,11 +307,32 @@ export function useAIWriting() { }; } + // Optimistic next-status so the correct skeleton shows immediately after + // the user clicks confirm, without waiting for the first SSE chunk. + let nextStatus: WritingStatus = state.status; + if (pausePoint === 'material_confirm') { + nextStatus = payload.action === 're_search' ? 'researching' : 'writing_outline'; + } else if (pausePoint === 'outline_confirm') { + nextStatus = payload.action === 're_outline' ? 'writing_outline' : 'writing_draft'; + } else if (pausePoint === 'draft_confirm') { + if (payload.action === 'finalize') nextStatus = 'done'; + else if (payload.action === 'to_editor') nextStatus = 'reviewing'; + else nextStatus = 'revising'; // user_revise + } else if (pausePoint === 'review_confirm') { + nextStatus = payload.action === 'force_finalize' ? 'done' : 'revising'; // accept_review + } + try { await resumeWriting(state.sessionId, payload); setState((prev) => ({ ...prev, currentPause: null, + status: nextStatus, + // Clear stale streaming state so new-cycle detection in chunk handlers works correctly + ...(nextStatus === 'writing_outline' ? { outlineStreamingText: '', outlineThinkingText: '' } : {}), + ...(nextStatus === 'writing_draft' ? { streamingDraftSections: [], streamingDraftTitle: '' } : {}), + ...(nextStatus === 'reviewing' ? { streamingReviewItems: [] } : {}), + ...(nextStatus === 'revising' ? { streamingDraftSections: [], streamingDraftTitle: '' } : {}), completedInterventions: [...prev.completedInterventions, record], ...(pendingRevisionContext ? { pendingRevisionContext } : {}), }));