@@ -13,7 +13,7 @@ import useMentoringPopup from '@hooks/useMentoringPopup.ts';
1313import useInfScroll from '@hooks/useInfScroll.ts' ;
1414import useWindowSizeStore from '@/stores/useWindowSizeStore.ts' ;
1515import { TechTypeOptions } from '@constant/selectOptions.ts' ;
16- import { IMainMentorList , IMentoring } from '@constant/interfaces.ts' ;
16+ import { IMainMentorList , IMentoring , SearchParams } from '@constant/interfaces.ts' ;
1717import { MentorAdapter } from '@constant/InfScrollAdapter.ts' ;
1818import authControl from '@constant/authControl.ts' ;
1919
@@ -29,14 +29,6 @@ function MainMentorPage() {
2929 const [ isLoginDialogOpen , setIsLoginDialogOpen ] = useState < boolean > ( false ) ;
3030 const infScrollLayout = useRef < HTMLDivElement > ( null ) ;
3131
32- const [ searchType , setSearchType ] = useState < string > ( SearchTypeOptions [ 0 ] . value ) ;
33- const [ searchValue , setSearchValue ] = useState < string > ( '' ) ;
34- // const [stack, setStack] = useState<string>('스택 전체');
35- const [ stack , setStack ] = useState < string [ ] > ( [ ] ) ;
36- const [ roleType , setRoleType ] = useState < string > ( TechTypeOptions [ 0 ] . value ) ;
37-
38- const isMobile = useWindowSizeStore ( state => state . isMobile ) ;
39-
4032 const adapter = useRef ( new MentorAdapter ( ) ) ;
4133 const { data, loading, isEnded, isEmpty, setReqParams, hideData}
4234 = useInfScroll < IMainMentorList , IMentoring > ( adapter . current , infScrollLayout ) ;
@@ -47,22 +39,6 @@ function MainMentorPage() {
4739 const isLogin = ! ! authControl . getUserIdFromToken ( ) ;
4840 const UserRole = token ? token . role : '' ;
4941
50- useEffect ( ( ) => {
51- search ( ) ;
52- } , [ ] ) ;
53-
54- function search ( ) {
55- let searchObj = { } ;
56-
57- if ( searchValue )
58- searchObj = { ...searchObj , searchType : searchType , searchValue : searchValue } ;
59- if ( stack . length )
60- searchObj = { ...searchObj , stack : stack [ 0 ] } ;
61- if ( roleType )
62- searchObj = { ...searchObj , roleType : roleType } ;
63-
64- setReqParams ( searchObj ) ;
65- }
6642
6743 return (
6844 < div >
@@ -100,29 +76,8 @@ function MainMentorPage() {
10076 ) ) }
10177 </ div >
10278 </ div >
103- < div className = 'search_layout' >
104- < SelectBox options = { TechTypeOptions }
105- hasDefault = { roleType !== TechTypeOptions [ 0 ] . value }
106- value = { roleType }
107- onChange = { value => setRoleType ( value ) } />
108- < TechStackSelector value = { stack } max = { 1 } placeholder = '스택 전체' onChange = { setStack } />
109- < SelectBox options = { SearchTypeOptions }
110- hasDefault = { false }
111- value = { searchType }
112- onChange = { value => setSearchType ( value ) } />
113-
114- < div className = 'search_input_layout' >
115- < input type = 'text'
116- placeholder = '키워드를 한글자 이상 입력해주세요'
117- maxLength = { 49 }
118- value = { searchValue }
119- onChange = { e => setSearchValue ( e . target . value ) } />
120-
121- < button className = 'search_button' onClick = { search } >
122- < Search width = { isMobile ? 48 : 62 } height = { isMobile ? 48 : 62 } />
123- </ button >
124- </ div >
125- </ div >
79+
80+ < MentorSearches setReqParams = { setReqParams } />
12681
12782 < div className = { 'card_layout' + ( ! loading && isEmpty ? ' no_contents' : '' ) }
12883 ref = { infScrollLayout } >
@@ -151,4 +106,57 @@ function MainMentorPage() {
151106 ) ;
152107}
153108
109+ function MentorSearches ( { setReqParams} : { setReqParams : ( params : SearchParams ) => void } ) {
110+ const [ searchType , setSearchType ] = useState < string > ( SearchTypeOptions [ 0 ] . value ) ;
111+ const [ searchValue , setSearchValue ] = useState < string > ( '' ) ;
112+ // const [stack, setStack] = useState<string>('스택 전체');
113+ const [ stack , setStack ] = useState < string [ ] > ( [ ] ) ;
114+ const [ roleType , setRoleType ] = useState < string > ( TechTypeOptions [ 0 ] . value ) ;
115+
116+ const isMobile = useWindowSizeStore ( state => state . isMobile ) ;
117+
118+ useEffect ( ( ) => {
119+ search ( ) ;
120+ } , [ ] ) ;
121+
122+ function search ( ) {
123+ let searchObj = { } ;
124+
125+ if ( searchValue )
126+ searchObj = { ...searchObj , searchType : searchType , searchValue : searchValue } ;
127+ if ( stack . length )
128+ searchObj = { ...searchObj , stack : stack [ 0 ] } ;
129+ if ( roleType )
130+ searchObj = { ...searchObj , roleType : roleType } ;
131+
132+ setReqParams ( searchObj ) ;
133+ }
134+
135+ return (
136+ < div className = 'search_layout' >
137+ < SelectBox options = { TechTypeOptions }
138+ hasDefault = { roleType !== TechTypeOptions [ 0 ] . value }
139+ value = { roleType }
140+ onChange = { value => setRoleType ( value ) } />
141+ < TechStackSelector value = { stack } max = { 1 } placeholder = '스택 전체' onChange = { setStack } />
142+ < SelectBox options = { SearchTypeOptions }
143+ hasDefault = { false }
144+ value = { searchType }
145+ onChange = { value => setSearchType ( value ) } />
146+
147+ < div className = 'search_input_layout' >
148+ < input type = 'text'
149+ placeholder = '키워드를 한글자 이상 입력해주세요'
150+ maxLength = { 49 }
151+ value = { searchValue }
152+ onChange = { e => setSearchValue ( e . target . value ) } />
153+
154+ < button className = 'search_button' aria-label = '검색' onClick = { search } >
155+ < Search width = { isMobile ? 48 : 62 } height = { isMobile ? 48 : 62 } />
156+ </ button >
157+ </ div >
158+ </ div >
159+ ) ;
160+ }
161+
154162export default MainMentorPage ;
0 commit comments