fix: replace Import button with "Save to Flow Library" and remove duplicate check

- After generation, toolbar shows "Save to Flow Library" button
  (replaces "Import to Editor")
- Button shows "Saving..." spinner state during API call
- Generate button shows animated spinner during generation
- Backend /import endpoint always creates a new Tree record
  (removed generated_tree_id idempotency check)
- Navigates to tree editor after successful save

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-28 15:08:58 -05:00
parent 2196886cd2
commit b819236aa5
3 changed files with 46 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
import { useCallback, useEffect } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { useAIChatStore } from '@/store/aiChatStore'
import { ChatPanel } from '@/components/ai-chat/ChatPanel'
@@ -62,11 +62,15 @@ export function AIChatBuilderPage() {
[sendMessage]
)
const [isSaving, setIsSaving] = useState(false)
const handleGenerate = useCallback(() => {
generateTree()
}, [generateTree])
const handleImport = useCallback(async () => {
const handleSave = useCallback(async () => {
if (isSaving) return
setIsSaving(true)
try {
const treeId = await importToEditor({
name: treeMetadata?.name,
@@ -75,11 +79,13 @@ export function AIChatBuilderPage() {
})
const path = getTreeEditorPath(treeId, flowType)
navigate(path)
toast.success('Flow imported to editor')
toast.success('Flow saved to library')
} catch {
toast.error('Failed to import flow')
toast.error('Failed to save flow')
} finally {
setIsSaving(false)
}
}, [importToEditor, treeMetadata, flowType, navigate])
}, [isSaving, importToEditor, treeMetadata, flowType, navigate])
const handleReset = useCallback(async () => {
await abandonSession()
@@ -116,8 +122,9 @@ export function AIChatBuilderPage() {
status={status}
isGenerating={isGenerating}
hasGeneratedTree={!!generatedTree}
isSaving={isSaving}
onGenerate={handleGenerate}
onImport={handleImport}
onSave={handleSave}
onReset={handleReset}
/>