From b00df8a9d18d517bbf7eb3a1c7cf3dee91ab3a43 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 28 Oct 2025 21:28:29 +0800 Subject: [PATCH] fix(web): remove error notifications for location geocoding failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove disruptive error toasts when reverse geocoding or geolocation fails. Instead, silently fall back to using coordinates as the location placeholder. This improves UX for users in regions where OpenStreetMap is restricted (e.g., China) or when CSP blocks external API calls. Fixes #5198, #5197 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../ActionButton/LocationSelector.tsx | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/web/src/components/MemoEditor/ActionButton/LocationSelector.tsx b/web/src/components/MemoEditor/ActionButton/LocationSelector.tsx index b02a2ccdc..8ae7cebe8 100644 --- a/web/src/components/MemoEditor/ActionButton/LocationSelector.tsx +++ b/web/src/components/MemoEditor/ActionButton/LocationSelector.tsx @@ -1,7 +1,6 @@ import { LatLng } from "leaflet"; import { MapPinIcon, XIcon } from "lucide-react"; import { useEffect, useState } from "react"; -import toast from "react-hot-toast"; import LeafletMap from "@/components/LeafletMap"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -48,10 +47,9 @@ const LocationSelector = (props: Props) => { useEffect(() => { if (popoverOpen && !props.location) { - const handleError = (error: any, errorMessage: string) => { + const handleError = (error: any) => { setState((prev) => ({ ...prev, initialized: true })); - toast.error(errorMessage); - console.error(error); + console.error("Geolocation error:", error); }; if (navigator.geolocation) { @@ -68,11 +66,11 @@ const LocationSelector = (props: Props) => { })); }, (error) => { - handleError(error, "Failed to get current position"); + handleError(error); }, ); } else { - handleError("Geolocation is not supported by this browser.", "Geolocation is not supported by this browser."); + handleError("Geolocation is not supported by this browser."); } } }, [popoverOpen, props.location]); @@ -91,16 +89,29 @@ const LocationSelector = (props: Props) => { } // Fetch reverse geocoding data. - fetch(`https://nominatim.openstreetmap.org/reverse?lat=${state.position.lat}&lon=${state.position.lng}&format=json`) + const lat = state.position.lat; + const lng = state.position.lng; + + fetch(`https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lng}&format=json`) .then((response) => response.json()) .then((data) => { if (data && data.display_name) { setState((prev) => ({ ...prev, placeholder: data.display_name })); + } else { + // Fallback to coordinates if no display name + setState((prev) => ({ + ...prev, + placeholder: `${lat.toFixed(6)}, ${lng.toFixed(6)}`, + })); } }) .catch((error) => { - toast.error("Failed to fetch reverse geocoding data"); + // Silent fallback: use coordinates as placeholder when geocoding fails console.error("Failed to fetch reverse geocoding data:", error); + setState((prev) => ({ + ...prev, + placeholder: `${lat.toFixed(6)}, ${lng.toFixed(6)}`, + })); }); }, [state.position]);