Skip to content

Commit

Permalink
chore: eslint 스타일 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
xilucks committed Jul 20, 2024
1 parent ebfbd55 commit 5e16331
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
'use client'
"use client";

import { useKakaoAddress } from "~/app/(playground)/playground/map/_store/KakaoAdressStore";

export default function AddressSearchButton(){
export default function AddressSearchButton() {
const { coordinate, setCoordinate } = useKakaoAddress();
const handleClickButton = () => {
new window.daum.Postcode({
oncomplete: (addressData: any) => {
const geocoder = new window.kakao.maps.services.Geocoder();
geocoder.addressSearch(
addressData.address,
((result: any, status: any) => {
(result: any, status: any) => {
const currentPositions = new window.kakao.maps.LatLng(
result[0].y,
result[0].x
result[0].x,
);
setCoordinate(currentPositions.Ma, currentPositions.La)
})
)
}
setCoordinate(currentPositions.Ma, currentPositions.La);
},
);
},
}).open();
}
};

return <button onClick={handleClickButton} className={'border rounded-xl bg-blue-300 p-2 text-white bold'}>내 주소 찾기</button>
}
return (
<button
onClick={handleClickButton}
className={"bold rounded-xl border bg-blue-300 p-2 text-white"}
>
내 주소 찾기
</button>
);
}
31 changes: 17 additions & 14 deletions src/app/(playground)/playground/map/_components/KakaoMap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use client"
"use client";

import { useRef, useEffect } from "react";
import { useKakaoAddress } from "~/app/(playground)/playground/map/_store/KakaoAdressStore";
import { useEffect, useRef } from "react";
import type { Coordinate } from "~/app/(playground)/playground/map/_store/KakaoAdressStore";
import { useKakaoAddress } from "~/app/(playground)/playground/map/_store/KakaoAdressStore";

interface KakaoMapProps {
width: string;
Expand All @@ -12,29 +12,32 @@ interface KakaoMapProps {
}

export default function KakaoMap({
width,
height,
level = 3,
addCenterPin = false
}: KakaoMapProps) {
width,
height,
level = 3,
addCenterPin = false,
}: KakaoMapProps) {
const { coordinate, setCoordinate } = useKakaoAddress();
const mapRef = useRef<HTMLDivElement | null>(null);

const initializeMap = () => {
if (!mapRef.current) return;

window.kakao.maps.load(() => {
const { latitude, longitude }: Coordinate = coordinate
const { latitude, longitude }: Coordinate = coordinate;
const center = new window.kakao.maps.LatLng(latitude, longitude);
const mapOption = {
center: center,
level: level,
};
const map = new window.kakao.maps.Map(mapRef.current as HTMLElement, mapOption);
const map = new window.kakao.maps.Map(
mapRef.current as HTMLElement,
mapOption,
);

if (addCenterPin) {
const marker = new window.kakao.maps.Marker({
position: center
position: center,
});
marker.setMap(map);
}
Expand All @@ -49,7 +52,7 @@ export default function KakaoMap({

return (
<div style={{ width, height }}>
<div ref={mapRef} style={{ width: '100%', height: '100%' }} />
<div ref={mapRef} style={{ width: "100%", height: "100%" }} />
</div>
)
}
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { create } from 'zustand';
import { create } from "zustand";

export interface Coordinate {
latitude: number;
Expand All @@ -12,12 +12,13 @@ interface KakaoAddressStore {

const useKakaoAddressStore = create<KakaoAddressStore>((set) => ({
coordinate: { latitude: 37.566828, longitude: 126.9786567 },
setCoordinate: (latitude: number, longitude: number) => set({ coordinate: { latitude, longitude } }),
setCoordinate: (latitude: number, longitude: number) =>
set({ coordinate: { latitude, longitude } }),
}));

export const useKakaoAddress = () => {
const coordinate = useKakaoAddressStore((state) => state.coordinate);
const setCoordinate = useKakaoAddressStore((state) => state.setCoordinate);

return { coordinate, setCoordinate };
};
};
11 changes: 5 additions & 6 deletions src/app/(playground)/playground/map/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import Script from "next/script";

export default function KaKaoMapPageLayout({
children,
}: {
}: {
children: React.ReactNode;
}){

return(
}) {
return (
<>
<Script
strategy="beforeInteractive"
Expand All @@ -20,5 +19,5 @@ export default function KaKaoMapPageLayout({
/>
{children}
</>
)
}
);
}
11 changes: 4 additions & 7 deletions src/app/(playground)/playground/map/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import KakaoMap from "~/app/(playground)/playground/map/_components/KakaoMap";
import AddressSearchButton from "~/app/(playground)/playground/map/_components/AddressSearchButton";
import { useKakaoAddress } from "~/app/(playground)/playground/map/_store/KakaoAdressStore";

import KakaoMap from "~/app/(playground)/playground/map/_components/KakaoMap";

export default function KaKaoMapPage() {

return(
return (
<div>
<div>
<KakaoMap height={"400px"} width={"100%"} addCenterPin={true} />
<AddressSearchButton />
</div>
</div>
)
}
);
}
5 changes: 1 addition & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const metadata: Metadata = {
description: "당신의 환대, 초대장 플랫폼 '인비' 입니다.",
};


export default function RootLayout({
children,
}: Readonly<{
Expand All @@ -22,9 +21,7 @@ export default function RootLayout({
href="https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/variable/pretendardvariable-dynamic-subset.min.css"
/>
</head>
<body>
{children}
</body>
<body>{children}</body>
</html>
);
}

0 comments on commit 5e16331

Please sign in to comment.