mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 06:41:46 +00:00
Fix route line not updating: reactive effect on assignment changes
This commit is contained in:
@@ -228,8 +228,6 @@ export default function TripPlannerPage() {
|
|||||||
try {
|
try {
|
||||||
await tripStore.deletePlace(tripId, placeId)
|
await tripStore.deletePlace(tripId, placeId)
|
||||||
if (selectedPlaceId === placeId) setSelectedPlaceId(null)
|
if (selectedPlaceId === placeId) setSelectedPlaceId(null)
|
||||||
// Delay route update to ensure store has propagated
|
|
||||||
setTimeout(() => updateRouteForDay(selectedDayId), 50)
|
|
||||||
toast.success(t('trip.toast.placeDeleted'))
|
toast.success(t('trip.toast.placeDeleted'))
|
||||||
} catch (err) { toast.error(err.message) }
|
} catch (err) { toast.error(err.message) }
|
||||||
}, [tripId, tripStore, toast, selectedPlaceId])
|
}, [tripId, tripStore, toast, selectedPlaceId])
|
||||||
@@ -247,7 +245,6 @@ export default function TripPlannerPage() {
|
|||||||
const handleRemoveAssignment = useCallback(async (dayId, assignmentId) => {
|
const handleRemoveAssignment = useCallback(async (dayId, assignmentId) => {
|
||||||
try {
|
try {
|
||||||
await tripStore.removeAssignment(tripId, dayId, assignmentId)
|
await tripStore.removeAssignment(tripId, dayId, assignmentId)
|
||||||
updateRouteForDay(dayId)
|
|
||||||
}
|
}
|
||||||
catch (err) { toast.error(err.message) }
|
catch (err) { toast.error(err.message) }
|
||||||
}, [tripId, tripStore, toast, updateRouteForDay])
|
}, [tripId, tripStore, toast, updateRouteForDay])
|
||||||
@@ -308,6 +305,18 @@ export default function TripPlannerPage() {
|
|||||||
return map
|
return map
|
||||||
}, [selectedDayId, assignments])
|
}, [selectedDayId, assignments])
|
||||||
|
|
||||||
|
// Auto-update route when assignments change
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedDayId) return
|
||||||
|
const da = (assignments[String(selectedDayId)] || []).slice().sort((a, b) => a.order_index - b.order_index)
|
||||||
|
const waypoints = da.map(a => a.place).filter(p => p?.lat && p?.lng)
|
||||||
|
if (waypoints.length >= 2) {
|
||||||
|
setRoute(waypoints.map(p => [p.lat, p.lng]))
|
||||||
|
} else {
|
||||||
|
setRoute(null)
|
||||||
|
}
|
||||||
|
}, [selectedDayId, assignments])
|
||||||
|
|
||||||
// Places assigned to selected day (with coords) — used for map fitting
|
// Places assigned to selected day (with coords) — used for map fitting
|
||||||
const dayPlaces = useMemo(() => {
|
const dayPlaces = useMemo(() => {
|
||||||
if (!selectedDayId) return []
|
if (!selectedDayId) return []
|
||||||
|
|||||||
Reference in New Issue
Block a user