Skip to content

Commit

Permalink
feat: 회원가입 동네인증 페이지 완료 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
OpenS3same committed Nov 29, 2024
1 parent b1ba90d commit 8e45c7c
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/components/common/KakaoMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ type KakaoMapProps = {
latitude: number;
longitude: number;
appKey: string;
width: number;
};

const KakaoMap: React.FC<KakaoMapProps> = ({ latitude, longitude, appKey }) => {
const KakaoMap: React.FC<KakaoMapProps> = ({
latitude,
longitude,
appKey,
width,
}) => {
const mapContainer = useRef<HTMLDivElement>(null);

useEffect(() => {
Expand Down Expand Up @@ -40,7 +46,7 @@ const KakaoMap: React.FC<KakaoMapProps> = ({ latitude, longitude, appKey }) => {
<div
ref={mapContainer}
style={{
width: '600px',
width: `${width}px`,
height: '350px',
}}
></div>
Expand Down
76 changes: 73 additions & 3 deletions src/components/pages/login/SetLocationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import styled from 'styled-components';
import KakaoMap from '../../common/KakaoMap';

function SetLocationPage() {
const navigate = useNavigate();
const [location, setLocation] = useState<{
latitude: number;
longitude: number;
} | null>(null);
const [region, setRegion] = useState<string | null>(null);
const [called, setCalled] = useState<boolean>(false);

useEffect(() => {
if (navigator.geolocation && !called) {
navigator.geolocation.getCurrentPosition(
(position) => {
const { latitude, longitude } = position.coords;
setLocation({ latitude, longitude });

if (window.kakao) {
const geocoder = new window.kakao.maps.services.Geocoder();

geocoder.coord2RegionCode(
longitude,
latitude,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(result: any, status: any) => {
if (status === window.kakao.maps.services.Status.OK) {
const primaryRegion = result[0]?.region_3depth_name || '';
setRegion(primaryRegion);
setCalled(true);
} else {
console.error('주소를 가져오지 못했습니다.');
}
}
);
}
},
(error) => {
console.error('위치 정보를 가져올 수 없습니다:', error);
}
);
}
}, [location]);

return (
<Wrapper>
<LeftContent>
Expand All @@ -13,7 +54,7 @@ function SetLocationPage() {
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectFit: 'cover',
}}
/>
</LeftContent>
Expand All @@ -25,6 +66,22 @@ function SetLocationPage() {
</Title>
<Subtitle>위치서비스를 허용해주세요</Subtitle>

<KakaoMapWrapper>
{location ? (
<KakaoMap
latitude={location.latitude}
longitude={location.longitude}
appKey={import.meta.env.VITE_KAKAO_KEY} // 카카오 JavaScript 키
width={400}
/>
) : (
<p>위치 정보를 불러오는 중...</p>
)}
<AddressDesc>
현재 위치가 내 동네로 설정한 {region || '00동'}에 있습니다.
</AddressDesc>
</KakaoMapWrapper>

<LoginButton
onClick={() => {
navigate('/setnickname');
Expand All @@ -37,6 +94,20 @@ function SetLocationPage() {
);
}

const AddressDesc = styled.div`
color: #88868c;
`;

const KakaoMapWrapper = styled.div`
display: inline-flex;
align-items: center;
justify-content: center;
width: 100%;
flex-direction: column;
gap: 20px;
margin-top: 20px;
`;

const LoginButton = styled.div`
background-color: #000;
color: #fff;
Expand All @@ -62,7 +133,6 @@ const Title = styled.div`
`;
const LeftContent = styled.div`
flex: 6;
background-color: #fff;
display: flex;
align-items: center;
justify-content: center;
Expand Down
1 change: 1 addition & 0 deletions src/components/pages/myPage/LocationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function LocationPage() {
latitude={location.latitude}
longitude={location.longitude}
appKey={import.meta.env.VITE_KAKAO_KEY} // 카카오 JavaScript 키
width={600}
/>
) : (
<p>위치 정보를 불러오는 중...</p>
Expand Down

0 comments on commit 8e45c7c

Please sign in to comment.