Skip to content

Commit 9a88327

Browse files
authored
Merge pull request #225 from wildan3105/fix/pass-usertype-to-chart
Fix: differentiate browse repos based on user type
2 parents b3455c4 + b8afe56 commit 9a88327

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

public/js/chart.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const saveChart = () => {
4444
const chart = ({ limit, singleColor }) => {
4545
const canvasContainer = document.getElementById('canvas-container');
4646
const color = 'white';
47+
const type = canvasContainer.dataset.type;
4748
const username = canvasContainer.dataset.username;
4849
const languages = JSON.parse(canvasContainer.dataset.languages);
4950
const colors = singleColor
@@ -116,13 +117,25 @@ const chart = ({ limit, singleColor }) => {
116117
}
117118
}));
118119

120+
const getURLBasedOnUserType = (userType, username) => {
121+
let prefixURL;
122+
if (userType === 'Organization') {
123+
prefixURL = `https://github.com/orgs/${username}/repositories?q=`;
124+
} else if (userType === 'Personal') {
125+
prefixURL = `https://github.com/${username}?tab=repositories`;
126+
}
127+
128+
return prefixURL;
129+
};
130+
119131
const onCanvasClick = (e) => {
120132
const activeElement = chart.getElementAtEvent(e)[0];
121133

122134
if (activeElement) {
123135
let language = chart.data.labels[activeElement._index];
124136
language = slugify(language);
125-
const url = `https://github.com/${username}?tab=repositories&type=&language=${language}`;
137+
const prefixURL = getURLBasedOnUserType(type, username);
138+
const url = `${prefixURL}&language=${language}`;
126139
window.open(url, '_blank');
127140
}
128141
};

src/api/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ exports.index = async (req, res) => {
9090

9191
axios.all(await reqRepos(username, numberOfPages))
9292
.then((pages) => {
93-
const reposData = _.flatMap(pages, (page) => page.data);
93+
const reposData = _.flatMap(pages, (page) => page);
9494

9595
(numberOfRepos === 1) ? repos = `${numberOfRepos} repo` : repos = `${numberOfRepos} repos`;
9696
reposData.forEach((repo) => {

src/api/octokit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OctokitService {
2222

2323
async getReposForUser(username, page) {
2424
try {
25-
const data = await this.octokit.request(`GET /users/${username}/repos?per_page=${REPOS_PER_PAGE}&page=${page}`);
25+
const { data } = await this.octokit.request(`GET /users/${username}/repos?per_page=${REPOS_PER_PAGE}&page=${page}`);
2626
return data;
2727
} catch (e) {
2828
throw e;

src/pages/partials/body.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
data-username='{{username}}'
5353
data-languages='{{languages}}'
5454
data-colors='{{colors}}'
55+
data-type='{{type}}'
5556
>
5657
<canvas id="myChart" style="cursor:pointer;"></canvas>
5758

0 commit comments

Comments
 (0)