Skip to content

Commit

Permalink
feat : 정렬 토글 버튼 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujin-Baek committed Nov 27, 2023
1 parent 0ade648 commit c18be56
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
5 changes: 4 additions & 1 deletion frontend/src/app/recruitment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
multiplefilterState,
keywordfilterState,
recruitfilterState,
directionState,
} from '../../utils/atoms'
import Filter from '../../components/recruitment/main/Filter'
import RecruitmentCard from '../../components/recruitment/main/RecruitmentCard'
Expand All @@ -29,6 +30,7 @@ export default function Recruitment() {
const multipleFilter = useRecoilValue(multiplefilterState)
const keywordFilter = useRecoilValue(keywordfilterState)
const recruitFilter = useRecoilValue(recruitfilterState)
const direction = useRecoilValue(directionState)

const [postCount, setPostCount] = useState(0)
const router = useRouter()
Expand All @@ -41,6 +43,7 @@ export default function Recruitment() {
const params = new URLSearchParams()
params.set('page', String(pageParam))
params.set('size', '12')
params.set('direction', direction)

const positions = multipleFilter
.filter((v) => v.category === 'position')
Expand Down Expand Up @@ -86,7 +89,7 @@ export default function Recruitment() {

const { data, fetchNextPage, hasNextPage, isFetchingNextPage, status } =
useInfiniteQuery(
['recruitments', multipleFilter, keywordFilter, recruitFilter],
['recruitments', multipleFilter, keywordFilter, recruitFilter, direction],
getData,
{
getNextPageParam: (lastPage, pages) =>
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/recruitment/main/Filter.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import SortToggleButton from './SortToggleButton'
import ToggleButton from './ToggleButton'

export type FilterPropsType = {
Expand All @@ -8,8 +9,8 @@ export default function Filter({ postCount }: FilterPropsType) {
return (
<div className="flex items-center h-[30px] w-[900px] px-4 justify-between text-[13px] pb-4 border-b-[1px]">
<div className="flex">
<span className="w-[62px]">게시글 {postCount}</span>
<div className="pl-4 ml-3 border-l-2">최신 순</div>
<span className="w-[73px] border-r-2 mr-3">게시글 {postCount}</span>
<SortToggleButton />
</div>
<div className="flex items-center">
<span className="mr-2">모집 중인 프로젝트만 보기</span>
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/components/recruitment/main/SortToggleButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useRecoilState } from 'recoil'
import { directionState } from '../../../utils/atoms'

export default function SortToggleButton() {
const [direction, setDirection] = useRecoilState(directionState)

return (
<button
type="button"
onClick={() => {
if (direction === 'ASC') {
setDirection('DESC')
} else {
setDirection('ASC')
}
}}
>
{direction === 'ASC' ? '오래된 순 ▲' : '최신 순 ▼'}
</button>
)
}
8 changes: 7 additions & 1 deletion frontend/src/utils/atoms.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom } from 'recoil'
import { recoilPersist } from 'recoil-persist'
import { MultipleFilterType } from './types'
import { DirectionType, MultipleFilterType } from './types'

const { persistAtom } = recoilPersist()

Expand Down Expand Up @@ -115,6 +115,11 @@ const recruitfilterState = atom<boolean>({
default: false,
})

const directionState = atom<DirectionType>({
key: 'directionState',
default: 'ASC',
})

export {
titleState,
tldrState,
Expand All @@ -137,4 +142,5 @@ export {
multiplefilterState,
keywordfilterState,
recruitfilterState,
directionState,
}
2 changes: 2 additions & 0 deletions frontend/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type MultipleFilterType = {
category: 'position' | 'skill'
name: PositionType | SkillType
}

export type DirectionType = 'ASC' | 'DESC'

0 comments on commit c18be56

Please sign in to comment.