2.8 KiB
2.8 KiB
Scroll-to-Place and Highlight Feature
Overview
Implemented automatic scroll and temporary highlight functionality for newly added places in the TripPlanner timeline.
Feature Behavior
When a user adds a new place to their trip:
- Scroll: Timeline automatically scrolls to center the newly added place
- Highlight: Place is temporarily highlighted with a glowing ring effect
- Auto-remove: Highlight effect automatically disappears after 2 seconds
Implementation Details
1. State Management (TripPlanner.tsx)
Added two new state variables:
newlyAddedPlaceId: Tracks which place was just addedhighlightedPlaceId: Controls which place should show the highlight effect
2. Place Addition Flow (TripPlanner.tsx)
Modified handleAddPlaceToDay() to:
- Set
newlyAddedPlaceIdwhen a place is successfully added - This triggers the scroll and highlight effect after
loadTrip()completes
3. Scroll & Highlight Effect (TripPlanner.tsx)
Added a useEffect hook that:
- Watches for
newlyAddedPlaceIdchanges - Waits for the place element to be rendered in the DOM
- Calculates optimal scroll position to center the place
- Smoothly scrolls to the place
- Applies highlight effect
- Automatically removes highlight after 2 seconds
4. Visual Highlight (TimelinePlace.tsx)
Updated component to:
- Accept
isHighlightedprop - Apply special styling when highlighted:
- Stronger ring effect (ring-4 vs ring-2)
- Increased ring opacity (ring-primary/40)
- Enhanced shadow (shadow-lg)
- Pulsing glow animation
5. Animation (index.css)
Added custom CSS animation:
pulse-glowkeyframe animation- Creates a pulsing glow effect using box-shadow
- Runs 2 times over 1 second each
- Uses primary color with varying opacity
Technical Highlights
Robust Element Detection
The scroll function includes retry logic:
- Checks if element ref exists
- Retries after 100ms if not found
- Ensures DOM is fully updated before scrolling
Smooth User Experience
- Uses
behavior: 'smooth'for scroll animation - Centers the place in the viewport for optimal visibility
- Non-intrusive highlight that doesn't interfere with user interaction
Clean State Management
- Automatically cleans up highlight state after 2 seconds
- Clears
newlyAddedPlaceIdto prevent re-triggering - Uses timeout cleanup to prevent memory leaks
Files Modified
/src/pages/TripPlanner.tsx- Main logic and state management/src/components/planner/TimelinePlace.tsx- Visual highlight rendering/src/index.css- Custom animation styles
Testing Recommendations
- Add a place to any day in the trip
- Verify timeline scrolls to show the new place
- Confirm highlight effect appears with glow
- Check highlight disappears after 2 seconds
- Test with places added to different time blocks (morning, afternoon, evening)