37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
"use client";
|
|
|
|
import { useCallback, useEffect, useState, useSyncExternalStore, type ComponentProps } from "react";
|
|
import { getMapSearchRevision, invalidateMapNavigation, subscribeMapSearch } from "@/features/map-search/lib/map-navigation";
|
|
import { ProcSearchBar } from "@common/business_components/ui/map/searchBar";
|
|
|
|
/** 지도 검색바의 Radix Select는 브라우저 마운트 이후 생성한다.
|
|
* 서버와 최초 클라이언트 렌더는 동일한 자리표시자를 사용하여 aria-controls ID의
|
|
* hydration 불일치를 피한다. 공통 Select 및 다른 앱의 렌더링 방식은 변경하지 않는다.
|
|
*/
|
|
export default function MapSearchBar(props: ComponentProps<typeof ProcSearchBar>) {
|
|
/** 부모의 지도 준비 렌더에 맞춰 해당 인스턴스만 구독한다. */
|
|
const map = props.gisMaps.current;
|
|
const subscribe = useCallback((listener: () => void) => subscribeMapSearch(map, listener), [map]);
|
|
const getSnapshot = useCallback(() => getMapSearchRevision(map), [map]);
|
|
const resetRevision = useSyncExternalStore(subscribe, getSnapshot, () => 0);
|
|
useEffect(() => () => invalidateMapNavigation(map), [map]);
|
|
const [isMounted, setIsMounted] = useState(false);
|
|
|
|
useEffect(() => {
|
|
setIsMounted(true);
|
|
}, []);
|
|
|
|
if (!isMounted) {
|
|
return (
|
|
<div
|
|
className="h-[44px] w-[656px] rounded-[8px] bg-form"
|
|
role="status"
|
|
aria-label="지도 검색조건 준비 중"
|
|
aria-busy="true"
|
|
/>
|
|
);
|
|
}
|
|
|
|
return <ProcSearchBar {...props} resetRevision={resetRevision} onSearchInteraction={() => invalidateMapNavigation(map)} />;
|
|
}
|