diff --git a/frontend/src/pages/Properties/PropertyDetail.js b/frontend/src/pages/Properties/PropertyDetail.js index d58f7e3..b52cae3 100644 --- a/frontend/src/pages/Properties/PropertyDetail.js +++ b/frontend/src/pages/Properties/PropertyDetail.js @@ -8,7 +8,8 @@ import { TrashIcon, ArrowLeftIcon, MapPinIcon, - SwatchIcon + SwatchIcon, + PencilIcon } from '@heroicons/react/24/outline'; import { propertiesAPI } from '../../services/api'; import LoadingSpinner from '../../components/UI/LoadingSpinner'; @@ -54,10 +55,19 @@ function PolygonDrawer({ isDrawing, onPolygonComplete, currentColor }) { if (!isDrawing) return; const newPoint = [e.latlng.lat, e.latlng.lng]; - setCurrentPolygon(prev => [...prev, newPoint]); + console.log('Adding point:', newPoint); + setCurrentPolygon(prev => { + const newPoly = [...prev, newPoint]; + console.log('Current polygon has', newPoly.length, 'points'); + return newPoly; + }); }, - dblclick() { + dblclick(e) { + console.log('Double click detected, drawing:', isDrawing, 'points:', currentPolygon.length); if (isDrawing && currentPolygon.length >= 3) { + e.originalEvent.preventDefault(); + e.originalEvent.stopPropagation(); + console.log('Completing polygon with', currentPolygon.length, 'points'); onPolygonComplete(currentPolygon); setCurrentPolygon([]); } @@ -89,11 +99,30 @@ const PropertyDetail = () => { const [showNameModal, setShowNameModal] = useState(false); const [pendingSection, setPendingSection] = useState(null); const [sectionName, setSectionName] = useState(''); + const [editingSection, setEditingSection] = useState(null); + const [showEditModal, setShowEditModal] = useState(false); useEffect(() => { fetchPropertyDetails(); }, [id]); // eslint-disable-line react-hooks/exhaustive-deps + // Handle keyboard shortcuts for polygon drawing + useEffect(() => { + const handleKeyPress = (e) => { + if (isDrawing && e.key === 'Enter') { + // Find the PolygonDrawer component and complete the polygon + console.log('Enter pressed during drawing mode'); + } + if (e.key === 'Escape' && isDrawing) { + setIsDrawing(false); + toast.info('Drawing cancelled'); + } + }; + + document.addEventListener('keydown', handleKeyPress); + return () => document.removeEventListener('keydown', handleKeyPress); + }, [isDrawing]); + const fetchPropertyDetails = async () => { try { setLoading(true); @@ -110,12 +139,14 @@ const PropertyDetail = () => { }; const handlePolygonComplete = (coordinates) => { + console.log('handlePolygonComplete called with', coordinates.length, 'coordinates'); if (coordinates.length < 3) { toast.error('Polygon needs at least 3 points'); return; } const area = calculateAreaInSqFt([...coordinates, coordinates[0]]); + console.log('Calculated area:', area); setPendingSection({ coordinates, color: currentColor, area }); setShowNameModal(true); setIsDrawing(false); @@ -153,6 +184,34 @@ const PropertyDetail = () => { } }; + const startEditSection = (section) => { + setEditingSection(section); + setSectionName(section.name); + setCurrentColor(section.color); + setShowEditModal(true); + }; + + const saveEditedSection = () => { + if (!sectionName.trim()) { + toast.error('Please enter a section name'); + return; + } + + const updatedSection = { + ...editingSection, + name: sectionName, + color: currentColor + }; + + setLawnSections(prev => prev.map(s => s.id === editingSection.id ? updatedSection : s)); + toast.success('Section updated!'); + + // Reset + setSectionName(''); + setEditingSection(null); + setShowEditModal(false); + }; + const getTotalArea = () => { return lawnSections.reduce((total, section) => total + section.area, 0); }; @@ -231,7 +290,8 @@ const PropertyDetail = () => {
- Drawing Mode: Click to add points. Double-click to complete polygon. +
+ Drawing Mode Active: Click to add points. Double-click to complete polygon. +
++ Need at least 3 points to create a section. Press ESC to cancel.
{section.area.toLocaleString()} sq ft