Skip to content

Commit 9bcdbcc

Browse files
authored
Merge branch 'main' into update-landing-909
2 parents fc75eb4 + 7ee366d commit 9bcdbcc

File tree

4 files changed

+248
-116
lines changed

4 files changed

+248
-116
lines changed

src/pages/IndvOrganization/IndvPageContainer.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,22 @@ const useStyles = makeStyles((theme) => ({
8282

8383

8484
export 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

src/pages/IndvOrganization/RenderProjectCard.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@ const calculateDaysSince = (updateTime) => {
77
return Math.round(days / (1000 * 3600 * 24));
88
};
99

10-
export const renderCard = (project) => {
10+
export const renderCard = (project, affiliations) => {
11+
const affiliationTags = [];
12+
const topicTags = [];
13+
project.topics.forEach((topic) => {
14+
if (affiliations[topic]) {
15+
affiliationTags.push(topic);
16+
} else {
17+
topicTags.push(topic)
18+
}
19+
});
1120
return (
1221
<Grid item style={{ paddingTop: '12px' }} key={project.id}>
1322
{' '}
1423
<ProjectCard
15-
projectUrl={project.html_url}
16-
organizationUrl={project.owner.html_url}
24+
homepage={project.homepage}
25+
issueCount={project.open_issues}
26+
lastUpdate={calculateDaysSince(project.updated_at)}
1727
organizationAvatarUrl={project.owner.avatar_url}
28+
organizationUrl={project.owner.html_url}
1829
ownerName={project.owner.login}
19-
projectName={project.name}
2030
projectDescription={project.description}
21-
homepage={project.homepage}
22-
lastUpdate={calculateDaysSince(project.updated_at)}
23-
issueCount={project.open_issues}
2431
projectLanguage={project.language}
25-
topics={project.topics}
26-
watchers={project.watchers_count}
32+
projectName={project.name}
33+
projectTags={affiliationTags}
34+
projectUrl={project.html_url}
2735
stargazers={project.stargazers_count}
28-
projectTags={project.parentOrgs}
36+
topics={topicTags}
37+
watchers={project.watchers_count}
2938
/>
3039
</Grid>
3140
);

0 commit comments

Comments
 (0)