-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat/#83] 리스트-맵 매장 관련 API 연동 #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
apps/customer/src/app/(tabs)/main/_apis/searchAddressByKakao.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| "use client"; | ||
|
|
||
| import type { AddressSearchItem } from "../_types/address-search"; | ||
|
|
||
| export function searchAddressByKakao( | ||
| keyword: string, | ||
| size = 10 | ||
| ): Promise<AddressSearchItem[]> { | ||
| return new Promise((resolve, reject) => { | ||
| const trimmedKeyword = keyword.trim(); | ||
|
|
||
| if (!trimmedKeyword) { | ||
| resolve([]); | ||
| return; | ||
| } | ||
|
|
||
| if ( | ||
| typeof window === "undefined" || | ||
| !window.kakao || | ||
| !window.kakao.maps || | ||
| !window.kakao.maps.services | ||
| ) { | ||
| reject(new Error("Kakao services library is not loaded.")); | ||
| return; | ||
| } | ||
|
|
||
| const geocoder = new window.kakao.maps.services.Geocoder(); | ||
|
|
||
| geocoder.addressSearch( | ||
| trimmedKeyword, | ||
| (result: KakaoAddressSearchResult[], status: string) => { | ||
| const { kakao } = window; | ||
|
|
||
| if (status === kakao.maps.services.Status.ZERO_RESULT) { | ||
| resolve([]); | ||
| return; | ||
| } | ||
|
|
||
| if (status !== kakao.maps.services.Status.OK) { | ||
| reject(new Error("주소 검색 중 오류가 발생했습니다.")); | ||
| return; | ||
| } | ||
|
|
||
| const mapped = result.slice(0, size).map( | ||
| (item: KakaoAddressSearchResult, index: number) => { | ||
| const lotNumberAddress = | ||
| item.address?.address_name || item.address_name || ""; | ||
|
|
||
| const roadAddress = | ||
| item.road_address?.address_name || item.address_name || ""; | ||
|
|
||
| return { | ||
| id: `${item.x}-${item.y}-${index}`, | ||
| label: roadAddress || lotNumberAddress, | ||
| lotNumberAddress, | ||
| roadAddress, | ||
| longitude: Number(item.x), | ||
| latitude: Number(item.y), | ||
| }; | ||
| } | ||
| ); | ||
|
|
||
| resolve(mapped); | ||
| }, | ||
| { | ||
| page: 1, | ||
| size, | ||
| analyze_type: window.kakao.maps.services.AnalyzeType.SIMILAR, | ||
| } | ||
| ); | ||
| }); | ||
| } |
146 changes: 146 additions & 0 deletions
146
apps/customer/src/app/(tabs)/main/_components/AddressSearchBottomSheet.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| "use client"; | ||
|
|
||
| import { useEffect, useRef, useState } from "react"; | ||
| import { BottomSheet, Input, Icon } from "@compasser/design-system"; | ||
| import type { AddressSearchItem } from "../_types/address-search"; | ||
| import { searchAddressByKakao } from "../_apis/searchAddressByKakao"; | ||
|
|
||
| interface AddressSearchBottomSheetProps { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| onSelectAddress: (item: AddressSearchItem) => void; | ||
| } | ||
|
|
||
| export default function AddressSearchBottomSheet({ | ||
| open, | ||
| onClose, | ||
| onSelectAddress, | ||
| }: AddressSearchBottomSheetProps) { | ||
| const [keyword, setKeyword] = useState(""); | ||
| const [results, setResults] = useState<AddressSearchItem[]>([]); | ||
| const [isSearching, setIsSearching] = useState(false); | ||
|
|
||
| const debounceRef = useRef<number | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| if (!open) { | ||
| setKeyword(""); | ||
| setResults([]); | ||
| setIsSearching(false); | ||
| } | ||
| }, [open]); | ||
|
|
||
| useEffect(() => { | ||
| if (!open) { | ||
| return; | ||
| } | ||
|
|
||
| const trimmedKeyword = keyword.trim(); | ||
|
|
||
| if (!trimmedKeyword) { | ||
| setResults([]); | ||
| setIsSearching(false); | ||
| return; | ||
| } | ||
|
|
||
| if (debounceRef.current) { | ||
| window.clearTimeout(debounceRef.current); | ||
| } | ||
|
|
||
| debounceRef.current = window.setTimeout(async () => { | ||
| try { | ||
| setIsSearching(true); | ||
| const searched = await searchAddressByKakao(trimmedKeyword, 10); | ||
| setResults(searched); | ||
| } catch (error) { | ||
| console.error(error); | ||
| setResults([]); | ||
| } finally { | ||
| setIsSearching(false); | ||
| } | ||
| }, 250); | ||
|
|
||
| return () => { | ||
| if (debounceRef.current) { | ||
| window.clearTimeout(debounceRef.current); | ||
| } | ||
| }; | ||
| }, [keyword, open]); | ||
|
|
||
| const handleQuickSelect = () => { | ||
| onSelectAddress({ | ||
| id: "catholic-univ", | ||
| label: "가톨릭대 주변 탐색", | ||
| lotNumberAddress: "경기도 부천시 원미구 역곡동 일대", | ||
| roadAddress: "가톨릭대학교 성심교정 주변", | ||
| longitude: 126.8016, | ||
| latitude: 37.4875, | ||
| }); | ||
| }; | ||
|
|
||
| const handleSelectItem = (item: AddressSearchItem) => { | ||
| onSelectAddress(item); | ||
| }; | ||
|
|
||
| return ( | ||
| <BottomSheet | ||
| open={open} | ||
| onClose={onClose} | ||
| variant="default" | ||
| overlay | ||
| closeOnOverlayClick | ||
| showHandle | ||
| className="w-full" | ||
| contentClassName="px-[1.6rem] pt-[0.8rem] pb-[2rem]" | ||
| > | ||
| <Input | ||
| inputStyle="address" | ||
| value={keyword} | ||
| onChange={(event) => setKeyword(event.target.value)} | ||
| placeholder="위치 입력" | ||
| /> | ||
|
|
||
| <button | ||
| type="button" | ||
| onClick={handleQuickSelect} | ||
| className="ml-[0.6rem] mt-[1rem] inline-flex items-center rounded-[999px] border border-secondary-variant px-[0.8rem] py-[0.2rem]" | ||
| > | ||
| <Icon | ||
| name="Pin" | ||
| width={20} | ||
| height={20} | ||
| className="mr-[0.4rem]" | ||
| /> | ||
| <span className="body2-r text-default">가톨릭대 주변 탐색</span> | ||
| </button> | ||
|
|
||
| {results.length > 0 && ( | ||
| <div className="mt-[1.2rem] max-h-[32rem] overflow-y-auto"> | ||
| {results.map((item) => ( | ||
| <button | ||
| key={item.id} | ||
| type="button" | ||
| onClick={() => handleSelectItem(item)} | ||
| className="block w-full border-b border-gray-100 px-[0.6rem] pt-[0.6rem] pb-[0.8rem] text-left" | ||
| > | ||
| <p className="body2-r text-default">{item.lotNumberAddress}</p> | ||
| <p className="caption1-r text-gray-500">{item.roadAddress}</p> | ||
| </button> | ||
| ))} | ||
| </div> | ||
| )} | ||
|
|
||
| {keyword.trim() && isSearching && ( | ||
| <p className="mt-[1.2rem] px-[0.6rem] text-center caption1-r text-gray-500"> | ||
| 검색 중... | ||
| </p> | ||
| )} | ||
|
|
||
| {keyword.trim() && !isSearching && results.length === 0 && ( | ||
| <p className="mt-[1.2rem] px-[0.6rem] text-center caption1-r text-gray-500"> | ||
| 검색 결과가 없습니다. | ||
| </p> | ||
| )} | ||
| </BottomSheet> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 136
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 3180
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 125
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 1772
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 87
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 87
🏁 Script executed:
Repository: CUK-Compasser/FE
Length of output: 532
🏁 Script executed:
rg "debounce|setIsSearching" apps/customer/src --max-count 20Repository: CUK-Compasser/FE
Length of output: 1331
검색 응답 경쟁 상태(race condition) 방어가 필요합니다.
Line 50-60의 비동기 API 호출에서 이전 요청의 응답이 늦게 도착하면 최신 키워드 결과를 덮어쓸 수 있습니다. 사용자가 "A" 검색 후 "B"를 검색할 때 "A"의 응답이 "B"의 응답보다 나중에 도착하면 잘못된 결과가 표시됩니다. 또한 시트를 닫은 직후에도 이전 요청의 응답으로 상태가 갱신될 수 있습니다. 요청 식별자 또는 취소 플래그를 사용하여 최신 요청만 반영해 주세요.
제안 코드
🤖 Prompt for AI Agents