Skip to content

Commit f57cf33

Browse files
committed
feat: 드롭다운 옵션 선택에 따라 쿼리 스트링 및 라벨 동기화
1 parent 61df74f commit f57cf33

File tree

1 file changed

+13
-3
lines changed
  • panda-market/src/components/common/DropDown

1 file changed

+13
-3
lines changed

panda-market/src/components/common/DropDown/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ export default function DropDown() {
1616
type OptionType = 'recent' | 'like';
1717

1818
const [isOpen, setIsOpen] = useState<boolean>(false);
19+
const [labelName, setLabelName] = useState<string>('최신순');
1920

2021
// 선택된 드롭다운 옵션에 따라 경로 쿼리 스트링 업데이트
21-
const handleDropDownOptionClick = (selectedOption: OptionType) => {
22+
const handleDropDownOptionClick = (optionId: OptionType) => {
23+
// optionId : 선택된 옵션
2224
const params = new URLSearchParams(window.location.search);
23-
params.set('orderBy', selectedOption);
25+
26+
const currentOrder = params.get('orderBy') || 'recent';
27+
if (currentOrder === optionId) return;
28+
29+
params.set('orderBy', optionId);
2430
router.push(`?${params}`);
31+
32+
// set dropdown handler label
33+
setLabelName(dropDownOptions.find((option) => optionId === option.id)?.label as string);
34+
setIsOpen(false); // close modal
2535
};
2636

2737
// 드롭다운 외부 클릭 시 닫힘
@@ -46,7 +56,7 @@ export default function DropDown() {
4656
onClick={() => setIsOpen((prev) => !prev)}
4757
>
4858
<div className="flex gap-6">
49-
<span>최신순</span>
59+
<span>{labelName}</span>
5060
<Image src="/icons/arrow_down.svg" alt="arrow down" width={16} height={8} />
5161
</div>
5262
</div>

0 commit comments

Comments
 (0)