Skip to content

feat(map): enable adding new points via drag and double-click on the map #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2025

Conversation

timDeHof
Copy link
Owner

@timDeHof timDeHof commented Aug 2, 2025

This PR introduces new interactive features for adding map points, including drag-and-drop functionality and double-click selection. The changes enhance the user interface by adding visual markers and tooltips to guide users in placing points on the map.

closes #30

Summary by CodeRabbit

  • New Features

    • Users can now add a point to the map by double-clicking or dragging a marker, with the map centering on the newly added point.
    • The add location form now synchronizes with the map, allowing users to set coordinates interactively rather than entering them manually.
  • Improvements

    • The dashboard layout dynamically adjusts based on the current route.
    • Latitude and longitude values are displayed in a user-friendly, read-only format during location addition.
    • Enhanced map interaction for a more intuitive user experience when adding locations.

This commit introduces new interactive features for adding map points, including drag-and-drop functionality and double-click selection. The changes enhance the user interface by adding visual markers and tooltips to guide users in placing points on the map.
Copy link

vercel bot commented Aug 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nuxt-travel-log ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 2, 2025 3:43am

Copy link

coderabbitai bot commented Aug 2, 2025

Walkthrough

This update enhances map interaction by enabling users to add and reposition a point on the map via dragging or double-clicking. The form for adding locations now synchronizes with the map marker, removing manual latitude/longitude entry. Store logic shifts to manage and animate the map based on the added point's state.

Changes

Cohort / File(s) Change Summary
Map Point Interaction Enhancements
components/app/map.client.vue, stores/map.ts
Introduces draggable "addedPoint" marker; updates store to manage addedPoint state; adds double-click to set marker; removes legacy fly-to logic; synchronizes map animation with marker addition.
Dashboard Add Form Synchronization
pages/dashboard/add.vue
Replaces manual lat/lng input with map-based selection; synchronizes form fields with draggable marker; displays formatted coordinates; adds lifecycle hooks to manage marker state; updates UI instructions.
Dashboard Layout Adjustment
pages/dashboard.vue
Adds conditional flex direction and background styling based on route; minor layout and style changes.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MapComponent
    participant MapStore
    participant AddForm

    User->>MapComponent: Double-click or drag marker
    MapComponent->>MapStore: Update addedPoint coordinates
    MapStore->>MapComponent: Watch addedPoint, fly to new location
    MapStore->>AddForm: Sync addedPoint with form fields
    AddForm->>User: Display updated coordinates
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #65: Establishes dynamic marker rendering and map state management, directly related to the new draggable marker and point state logic.
  • #64: Introduces the map component that is extended here with interactive marker features.

Poem

A marker hops where you double-click,
Drag it gently—its spot will stick.
No more numbers, just map and view,
Coordinates update, fresh as dew.
Rabbits rejoice in this mapping spree,
For adding a place is now hassle-free! 🗺️🐇

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ntl-30

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
components/app/map.client.vue (3)

16-21: Remove unnecessary semicolon after function closing brace.

 function updatedAddedPoint(location: LngLat) {
   if (mapStore.addedPoint) {
     mapStore.addedPoint.lat = location.lat;
     mapStore.addedPoint.long = location.lng;
   }
-};
+}

23-28: Remove unnecessary semicolon after function closing brace.

 function onDoubleClick(mglEvent: MglEvent<"dblclick">) {
   if (mapStore.addedPoint) {
     mapStore.addedPoint.lat = mglEvent.event.lngLat.lat;
     mapStore.addedPoint.long = mglEvent.event.lngLat.lng;
   }
-};
+}

49-55: Consider making the tooltip conditional to improve user experience.

The tooltip is always open with the tooltip-open class, which might be distracting. Consider showing it only initially or on hover.

-        <div class="tooltip tooltip-top hover:cursor-pointer tooltip-open" data-tip="Drag to your desired location">
+        <div class="tooltip tooltip-top hover:cursor-pointer" :class="{ 'tooltip-open': showAddedPointTooltip }" data-tip="Drag to your desired location">

You would need to add a showAddedPointTooltip ref that could be controlled based on user interaction or a timer.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65bc060 and db86910.

📒 Files selected for processing (4)
  • components/app/map.client.vue (4 hunks)
  • pages/dashboard.vue (1 hunks)
  • pages/dashboard/add.vue (4 hunks)
  • stores/map.ts (2 hunks)
🔇 Additional comments (4)
pages/dashboard.vue (1)

82-83: LGTM! Layout adjustments support the new map interaction feature.

The conditional flex direction based on the route and the background color addition are appropriate changes that complement the new interactive map features.

components/app/map.client.vue (1)

70-71: Good simplification of mouse event handlers!

