Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8092924

Browse files
committed
.
1 parent 9589f2f commit 8092924

File tree

1 file changed

+8
-96
lines changed

1 file changed

+8
-96
lines changed

homework/src/index.js

Lines changed: 8 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,107 +29,19 @@
2929
});
3030
return elem;
3131
}
32-
32+
3333
function main(url) {
34-
const root = document.getElementById('root');
35-
while (root.firstChild) {
36-
root.removeChild(root.firstChild);
37-
}
38-
39-
fetchJSON( HYF_REPOS_URL, (err, data) => {
34+
fetchJSON(url, (err, data) => {
35+
const root = document.getElementById('root');
4036
if (err) {
4137
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
42-
createAndAppend('img', root, {id: 'catImage', src: 'https://us.123rf.com/450wm/photodeti/photodeti1702/photodeti170200132/72587923-cat-holding-stop-sign-isolated-on-white-background-.jpg?ver=6'})
38+
} else {
39+
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
4340
}
44-
let newArray = [];
45-
let forkArray = [];
46-
let languageArray = [];
47-
let descriptionArray = [];
48-
let updatedAt = [];
49-
let htmlArray = [];
50-
data.sort((a, b) => (a.name).localeCompare(b.name));
51-
52-
53-
for (let i = 0; i < data.length; i++){
54-
newArray.push(data[i].name);
55-
descriptionArray.push(data[i].description);
56-
forkArray.push(data[i].forks);
57-
languageArray.push(data[i].language);
58-
updatedAt.push(data[i].updated_at);
59-
htmlArray.push(data[i].html_url);
60-
var date = new Date ((data[i].updated_at));
61-
date = date.toUTCString();
62-
}
63-
64-
65-
66-
createAndAppend('h1', root, { text: "Hack Your Future Repositories", class: 'title' });
67-
createAndAppend('h3', root, { text: "Select a repository: ", class: 'subtitle'});
68-
const selectList = createAndAppend('select', root, {id: "mySelect" });
69-
const headerDiv = createAndAppend('div', root, {class: 'headerdiv'});
70-
createAndAppend('h3', headerDiv, { text: "Repository Information", class: 'subtitle', id: 'repoHeader' });
71-
createAndAppend('h3', headerDiv, { text: "Contributors", class: 'subtitle', id:'contributorHeader' });
72-
const container = createAndAppend('div', root, {class: 'container'});
73-
const card = createAndAppend('div', container, { class: 'card'});
74-
const ul = createAndAppend('ul', card, {id: "myUl", });
75-
const contributorsCard = createAndAppend('div', container, {class: 'card'});
76-
const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'});
77-
const Index0Name = createAndAppend ('li', ul, {text: "Repository: ", class: 'nameInContainer'});
78-
const Index0Link = createAndAppend ('a', Index0Name, {text: newArray[0], target: "_blank", href: htmlArray[0]});
79-
const Index0Description = createAndAppend('li', ul, {text: "Description: " + descriptionArray[0], class:"descriptionInContainer"});
80-
const Index0Fork = createAndAppend ('li', ul, {text: "Number of Forks: " + forkArray[0], class: 'forksInContainer'});
81-
const Index0Language = createAndAppend ('li', ul, {text: "Language: " + languageArray[0], class: 'updatedAtInContainer'});
82-
const Index0UpdatedAt = createAndAppend ('li', ul, {text: "Updated at: " + date, class: 'updatedAtInContainer'})
83-
fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[0] + '/contributors', (err, data) => {
84-
for (let i = 0; i < data.length; i++){
85-
let Image0Link = createAndAppend('li', contributorsUl, {})
86-
let contributor0Name = createAndAppend('img', Image0Link, {src: data[i].avatar_url, class: 'imageSrc'});
87-
let contributor0Link = createAndAppend('a', Image0Link, {text: data[i].login, target: "_blank", href: data[i].html_url, id: 'link'});
88-
let contributor0Badge = createAndAppend('li', Image0Link, {text:"Contributions: " + data[i].contributions, class: 'badge'});
89-
} //end for
90-
}); //end fetchJSON
91-
92-
93-
data.forEach((repo) => {
94-
for (let i = 0; i < newArray.length; i++) {
95-
createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]});
96-
}
97-
});
98-
99-
function removeNodes(container){
100-
while (ul.hasChildNodes()) {
101-
ul.removeChild(ul.firstChild);
102-
}
103-
while (contributorsUl.hasChildNodes()) {
104-
contributorsUl.removeChild(contributorsUl.firstChild);
105-
}
106-
} //end removeNodes
107-
108-
selectList.onchange = function(selectedIndex){
109-
fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[this.selectedIndex] + '/contributors', (err, data) => {
110-
for (let i = 0; i < data.length; i++){
111-
let ImageLink = createAndAppend('li', contributorsUl, {})
112-
let contributorName = createAndAppend('img', ImageLink, {src: data[i].avatar_url, class: 'imageSrc'});
113-
let contributorLink = createAndAppend('a', ImageLink, {text: data[i].login, target: "_blank", href: data[i].html_url, id: 'link'});
114-
let contributorBadge = createAndAppend('li', ImageLink, {text:"Contributions: " + data[i].contributions, class: 'badge'});
115-
} //end for
116-
}); //end fetchJSON
117-
let repoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()});
118-
createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
119-
createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'});
120-
createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
121-
createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
122-
let dates = new Date (updatedAt[this.selectedIndex]);
123-
dates = dates.toUTCString();
124-
createAndAppend('li', ul, {text: "Updated at: " + dates, class: 'updatedAtInContainer'});
125-
126-
}// end of onchange
127-
128-
}); //end of Fetch
129-
} //end main
130-
41+
});
42+
}
13143

13244
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
133-
window.onload = () => main(HYF_REPOS_URL);
13445

46+
window.onload = () => main(HYF_REPOS_URL);
13547
}

0 commit comments

Comments
 (0)