diff --git a/src/pages/map/components/Map.tsx b/src/pages/map/components/Map.tsx index 1da48fd9..f083959b 100644 --- a/src/pages/map/components/Map.tsx +++ b/src/pages/map/components/Map.tsx @@ -7,7 +7,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-use-before-define */ /* eslint-disable no-new */ -import { useEffect, useRef } from 'react'; +import { useState, useEffect, useRef } from 'react'; import MapList from './MapList'; import useMap from '../useMap'; @@ -19,8 +19,9 @@ declare global { const Map = () => { const mapRef = useRef(null); + const [loading, setLoading] = useState(true); const { map, displayMarkerByInfo, searchedPlace, mutate, mutateData } = - useMap(mapRef); + useMap(mapRef, setLoading); useEffect(() => { mutate(searchedPlace); }, [searchedPlace]); @@ -41,8 +42,11 @@ const Map = () => { return (
+ {loading && ( +
+ )}
- +
); }; diff --git a/src/pages/map/components/MapList.tsx b/src/pages/map/components/MapList.tsx index aa1c0af8..b2b28210 100644 --- a/src/pages/map/components/MapList.tsx +++ b/src/pages/map/components/MapList.tsx @@ -6,10 +6,12 @@ import { SearchedPlace } from '../mapType'; const MapList = ({ searchedPlace, map, + loading, }: { searchedPlace: SearchedPlace[]; // eslint-disable-next-line @typescript-eslint/no-explicit-any map: any; + loading: boolean; }) => { const { kakao } = window; const navigate = useNavigate(); @@ -30,48 +32,51 @@ const MapList = ({ }); return ( -
- {searchedPlace.map((place) => ( -
{ - const moveLatLon = new kakao.maps.LatLng( - parseFloat(place.y), - parseFloat(place.x), - ); - map.setCenter(moveLatLon); - }} - onClick={() => { - if (place.isRegistered) { - navigate(`/shelter/${place.shelterId}/1`); - } else { - setUnRegisteredClick(true); - setTimeout(() => { - setUnRegisteredClick(false); - }, 1000); - } - }} - className={`${ - !place.isRegistered && unRegisteredClick - ? 'bg-red-200 ' - : 'bg-white hover:bg-gray-100 ' - } cursor-pointer border rounded-md p-4 mb-2 transition duration-300 ease-in-out`} - > - {place.isRegistered && ( -
- {`애니모리 등록 보호소`} -
- )} -
{place.place_name}
-
{place.road_address_name}
-
- ))} - {unRegisteredClick && ( -
- 등록되지 않은 보호소는 클릭할 수 없습니다. -
- )} -
+ <> + {loading &&
} +
+ {searchedPlace.map((place) => ( +
{ + const moveLatLon = new kakao.maps.LatLng( + parseFloat(place.y), + parseFloat(place.x), + ); + map.setCenter(moveLatLon); + }} + onClick={() => { + if (place.isRegistered) { + navigate(`/shelter/${place.shelterId}/1`); + } else { + setUnRegisteredClick(true); + setTimeout(() => { + setUnRegisteredClick(false); + }, 1000); + } + }} + className={`${ + !place.isRegistered && unRegisteredClick + ? 'bg-red-200 ' + : 'bg-white hover:bg-gray-100 ' + } cursor-pointer border rounded-md p-4 mb-2 transition duration-300 ease-in-out`} + > + {place.isRegistered && ( +
+ {`애니모리 등록 보호소`} +
+ )} +
{place.place_name}
+
{place.road_address_name}
+
+ ))} + {unRegisteredClick && ( +
+ 등록되지 않은 보호소는 클릭할 수 없습니다. +
+ )} +
+ ); }; diff --git a/src/pages/map/useMap.ts b/src/pages/map/useMap.ts index 45d67caf..aa86e173 100644 --- a/src/pages/map/useMap.ts +++ b/src/pages/map/useMap.ts @@ -6,6 +6,7 @@ import { SearchedPlace } from './mapType'; function useMap( containerRef: RefObject, + setLoading: React.Dispatch>, ) { const { kakao } = window; const [map, setMap] = useState(); @@ -29,6 +30,7 @@ function useMap( }).then((res) => res.json()), { onSuccess: (data) => { + setLoading(false); if (data.success === false) { throw new Error(data.error.message); }