The direct assignment to mapStore.selectedPoint is cleaner than using separate handler functions.

pages/dashboard/add.vue (2)

131-142: Clear and helpful UI instructions!

The instructions for dragging the marker or double-clicking the map, along with the real-time coordinate display, provide excellent user guidance.


61-69: Verify hardcoded id assignment on new map points

File: pages/dashboard/add.vue
Lines: 61–69

onMounted(() => {
  mapStore.addedPoint = {
    long: (CENTER_USA as [number, number])[0],
    lat: (CENTER_USA as [number, number])[1],
    description: "",
    name: "Added Point",
    id: 1,
  };
});

We weren’t able to locate a MapPoint type or any downstream logic that relies on .id—absence of evidence isn’t evidence of absence. Please confirm:

  • Is the id field actually required for new points?
  • Could a static id: 1 collide with other points (e.g., in persistence or comparisons)?
  • Should you generate a unique identifier (UUID, nanoid, etc.) or defer ID assignment until the point is saved?

Consider omitting the id for purely temporary points or switching to a dynamic ID strategy to avoid clashes.

Comment on lines +25 to +29
function formatNumber(value?: number) {
if (!value)
return 0;
return value.toFixed(5);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve null/undefined handling in formatNumber.

The current implementation returns 0 for falsy values, which might not be appropriate for coordinates.

 function formatNumber(value?: number) {
-  if (!value)
-    return 0;
+  if (value === undefined || value === null)
+    return '';
   return value.toFixed(5);
 }

This change ensures that undefined/null values are displayed as empty strings rather than "0.00000", which is clearer for users.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function formatNumber(value?: number) {
if (!value)
return 0;
return value.toFixed(5);
}
function formatNumber(value?: number) {
if (value === undefined || value === null)
return '';
return value.toFixed(5);
}
🤖 Prompt for AI Agents
In pages/dashboard/add.vue around lines 25 to 29, the formatNumber function
returns 0 for any falsy value, which incorrectly converts null or undefined to
"0.00000". Update the function to explicitly check for null or undefined and
return an empty string in those cases, while still formatting valid numbers to
five decimal places. This will ensure clearer display of missing coordinate
values.

Comment on lines +28 to 38
watch(addedPoint, (newValue, oldValue) => {
if (newValue && !oldValue) {
map.map?.flyTo({
center: [newValue.long, newValue.lat],
speed: 0.8,
zoom: 6,
});
}
}, {
immediate: true,
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider refining the watcher logic for better control over fly-to animations.

The current implementation has a few potential issues:

  1. With immediate: true, if addedPoint is already set when the store initializes, it will trigger an unnecessary fly-to animation
  2. The condition newValue && !oldValue only triggers on null-to-value transitions, missing updates when dragging an existing point

Consider this improved implementation:

-    watch(addedPoint, (newValue, oldValue) => {
-      if (newValue && !oldValue) {
-        map.map?.flyTo({
-          center: [newValue.long, newValue.lat],
-          speed: 0.8,
-          zoom: 6,
-        });
-      }
-    }, {
-      immediate: true,
-    });
+    watch(addedPoint, (newValue, oldValue) => {
+      // Only fly to if we're adding a new point (not just updating coordinates)
+      if (newValue && !oldValue && map.map) {
+        map.map.flyTo({
+          center: [newValue.long, newValue.lat],
+          speed: 0.8,
+          zoom: 6,
+        });
+      }
+    });

This removes the immediate option and adds a null check for map.map to prevent potential runtime errors.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
watch(addedPoint, (newValue, oldValue) => {
if (newValue && !oldValue) {
map.map?.flyTo({
center: [newValue.long, newValue.lat],
speed: 0.8,
zoom: 6,
});
}
}, {
immediate: true,
});
watch(addedPoint, (newValue, oldValue) => {
// Only fly to if we're adding a new point (not just updating coordinates)
if (newValue && !oldValue && map.map) {
map.map.flyTo({
center: [newValue.long, newValue.lat],
speed: 0.8,
zoom: 6,
});
}
});
🤖 Prompt for AI Agents
In stores/map.ts around lines 28 to 38, the watcher on addedPoint uses
immediate: true causing an unnecessary fly-to animation on initialization and
only triggers on null-to-value changes, missing updates when the point changes.
Remove the immediate option and update the watcher condition to trigger on any
newValue change, adding a null check for map.map before calling flyTo to avoid
runtime errors.

@timDeHof timDeHof merged commit e8af190 into main Aug 2, 2025
7 checks passed
@timDeHof timDeHof deleted the ntl-30 branch August 2, 2025 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

As a traveler, I want to select coordinates by clicking on the map
1 participant