From 10ff50851ec9ea21236a9ce47dce12b97da364da Mon Sep 17 00:00:00 2001 From: hjiwon Date: Fri, 10 Nov 2023 17:32:19 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=A7=B5=20=EB=A1=9C=EB=8D=94=20?= =?UTF-8?q?=EB=B6=80=ED=99=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/map/components/Map.tsx | 10 +++- src/pages/map/components/MapList.tsx | 89 +++++++++++++++------------- src/pages/map/useMap.ts | 2 + 3 files changed, 56 insertions(+), 45 deletions(-) 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); }