diff --git a/frontend/src/components/network/CanvasEmptyPrompt.tsx b/frontend/src/components/network/CanvasEmptyPrompt.tsx index e1cec86d..1f532dfe 100644 --- a/frontend/src/components/network/CanvasEmptyPrompt.tsx +++ b/frontend/src/components/network/CanvasEmptyPrompt.tsx @@ -1,5 +1,5 @@ -import { useState, useCallback } from 'react' -import { Sparkles, ArrowRight, PencilRuler, Wand2 } from 'lucide-react' +import { useState, useCallback, useEffect } from 'react' +import { Sparkles, ArrowRight, PencilRuler, Wand2, X } from 'lucide-react' import { networkDiagramsApi } from '@/api' import type { AIGenerateResponse } from '@/types' @@ -21,6 +21,12 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) + const switchToManual = useCallback(() => { + if (loading) return + setMode('manual') + setError(null) + }, [loading]) + const handleGenerate = useCallback(async (text?: string) => { const desc = (text ?? description).trim() if (!desc) return @@ -40,16 +46,36 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) { } }, [description, onGenerate]) + useEffect(() => { + if (mode === 'manual') return + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key === 'Escape') { + event.preventDefault() + switchToManual() + } + } + + window.addEventListener('keydown', handleKeyDown) + return () => window.removeEventListener('keydown', handleKeyDown) + }, [mode, switchToManual]) + if (mode === 'manual') { return (
-
- - Manual mode enabled. Drag devices from the left panel to start building. - +
+
+ +
+
+

Manual mode is on

+

+ Drag devices from the left panel onto the canvas, or reopen AI whenever you want. +

+
{mode === 'choice' ? ( <>
@@ -74,6 +115,9 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) {

Generate a topology with AI or start with a blank canvas and build it manually.

+

+ Press Esc or click outside to skip AI and start dragging devices. +

@@ -91,18 +135,26 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) {
+ + ) : ( <> @@ -116,6 +168,9 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) {

AI will generate the topology in seconds, or you can go back and switch to manual creation.

+

+ Press Esc, click outside, or use the close button to build manually instead. +

@@ -153,12 +208,9 @@ export function CanvasEmptyPrompt({ onGenerate }: CanvasEmptyPromptProps) {