diff --git a/src/components/map/MapSearchResult.tsx b/src/components/map/MapSearchResult.tsx index eb11db9..6b289fb 100644 --- a/src/components/map/MapSearchResult.tsx +++ b/src/components/map/MapSearchResult.tsx @@ -7,6 +7,7 @@ import { MapSearchResultProps } from '@/api/types/branch'; const MapSearchResult: React.FC = ({ onClose, results, onMarkerClick, currentLatitude, currentLongitude }) => { const [searchTerm, setSearchTerm] = useState(''); const inputRef = useRef(null); + const [locationSet, setLocationSet] = useState(false); useEffect(() => { if (inputRef.current) { @@ -14,17 +15,24 @@ const MapSearchResult: React.FC = ({ onClose, results, onM } }, []); + useEffect(() => { + setLocationSet(currentLatitude !== 37.4979 || currentLongitude !== 127.0276); + }, [currentLatitude, currentLongitude]); + const filteredResults = results .filter(branch => branch.branchName.includes(searchTerm)) .sort((a, b) => { - const distanceA = calculateDistance(currentLatitude, currentLongitude, a.branchLatitude, a.branchLongitude); - const distanceB = calculateDistance(currentLatitude, currentLongitude, b.branchLatitude, b.branchLongitude); - return distanceA - distanceB; + if (locationSet) { + const distanceA = calculateDistance(currentLatitude, currentLongitude, a.branchLatitude, a.branchLongitude); + const distanceB = calculateDistance(currentLatitude, currentLongitude, b.branchLatitude, b.branchLongitude); + return distanceA - distanceB; + } + return 0; }); const handleItemClick = (branch: Branch) => { onMarkerClick(branch); - onClose(); + onClose(); }; return ( @@ -58,7 +66,11 @@ const MapSearchResult: React.FC = ({ onClose, results, onM
  • handleItemClick(branch)}> Location {branch.branchName} - {formatDistance(calculateDistance(currentLatitude, currentLongitude, branch.branchLatitude, branch.branchLongitude))} + {locationSet && ( + + {formatDistance(calculateDistance(currentLatitude, currentLongitude, branch.branchLatitude, branch.branchLongitude))} + + )}
  • ))}