-
-
Notifications
You must be signed in to change notification settings - Fork 586
add map comments with collab sync #1607
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
giswqs
merged 8 commits into
opengeos:main
from
HarshShinde0:feat/comments-collab-improvements
Aug 1, 2026
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6720811
feat: add comments panel and collab protocol support
HarshShinde0 b670920
test: fix comment tests and add send-path coverage
HarshShinde0 66408bd
style: auto-format (ruff + oxfmt) [pre-commit.ci]
pre-commit-ci[bot] 0faa763
fix: address review feedback
HarshShinde0 ca6285c
fix: address i18n, collab connection identity, and store/relay reply …
HarshShinde0 40a7462
fix: resolve layer style IDs, disconnect rejection, and canEdit permi…
HarshShinde0 17bd9d0
fix: localize session disconnect error, guard collab socket callbacks…
HarshShinde0 101ea38
style: auto-format (ruff + oxfmt) [pre-commit.ci]
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
155 changes: 155 additions & 0 deletions
155
apps/geolibre-desktop/src/components/comments/AddCommentDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { useState } from "react"; | ||
| import { | ||
| Button, | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| Input, | ||
| Textarea, | ||
| } from "@geolibre/ui"; | ||
| import { MapPin, Layers, MessageSquare, Send, User } from "lucide-react"; | ||
| import type { PendingCommentState } from "./useCommentTool"; | ||
|
|
||
| interface AddCommentDialogProps { | ||
| pendingComment: PendingCommentState; | ||
| onSubmit: (body: string, authorName?: string) => void; | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| export function AddCommentDialog({ pendingComment, onSubmit, onCancel }: AddCommentDialogProps) { | ||
| const savedName = | ||
| typeof localStorage !== "undefined" ? localStorage.getItem("geolibre_author_name") : null; | ||
| const hasSavedName = !!savedName && savedName.trim().length > 0; | ||
|
|
||
| const [text, setText] = useState(""); | ||
| const [authorName, setAuthorName] = useState(savedName ?? ""); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| const handleSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault(); | ||
| if (!text.trim()) return; | ||
|
|
||
| const finalName = authorName.trim() || savedName?.trim() || "Author"; | ||
| if (typeof localStorage !== "undefined" && finalName) { | ||
| try { | ||
| localStorage.setItem("geolibre_author_name", finalName); | ||
| } catch { | ||
| // ignore storage errors | ||
| } | ||
| } | ||
|
|
||
| onSubmit(text.trim(), finalName); | ||
| setText(""); | ||
| }; | ||
|
|
||
| const anchor = pendingComment.anchor; | ||
| const lngLat = anchor.lngLat; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={true} | ||
| onOpenChange={(open) => { | ||
| if (!open) onCancel(); | ||
| }} | ||
| > | ||
| <DialogContent className="max-w-md p-5 sm:max-w-md"> | ||
| <DialogHeader className="mb-2"> | ||
| <DialogTitle className="flex items-center gap-2 text-sm"> | ||
| <MessageSquare className="h-4 w-4 text-primary" /> | ||
| <span>Add Review Comment</span> | ||
| </DialogTitle> | ||
| <DialogDescription className="text-xs text-muted-foreground"> | ||
| Post an anchored note on this project for team review or offline reference. | ||
| </DialogDescription> | ||
|
HarshShinde0 marked this conversation as resolved.
Outdated
|
||
| </DialogHeader> | ||
|
|
||
| <form onSubmit={handleSubmit} className="space-y-3.5"> | ||
| <div className="flex items-center gap-2 text-xs text-muted-foreground bg-muted/50 p-2.5 rounded-md border border-border/60"> | ||
| {anchor.type === "feature" ? ( | ||
| <> | ||
| <Layers className="h-3.5 w-3.5 text-sky-400 shrink-0" /> | ||
| <span className="truncate font-medium text-foreground"> | ||
| Anchored to Feature #{String(anchor.featureId)} ({anchor.layerId}) | ||
| </span> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <MapPin className="h-3.5 w-3.5 text-amber-400 shrink-0" /> | ||
| <span className="font-medium text-foreground"> | ||
| Anchored to ( | ||
| {lngLat ? `${lngLat[1].toFixed(4)}, ${lngLat[0].toFixed(4)}` : "Map Point"}) | ||
| </span> | ||
| </> | ||
| )} | ||
| </div> | ||
|
|
||
| {/* Prompt for name 1 time if not saved in localStorage */} | ||
| {!hasSavedName ? ( | ||
| <div className="space-y-1"> | ||
| <label className="text-[11px] font-medium text-muted-foreground flex items-center gap-1"> | ||
| <User className="h-3 w-3 text-primary" /> | ||
| <span>Your Name (Asked once, saved automatically)</span> | ||
| </label> | ||
| <Input | ||
| value={authorName} | ||
| onChange={(e) => setAuthorName(e.target.value)} | ||
| placeholder="e.g. Alex or Sarah" | ||
| className="text-xs h-8" | ||
| autoFocus | ||
| /> | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| </div> | ||
| ) : ( | ||
| <div className="flex items-center justify-between text-[11px] text-muted-foreground px-1"> | ||
| <span> | ||
| Posting as <strong className="text-foreground">{savedName}</strong> | ||
| </span> | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| if (typeof localStorage !== "undefined") { | ||
| localStorage.removeItem("geolibre_author_name"); | ||
| setAuthorName(""); | ||
| } | ||
| }} | ||
| className="text-primary hover:underline text-[10px]" | ||
| > | ||
| Change Name | ||
| </button> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="space-y-1"> | ||
| <label className="text-[11px] font-medium text-muted-foreground"> | ||
| Comment / Feedback | ||
| </label> | ||
| <Textarea | ||
| value={text} | ||
| onChange={(e) => setText(e.target.value)} | ||
| placeholder="Type your review note or feedback here..." | ||
| rows={3} | ||
| className="text-xs min-h-20 resize-none" | ||
| autoFocus={hasSavedName} | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="flex items-center justify-end gap-2 pt-1"> | ||
| <Button type="button" variant="outline" size="sm" onClick={onCancel}> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| type="submit" | ||
| variant="default" | ||
| size="sm" | ||
| className="gap-1.5" | ||
| disabled={!text.trim() || (!hasSavedName && !authorName.trim())} | ||
| > | ||
| <Send className="h-3.5 w-3.5" /> | ||
| <span>Post Comment</span> | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
151 changes: 151 additions & 0 deletions
151
apps/geolibre-desktop/src/components/comments/CommentMapOverlay.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { useEffect, useRef } from "react"; | ||
| import { useAppStore, type ProjectComment } from "@geolibre/core"; | ||
| import type { MapController } from "@geolibre/map"; | ||
| import maplibreGl from "maplibre-gl"; | ||
|
|
||
| interface CommentMapOverlayProps { | ||
| mapControllerRef: React.RefObject<MapController | null>; | ||
| onSelectComment?: (commentId: string) => void; | ||
| showResolved?: boolean; | ||
| } | ||
|
|
||
| export function resolveCommentCoordinates( | ||
| comment: ProjectComment, | ||
| map: maplibreGl.Map | null, | ||
| ): [number, number] | null { | ||
| // 1. Direct lngLat on point or feature anchor | ||
| if (comment.anchor.lngLat) { | ||
| return comment.anchor.lngLat; | ||
| } | ||
|
|
||
| if (!map) return null; | ||
|
|
||
| // 2. Query rendered features on active layer | ||
| if (comment.anchor.type === "feature") { | ||
| const { layerId, featureId } = comment.anchor; | ||
| try { | ||
| const features = map.queryRenderedFeatures(undefined, { | ||
| layers: [layerId], | ||
| filter: ["==", ["id"], featureId], | ||
| }); | ||
| if (features.length > 0 && features[0].geometry) { | ||
| const g = features[0].geometry; | ||
| if (g.type === "Point") return g.coordinates as [number, number]; | ||
| if (g.type === "Polygon" && g.coordinates[0]?.[0]) { | ||
| return g.coordinates[0][0] as [number, number]; | ||
| } | ||
| if (g.type === "LineString" && g.coordinates[0]) { | ||
| return g.coordinates[0] as [number, number]; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| } | ||
| } catch { | ||
| // Ignore query errors | ||
| } | ||
|
|
||
| // 3. Fallback to GeoJSON features in store layers | ||
| const layer = useAppStore.getState().layers.find((l) => l.id === layerId); | ||
| if (layer?.geojson?.features) { | ||
| const feat = layer.geojson.features.find((f) => String(f.id) === String(featureId)); | ||
| if (feat?.geometry) { | ||
| const g = feat.geometry; | ||
| if (g.type === "Point") return g.coordinates as [number, number]; | ||
| if (g.type === "Polygon" && g.coordinates[0]?.[0]) { | ||
| return g.coordinates[0][0] as [number, number]; | ||
| } | ||
| if (g.type === "LineString" && g.coordinates[0]) { | ||
| return g.coordinates[0] as [number, number]; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| export function CommentMapOverlay({ | ||
| mapControllerRef, | ||
| onSelectComment, | ||
| showResolved = false, | ||
| }: CommentMapOverlayProps): null { | ||
| const comments = useAppStore((s) => s.comments); | ||
| const markersRef = useRef<maplibreGl.Marker[]>([]); | ||
|
|
||
| useEffect(() => { | ||
| const map = mapControllerRef.current?.getMap() ?? null; | ||
| if (!map) return; | ||
|
|
||
| const renderMarkers = () => { | ||
| // Clear existing markers | ||
| markersRef.current.forEach((m) => m.remove()); | ||
| markersRef.current = []; | ||
|
|
||
| comments.forEach((comment, idx) => { | ||
| if (comment.resolved && !showResolved) return; | ||
|
|
||
| const coords = resolveCommentCoordinates(comment, map); | ||
| if (!coords) return; | ||
|
|
||
| const pinColor = comment.author?.color || "#3b82f6"; | ||
|
|
||
| const container = document.createElement("div"); | ||
| container.className = | ||
| "group relative cursor-pointer select-none transition-transform duration-150 ease-out hover:scale-115"; | ||
| container.style.zIndex = comment.resolved ? "9" : "10"; | ||
|
HarshShinde0 marked this conversation as resolved.
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| // Build the pin with DOM APIs so the author color is set as a style | ||
| // property, never interpolated into markup — defense-in-depth against | ||
| // a hand-edited project file with a hostile color value. | ||
| const pin = document.createElement("div"); | ||
| pin.style.cssText = [ | ||
| "display:flex", | ||
| "align-items:center", | ||
| "justify-content:center", | ||
| "width:28px", | ||
| "height:28px", | ||
| "border-radius:50% 50% 50% 0", | ||
| "transform:rotate(-45deg)", | ||
| `border:2px solid ${comment.resolved ? "#10b981" : "#ffffff"}`, | ||
| "box-shadow:0 4px 10px rgba(0,0,0,0.35)", | ||
| `opacity:${comment.resolved ? 0.65 : 1}`, | ||
| ].join(";"); | ||
| pin.style.backgroundColor = pinColor; | ||
|
|
||
| const label = document.createElement("span"); | ||
| label.style.cssText = | ||
| "transform:rotate(45deg);color:#ffffff;font-size:11px;font-weight:700;font-family:system-ui,sans-serif;line-height:1"; | ||
| label.textContent = `#${idx + 1}`; | ||
| pin.appendChild(label); | ||
| container.appendChild(pin); | ||
|
|
||
| container.addEventListener("click", (e) => { | ||
| e.stopPropagation(); | ||
| onSelectComment?.(comment.id); | ||
| }); | ||
|
|
||
| const marker = new maplibreGl.Marker({ | ||
| element: container, | ||
| anchor: "bottom", | ||
| }) | ||
| .setLngLat(coords) | ||
| .addTo(map); | ||
|
|
||
| markersRef.current.push(marker); | ||
| }); | ||
| }; | ||
|
|
||
| renderMarkers(); | ||
|
|
||
| // Re-render when the style reloads (basemap switch wipes all markers). | ||
| // No moveend listener needed: MapLibre Marker objects are positioned in | ||
| // geographic space and track the map viewport automatically. | ||
| map.on("styledata", renderMarkers); | ||
|
|
||
| return () => { | ||
| map.off("styledata", renderMarkers); | ||
| markersRef.current.forEach((m) => m.remove()); | ||
| markersRef.current = []; | ||
| }; | ||
| }, [comments, showResolved, mapControllerRef, onSelectComment]); | ||
|
HarshShinde0 marked this conversation as resolved.
|
||
|
|
||
| return null; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.