Skip to content

Commit

Permalink
feat: result 페이지 경로 이탈 이슈 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhyojeong committed Jan 23, 2024
1 parent 10a0518 commit fae61bf
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/pages/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import type { SortOptionCodes, TradeTypeCodes } from '@types'
import { toQueryString, removeNullish } from '@utils'

const DEFAULT_POST_PAGE_NUMBER = 8
// TODO: 포스트 전체 갯수 내려달라고 요청해놓았습니다
const POST_COUNT_MOCK = 10

type ResultPageProps = {
keyword?: string
Expand Down Expand Up @@ -66,24 +68,31 @@ const ResultPage: NextPage = ({
...searchParams
})

// TODO: 포스트 전체 갯수 내려달라고 요청해놓았습니다
const postsCount = 10
const searchByResult = ({ priceRange, ...params }: SearchOptionsState) => {
router.push(
`/result?${toQueryString({
...params,
minPrice: priceRange.min,
maxPrice: priceRange.max
})}`
)
}

const handleChangeSearchOptions: OnChangeSearchOptions = (name, value) => {
const nextSearchOptions = {
const newSearchOptions = {
...searchOptions,
[name]: value
}
setSearchOptions(nextSearchOptions)

router.push(`/result?${toQueryString(searchParams)}`)
setSearchOptions(newSearchOptions)
searchByResult(newSearchOptions)
}

return (
<Layout>
<ResultWrapper>
<ResultHeader
postsCount={postsCount}
postsCount={POST_COUNT_MOCK}
resultMessage={`"${currentKeyword}"의 검색결과`}
/>
<PostSection
Expand All @@ -92,7 +101,7 @@ const ResultPage: NextPage = ({
hasNextPage: infinitePosts?.hasNextPage,
postData: infinitePosts.data?.pages
}}
postsCount={postsCount}
postsCount={POST_COUNT_MOCK}
searchOptions={searchOptions}
onChangeSearchOption={handleChangeSearchOptions}
/>
Expand Down

0 comments on commit fae61bf

Please sign in to comment.