Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

Fix route line not updating: reactive effect on assignment changes

Mauricec1e568cb1e96
diff --git a/client/src/pages/TripPlannerPage.jsx b/client/src/pages/TripPlannerPage.jsx
index a02a32fc9..baaa532e0 100644
--- a/client/src/pages/TripPlannerPage.jsx
+++ b/client/src/pages/TripPlannerPage.jsx
@@ -228,8 +228,6 @@ export default function TripPlannerPage() {
try {
await tripStore.deletePlace(tripId, placeId)
if (selectedPlaceId === placeId) setSelectedPlaceId(null)
- // Delay route update to ensure store has propagated
- setTimeout(() => updateRouteForDay(selectedDayId), 50)
toast.success(t('trip.toast.placeDeleted'))
} catch (err) { toast.error(err.message) }
}, [tripId, tripStore, toast, selectedPlaceId])
@@ -247,7 +245,6 @@ export default function TripPlannerPage() {
const handleRemoveAssignment = useCallback(async (dayId, assignmentId) => {
try {
await tripStore.removeAssignment(tripId, dayId, assignmentId)
- updateRouteForDay(dayId)
}
catch (err) { toast.error(err.message) }
}, [tripId, tripStore, toast, updateRouteForDay])
@@ -308,6 +305,18 @@ export default function TripPlannerPage() {
return map
}, [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
const dayPlaces = useMemo(() => {
if (!selectedDayId) return []