diff --git a/src/components/Timeline/CreateStateDialog.tsx b/src/components/Timeline/CreateStateDialog.tsx index 41537d9..0d72425 100644 --- a/src/components/Timeline/CreateStateDialog.tsx +++ b/src/components/Timeline/CreateStateDialog.tsx @@ -1,14 +1,5 @@ -import React, { useState } from 'react'; -import { - Dialog, - DialogTitle, - DialogContent, - DialogActions, - TextField, - Button, - FormControlLabel, - Checkbox, -} from '@mui/material'; +import React, { useState, useEffect, useRef } from 'react'; +import AddCircleIcon from '@mui/icons-material/AddCircle'; import { useTimelineStore } from '../../stores/timelineStore'; interface CreateStateDialogProps { @@ -23,9 +14,19 @@ const CreateStateDialog: React.FC = ({ open, onClose }) const [label, setLabel] = useState(''); const [description, setDescription] = useState(''); const [cloneFromCurrent, setCloneFromCurrent] = useState(true); + const inputRef = useRef(null); const { createState } = useTimelineStore(); + // Focus input when dialog opens + useEffect(() => { + if (open) { + setTimeout(() => { + inputRef.current?.focus(); + }, 50); + } + }, [open]); + const handleCreate = () => { if (!label.trim()) return; @@ -46,53 +47,129 @@ const CreateStateDialog: React.FC = ({ open, onClose }) onClose(); }; + // Handle keyboard shortcuts + useEffect(() => { + if (!open) return; + + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Enter' && !e.shiftKey) { + e.preventDefault(); + handleCreate(); + } else if (e.key === 'Escape') { + e.preventDefault(); + handleClose(); + } + }; + + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, [open, label, description, cloneFromCurrent]); // eslint-disable-line react-hooks/exhaustive-deps + + if (!open) return null; + return ( - - Create New State - -
- setLabel(e.target.value)} - placeholder="e.g., 'January 2024' or 'Strategy A'" - helperText="Give this state a descriptive name" - /> +
+
e.stopPropagation()} + > + {/* Content */} +
+
+ {/* Icon */} +
+ +
- setDescription(e.target.value)} - placeholder="Optional notes about this state..." - /> + {/* Text Content */} +
+

+ Create New State +

+

+ Create a new timeline state to capture a different version of your graph +

- setCloneFromCurrent(e.target.checked)} - /> - } - label="Clone current graph (uncheck for empty state)" - /> + {/* Form Fields */} +
+ {/* State Label */} +
+ + setLabel(e.target.value)} + placeholder="e.g., 'January 2024' or 'Strategy A'" + className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500" + /> +

+ Give this state a descriptive name +

+
+ + {/* Description */} +
+ +