diff --git a/apps/admin/src/app/requests/[id]/_components/Location/Location.tsx b/apps/admin/src/app/requests/[id]/_components/Location/Location.tsx index 2f3a97c..b7d49c7 100644 --- a/apps/admin/src/app/requests/[id]/_components/Location/Location.tsx +++ b/apps/admin/src/app/requests/[id]/_components/Location/Location.tsx @@ -17,7 +17,12 @@ export const Location = ({ location }: Props) => { 위치 - + diff --git a/apps/web/app/_store/prevMapCenter.ts b/apps/web/app/_store/prevMapCenter.ts new file mode 100644 index 0000000..5c97819 --- /dev/null +++ b/apps/web/app/_store/prevMapCenter.ts @@ -0,0 +1,12 @@ +import { create } from 'zustand' +import { Coord } from '@/map/_utils/toLatLng' + +type LastMapCenter = { + lastMapCenter: Coord | null + setLastMapCenter: (mapCenter: Coord) => void +} + +export const useLastMapCenterStore = create((set) => ({ + lastMapCenter: null, + setLastMapCenter: (mapCenter: Coord) => set({ lastMapCenter: mapCenter }), +})) diff --git a/apps/web/app/map/MapComponent.tsx b/apps/web/app/map/MapComponent.tsx index 866b6cd..dd5fc36 100644 --- a/apps/web/app/map/MapComponent.tsx +++ b/apps/web/app/map/MapComponent.tsx @@ -6,6 +6,7 @@ import { Container, NaverMap } from 'react-naver-maps' import { CAMPUS_LOCATION } from '@/_constants/campus' import { useCampusStore } from '@/_store/campus' +import { useLastMapCenterStore } from '@/_store/prevMapCenter' import { usePlaceQueries } from '@/_apis/queries/place' import type { MapBounds } from '@/_apis/schemas/place' @@ -27,9 +28,11 @@ const MapComponent = () => { const [showUpdateButton, setShowUpdateButton] = useState(false) const { campus } = useCampusStore() + const { lastMapCenter, setLastMapCenter } = useLastMapCenterStore() const { userLocation } = useWatchLocation() const { data = [] } = useQuery(usePlaceQueries.byMap(currentBounds)) + const defaultCenter = toLatLng(lastMapCenter || CAMPUS_LOCATION[campus]) const previewPlace = previewPlaceId ? data.find((place) => place.placeId === previewPlaceId)! : null @@ -77,6 +80,14 @@ const MapComponent = () => { } useEffect(refreshMapBounds, [refreshMapBounds]) + useEffect(() => { + return () => { + if (!map) return + const { x: longitude, y: latitude } = map.getCenter() + + setLastMapCenter({ longitude, latitude }) + } + }, [map, setLastMapCenter]) return ( <> @@ -96,8 +107,10 @@ const MapComponent = () => { onMouseUp={onCenterChanged} > {userLocation && } diff --git a/apps/web/app/map/_components/PreviewPlace/PreviewPlace.tsx b/apps/web/app/map/_components/PreviewPlace/PreviewPlace.tsx index a879262..d96dd08 100644 --- a/apps/web/app/map/_components/PreviewPlace/PreviewPlace.tsx +++ b/apps/web/app/map/_components/PreviewPlace/PreviewPlace.tsx @@ -35,7 +35,7 @@ export const PreviewPlace = ({ place }: { place: PlaceByMap }) => { {address} - {photos.map((photo) => ( + {photos.slice(0, 5).map((photo) => ( { - +