diff --git a/src/apis/map/index.ts b/src/apis/map/index.ts index e8ebb07..f3bd69b 100644 --- a/src/apis/map/index.ts +++ b/src/apis/map/index.ts @@ -1,9 +1,10 @@ import Axios from '..'; -export const fetchMapMarker = () => () => +export const fetchMapMarker = (searchFilter: string) => () => Axios.get('/programs/filters', { params: { orderCriteria: '최신순', + location: searchFilter, size: 100, }, }); diff --git a/src/components/PageBar/PageBar.tsx b/src/components/PageBar/PageBar.tsx index 73eb3bf..a8bb3a0 100644 --- a/src/components/PageBar/PageBar.tsx +++ b/src/components/PageBar/PageBar.tsx @@ -52,7 +52,12 @@ const PageBar: React.FC = ({ page, setPage, maxPage }) => { <> {maxPage > 0 && ( - + { + setPage(1); + }} + /> movePage('prev')} @@ -73,7 +78,12 @@ const PageBar: React.FC = ({ page, setPage, maxPage }) => { className="icon" onClick={() => movePage('next')} /> - + { + setPage(maxPage); + }} + /> )} diff --git a/src/functions/index.ts b/src/functions/index.ts index 149119e..3bb9927 100644 --- a/src/functions/index.ts +++ b/src/functions/index.ts @@ -9,3 +9,14 @@ export const handleClickSearchProgram = ( navigate(`/search?keyword=${searchInput}`); setSearchInput(''); }; + +export const handleClickSearchMap = ( + searchInput: string, + setSearchInput: React.Dispatch>, + setSearhFilter: React.Dispatch>, +) => { + // 검색 후 페이지 이동 + console.log(searchInput); + setSearhFilter(searchInput); + setSearchInput(''); +}; diff --git a/src/pages/board/Board.tsx b/src/pages/board/Board.tsx index b494c76..b093bd3 100644 --- a/src/pages/board/Board.tsx +++ b/src/pages/board/Board.tsx @@ -108,7 +108,7 @@ const Container = styled.div` width: 1400px; margin: 0 auto 128px; - + body:not(&) { background-color: white; } diff --git a/src/pages/map/Map.tsx b/src/pages/map/Map.tsx index 9d723e3..ea0f3b8 100644 --- a/src/pages/map/Map.tsx +++ b/src/pages/map/Map.tsx @@ -1,6 +1,6 @@ import { Map, MarkerClusterer } from 'react-kakao-maps-sdk'; import CustomMarker from './components/CustomMarker'; -import { useEffect, useRef, useState } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import MapCard from './components/MapCard'; import styled from 'styled-components'; import SearchBar from '@/components/SearchBar/SearchBar'; @@ -8,8 +8,7 @@ import useOnClickOutside from '@/hooks/useOnClickOutside'; import { useQuery } from 'react-query'; import { fetchMapMarker } from '@/apis/map'; import Loading from '@/components/Loading/Loading'; -import { handleClickSearchProgram } from '@/functions'; -import { useNavigate } from 'react-router-dom'; +import { handleClickSearchMap } from '@/functions'; interface markerDataType { id: number; @@ -24,20 +23,24 @@ interface markerDataType { const MapPage = () => { const [selected, setSelected] = useState(-1); const [isModalOpen, setIsModalOpen] = useState(false); - const [searchInput, setSearchInput] = useState(''); + const [searchInput, setSearchInput] = useState(''); + const [searchFilter, setSearchFilter] = useState(''); const { isLoading, data, refetch } = useQuery( - ['marker', selected], - fetchMapMarker(), + ['marker', selected, searchFilter], + fetchMapMarker(searchFilter), { cacheTime: 500005, staleTime: 500000, }, ); - const navigate = useNavigate(); const cardRef = useRef(null); + const handleClickSearch = useCallback(() => { + handleClickSearchMap(searchInput, setSearchInput, setSearchFilter); + }, [searchInput, searchFilter]); + useOnClickOutside(cardRef, () => { setIsModalOpen(false); setSelected(-1); @@ -74,16 +77,14 @@ const MapPage = () => { searchInput={searchInput} setSearchInput={setSearchInput} placeHolder="관심있는 여행지가 있으신가요?" - handleSubmit={() => - handleClickSearchProgram(searchInput, setSearchInput, navigate) - } + handleSubmit={handleClickSearch} /> {markerData?.map(({ latitude: lat, longitude: lng, id }, idx) => (