Skip to content

Commit

Permalink
Merge pull request #175 from ShinChanU/fix/rental-bug
Browse files Browse the repository at this point in the history
fix: 대여소 위치 페이지 컴포넌트 에러 수정
  • Loading branch information
LeeJSYS authored Oct 4, 2023
2 parents b01bebc + 1576a2e commit 43242df
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/components/pages/RentalLocation/RentalLocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const RentalInfo = () => {
const [markers, setMarkers] = useState<naver.maps.Marker[]>([]);
const [userPosition, setUserPosition] = useState<{ lat: number; lng: number } | null>(null);
const [isBottomOpen, setIsBottomOpen] = useState(false);
const [showInitialCard, setShowInitialCard] = useState(true);

// server
const { data: classificationsRes } = useGetClassifications();
Expand Down Expand Up @@ -120,17 +121,17 @@ const RentalInfo = () => {
]);

useEffect(() => {
if (storeMarker.data && storeMarker.data.length > 0 && showInitialCard) {
const randomIndex = Math.floor(Math.random() * storeMarker.data.length);
const randomStore = storeMarker.data[randomIndex].id;
if (storeListRes && storeListRes.length > 0 && showInitialCard) {
const randomIndex = Math.floor(Math.random() * storeListRes.length);
const randomStore = storeListRes[randomIndex].id;
setSelectedStoreId(randomStore);
setShowInitialCard(false);
}
}, [storeMarker.data, showInitialCard]);
}, [storeListRes, showInitialCard]);

useEffect(() => {
if (userPosition && storeMarker.data && storeMarker.data.length > 0) {
const distances = storeMarker.data.map((store) =>
if (userPosition && storeListRes && storeListRes.length > 0) {
const distances = storeListRes.map((store) =>
getDistanceFromLatLonInKm(
userPosition.lat,
userPosition.lng,
Expand All @@ -142,10 +143,10 @@ const RentalInfo = () => {
const minDistanceIndex = distances.indexOf(Math.min(...distances));

if (!showInitialCard) {
setSelectedStoreId(storeMarker.data[minDistanceIndex].id);
setSelectedStoreId(storeListRes[minDistanceIndex].id);
}
}
}, [userPosition, storeMarker.data, showInitialCard]);
}, [userPosition, storeListRes, showInitialCard]);

useEffect(() => {
getUserPosition().then(
Expand Down Expand Up @@ -181,7 +182,6 @@ const RentalInfo = () => {
}
}, [storeListRes, userPosition]);


return (
<div className="flex flex-col mt-24">
<div className="flex justify-center">
Expand Down

0 comments on commit 43242df

Please sign in to comment.