File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
panda-market/src/components/common/DropDown Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments