diff --git a/src/components/ContentBox/index.tsx b/src/components/ContentBox/index.tsx
index 77e64d2..e2f5fba 100644
--- a/src/components/ContentBox/index.tsx
+++ b/src/components/ContentBox/index.tsx
@@ -33,7 +33,7 @@ const ContentBox = () => {
} = useBookmarkInfinityAPI({
size: 10,
direction: 'DESC',
- property: 'id',
+ property: queryParam.get('sort') ?? 'id',
categoryId,
isFavorite: queryParam.get('favorite') === 'true',
});
diff --git a/src/components/FilterBox/index.tsx b/src/components/FilterBox/index.tsx
index 32b2c4e..097504c 100644
--- a/src/components/FilterBox/index.tsx
+++ b/src/components/FilterBox/index.tsx
@@ -4,13 +4,20 @@ import { useCategoryList, useSaveCategory } from '@/apis/category';
import useQueryString from '@/hooks/useQueyString';
import { cn } from '@/lib/utils';
import useToastStore from '@/stores/toastStore';
-import { ChangeEvent, useRef, useState } from 'react';
+import { ChangeEvent, useEffect, useRef, useState } from 'react';
import TabList from '../TabList';
import { Button } from '../common/Button';
import Divider from '../common/Divider';
import Icon from '../common/Icon';
+import { Option } from '../common/Option';
import AddCategory from './AddCategory';
+const sortList = [
+ { label: '최신순', value: 'id' },
+ { label: '이름순', value: 'updatedAt' },
+ { label: '오래된순', value: 'createdAt' },
+];
+
const FilterBox = () => {
const { queryParam, updateQueryString } = useQueryString();
@@ -19,12 +26,15 @@ const FilterBox = () => {
const { mutateAsync: mutateSaveCategory } = useSaveCategory();
const isLikeChecked = queryParam.get('favorite') === 'true'; // 종아요 항목 표시
+ const sortType = queryParam.get('sort') ?? 'id'; // 종아요 항목 표시
const viewType = queryParam.get('view') ?? 'grid'; // list 타입 grid | list
+ const [isShowSort, setIsShowSort] = useState
(false);
const [isOpenCategory, setIsOpenCategory] = useState(false); // 카테고리 모달 오픈
const [category, setCategory] = useState(''); // 카테고리 텍스트
const [isError, setIsError] = useState(false); // 카테고리 에러
+ const sortTabRef = useRef(null);
const buttonRef = useRef(null);
const handleChangeCategory = (e: ChangeEvent) => {
@@ -34,10 +44,14 @@ const FilterBox = () => {
setCategory(e.target.value);
};
+ const handleSelectSortOption = (value: string) => {
+ updateQueryString('sort', value);
+ setIsShowSort(false);
+ };
+
/**
* TODO :
* - 유효성 검증 case 추가 필요
- * - 카테고리 영역 밖 클릭 or esc 닫기
*/
const handleAddCategory = () => {
if (!category) {
@@ -63,6 +77,19 @@ const FilterBox = () => {
});
};
+ // 정렬 option 외부 클릭시 닫힘
+ useEffect(() => {
+ const handleCloseSortOption = (e: Event) => {
+ const target = e.target as HTMLElement;
+
+ if (isShowSort && !sortTabRef.current?.contains(target)) setIsShowSort(false);
+ };
+
+ window.addEventListener('click', handleCloseSortOption);
+
+ return () => window.removeEventListener('click', handleCloseSortOption);
+ }, [isShowSort]);
+
return (
@@ -108,9 +135,29 @@ const FilterBox = () => {
-
- 최신순
-
+ {/* 정렬 START */}
+
+
{
+ setIsShowSort((prev) => !prev);
+ }}
+ >
+ {sortList.find((item) => item.value === sortType)?.label}
+
+
+ {isShowSort && (
+
+ {sortList.map((item) => (
+ {item.label}
+
+ ))}
+
+ )}
+
+
+ {/* 정렬 END */}