planning fixes

This commit is contained in:
Jake Kasper
2025-08-27 13:47:54 -04:00
parent 2d085c1e72
commit ac6f6857b0

View File

@@ -23,6 +23,47 @@ const ApplicationPlanModal = ({
const [notes, setNotes] = useState(''); const [notes, setNotes] = useState('');
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
// Calculate map center from property or sections
const mapCenter = React.useMemo(() => {
// First try to use property coordinates
if (selectedPropertyDetails?.latitude && selectedPropertyDetails?.longitude) {
return [selectedPropertyDetails.latitude, selectedPropertyDetails.longitude];
}
// Fall back to calculating center from sections
if (selectedPropertyDetails?.sections?.length > 0) {
let totalLat = 0;
let totalLng = 0;
let pointCount = 0;
selectedPropertyDetails.sections.forEach(section => {
let polygonData = section.polygonData;
if (typeof polygonData === 'string') {
try {
polygonData = JSON.parse(polygonData);
} catch (e) {
return;
}
}
if (polygonData?.coordinates?.[0]) {
polygonData.coordinates[0].forEach(([lat, lng]) => {
totalLat += lat;
totalLng += lng;
pointCount++;
});
}
});
if (pointCount > 0) {
return [totalLat / pointCount, totalLng / pointCount];
}
}
// Default center
return [39.8283, -98.5795];
}, [selectedPropertyDetails]);
// Initialize form with editing data if provided // Initialize form with editing data if provided
useEffect(() => { useEffect(() => {
if (editingPlan) { if (editingPlan) {
@@ -46,6 +87,13 @@ const ApplicationPlanModal = ({
} }
}; };
// Debug logging
React.useEffect(() => {
console.log('ApplicationPlanModal - selectedPropertyDetails:', selectedPropertyDetails);
console.log('ApplicationPlanModal - mapCenter:', mapCenter);
console.log('ApplicationPlanModal - sections:', selectedPropertyDetails?.sections);
}, [selectedPropertyDetails, mapCenter]);
// Handle area selection on map // Handle area selection on map
const handleAreaClick = (area) => { const handleAreaClick = (area) => {
setSelectedAreas(prev => { setSelectedAreas(prev => {
@@ -336,6 +384,8 @@ const ApplicationPlanModal = ({
<div className="h-96 border rounded-lg overflow-hidden"> <div className="h-96 border rounded-lg overflow-hidden">
{selectedPropertyDetails ? ( {selectedPropertyDetails ? (
<PropertyMap <PropertyMap
center={mapCenter}
zoom={16}
property={selectedPropertyDetails} property={selectedPropertyDetails}
sections={selectedPropertyDetails.sections || []} sections={selectedPropertyDetails.sections || []}
selectedSections={selectedAreas} selectedSections={selectedAreas}