@@ -82,21 +82,22 @@ const useStyles = makeStyles((theme) => ({
8282
8383
8484export const IndvPageContainer = ( props ) => {
85- const [ projects , setProjects ] = useState ( [ ] ) ;
85+ const classes = useStyles ( ) ;
86+ const inputSortMethodList = [ 'best match' , 'updated' , 'stars' ] ;
87+ const projectsPerPage = 4 ;
88+ const [ affiliations , setAffiliations ] = useState ( { } ) ;
8689 const [ bestMatchProjects , setBestMatchProjects ] = useState ( [ ] ) ;
90+ const [ dropDownListItem , setDropDownListItem ] = useState ( '' ) ;
91+ const [ errorState , setErrorState ] = useState ( false ) ;
92+ const [ isProjectSearchFinish , setIsProjectSearchFinish ] = useState ( false ) ;
8793 const [ lastUpdatedProjects , setLastUpdatedProjects ] = useState ( [ ] ) ;
88- const [ stargazerProjects , setStargazerProjects ] = useState ( [ ] ) ;
89- const [ pageNum , setPageNum ] = useState ( 1 ) ;
94+ const [ loading , setLoading ] = useState ( true ) ;
9095 const [ pages , setPages ] = useState ( 1 ) ;
96+ const [ pageNum , setPageNum ] = useState ( 1 ) ;
97+ const [ projects , setProjects ] = useState ( [ ] ) ;
9198 const [ results , setResults ] = useState ( '' ) ;
92- const [ dropDownListItem , setDropDownListItem ] = useState ( '' ) ;
93- const [ loading , setLoading ] = useState ( true ) ;
9499 const [ sortMethod , setSortMethod ] = useState ( 'best match' ) ;
95- const inputSortMethodList = [ 'best match' , 'updated' , 'stars' ] ;
96- const [ isProjectSearchFinish , setIsProjectSearchFinish ] = useState ( false ) ;
97- const [ errorState , setErrorState ] = useState ( false ) ;
98- const projectsPerPage = 4 ;
99- const classes = useStyles ( ) ;
100+ const [ stargazerProjects , setStargazerProjects ] = useState ( [ ] ) ;
100101
101102 useEffect ( ( ) => {
102103 setLoading ( true ) ;
@@ -109,6 +110,7 @@ export const IndvPageContainer = (props) => {
109110 setResults ( '' ) ;
110111 setDropDownListItem ( '' ) ;
111112 setSortMethod ( 'best match' ) ;
113+ fetchAffiliations ( ) ;
112114 } , [ props . pathName ] ) ;
113115
114116 // Fetching the data for 'other repo' dropdown elements
@@ -215,12 +217,12 @@ export const IndvPageContainer = (props) => {
215217 indexOfFirstProject ,
216218 indexOfLastProject
217219 ) ;
218- const items = currentProjects . map ( ( i ) => renderCard ( i ) ) ;
220+ const items = currentProjects . map ( ( i ) => renderCard ( i , affiliations ) ) ;
219221 setResults ( items ) ;
220222 if ( isProjectSearchFinish ) {
221223 setLoading ( false ) ;
222224 }
223- } , [ projects , isProjectSearchFinish ] ) ;
225+ } , [ projects , isProjectSearchFinish , affiliations ] ) ;
224226
225227 useEffect ( ( ) => {
226228 if ( sortMethod === 'best match' ) {
@@ -261,6 +263,17 @@ export const IndvPageContainer = (props) => {
261263 return sortedProjectsArr ;
262264 } ;
263265
266+ const fetchAffiliations = ( ) => {
267+ const afflns = { } ;
268+ axios . get ( `${ process . env . REACT_APP_API_URL } /api/organizations/` )
269+ . then ( ( res ) => {
270+ res . data . forEach ( ( org ) => {
271+ afflns [ org . org_tag ] = true ;
272+ } ) ;
273+ setAffiliations ( afflns ) ;
274+ } ) ;
275+ } ;
276+
264277 const handlePageChange = ( pageNum ) => {
265278 setPageNum ( pageNum ) ;
266279 const indexOfLastProject = pageNum * projectsPerPage ;
@@ -269,7 +282,7 @@ export const IndvPageContainer = (props) => {
269282 indexOfFirstProject ,
270283 indexOfLastProject
271284 ) ;
272- const items = currentProjects . map ( ( i ) => renderCard ( i ) ) ;
285+ const items = currentProjects . map ( ( i ) => renderCard ( i , affiliations ) ) ;
273286 setResults ( items ) ;
274287 } ;
275288
0 commit comments