diff --git a/apps/geolibre-desktop/src/components/comments/AddCommentDialog.tsx b/apps/geolibre-desktop/src/components/comments/AddCommentDialog.tsx new file mode 100644 index 000000000..03e2f6b2f --- /dev/null +++ b/apps/geolibre-desktop/src/components/comments/AddCommentDialog.tsx @@ -0,0 +1,176 @@ +import { useState } from "react"; +import { useTranslation } from "react-i18next"; +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 { t } = useTranslation(); + const [savedName, setSavedName] = useState(() => { + try { + return typeof localStorage !== "undefined" + ? localStorage.getItem("geolibre_author_name") + : null; + } catch { + return null; + } + }); + const hasSavedName = !!savedName && savedName.trim().length > 0; + + const [text, setText] = useState(""); + const [authorName, setAuthorName] = useState(savedName ?? ""); + + 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); + setSavedName(finalName); + } catch { + // ignore storage errors + } + } + + onSubmit(text.trim(), finalName); + setText(""); + }; + + const anchor = pendingComment.anchor; + const lngLat = anchor.lngLat; + + return ( + { + if (!open) onCancel(); + }} + > + + + + + {t("comments.addDialogTitle")} + + + {t("comments.addDialogDescription")} + + + +
+
+ {anchor.type === "feature" ? ( + <> + + + Anchored to Feature #{String(anchor.featureId)} ({anchor.layerId}) + + + ) : ( + <> + + + Anchored to ( + {lngLat ? `${lngLat[1].toFixed(4)}, ${lngLat[0].toFixed(4)}` : "Map Point"}) + + + )} +
+ + {/* Prompt for name 1 time if not saved in localStorage */} + {!hasSavedName ? ( +
+ + setAuthorName(e.target.value)} + placeholder={t("comments.authorNamePlaceholder")} + className="text-xs h-8" + autoFocus + /> +
+ ) : ( +
+ + Posting as {savedName} + + +
+ )} + +
+ +