|
10 | 10 | cb(null, xhr.response);
|
11 | 11 | } else {
|
12 | 12 | cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));
|
| 13 | + console.log("Hello error"); |
13 | 14 | }
|
14 | 15 | };
|
15 | 16 | xhr.onerror = () => cb(new Error('Network request failed'));
|
|
30 | 31 | return elem;
|
31 | 32 | }
|
32 | 33 |
|
33 |
| - |
34 | 34 |
|
35 | 35 | function main(url) {
|
36 | 36 | while (root.firstChild) {
|
|
41 | 41 | let newArray = [];
|
42 | 42 | let forkArray = [];
|
43 | 43 | let languageArray = [];
|
| 44 | + let descriptionArray = []; |
44 | 45 | let htmlArray = [];
|
45 | 46 | let contributorsArray = [];
|
46 | 47 | for (let i = 0; i < data.length; i++){
|
47 |
| - newArray.push(data[i].name); |
48 |
| - newArray.sort(); |
49 |
| - forkArray.push(data[i].forks); |
50 |
| - languageArray.push(data[i].language); |
51 |
| - contributorsArray.push(data[i].contributors_url); |
52 |
| - contributorsArray.sort(); |
53 |
| - htmlArray.push(data[i].html_url); |
54 |
| - htmlArray.sort(); |
55 |
| - } |
56 |
| - |
57 |
| - let app = document.getElementById('root'); |
58 |
| - const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' }); |
59 |
| - const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'}); |
60 |
| - const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" }); |
61 |
| - const container = createAndAppend('div', app, {class: 'container'}); |
62 |
| - const card = createAndAppend('div', container, {text: "Description of this repository ", class: 'card'}); |
63 |
| - const ul = createAndAppend('ul', card, {id: "myUl", }); |
64 |
| - const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' }); |
65 |
| - const contributorsContainer = createAndAppend('div', root, { class: 'container'}) |
66 |
| - const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'}); |
67 |
| - const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'}); |
| 48 | + newArray.push(data[i].name); |
| 49 | + newArray.sort(); |
| 50 | + descriptionArray.push(data[i].description); |
| 51 | + forkArray.push(data[i].forks); |
| 52 | + languageArray.push(data[i].language); |
| 53 | + contributorsArray.push(data[i].contributors_url); |
| 54 | + contributorsArray.sort(); |
| 55 | + htmlArray.push(data[i].html_url); |
| 56 | + htmlArray.sort(); |
| 57 | + } |
| 58 | + |
| 59 | + let app = document.getElementById('root'); |
| 60 | + const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' }); |
| 61 | + const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'}); |
| 62 | + const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" }); |
| 63 | + const container = createAndAppend('div', app, {class: 'container'}); |
| 64 | + const card = createAndAppend('div', container, {text: "Information about this repository: ", class: 'card'}); |
| 65 | + const ul = createAndAppend('ul', card, {id: "myUl", }); |
| 66 | + const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' }); |
| 67 | + const contributorsContainer = createAndAppend('div', root, { class: 'container'}) |
| 68 | + const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'}); |
| 69 | + const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'}); |
68 | 70 |
|
69 | 71 |
|
70 | 72 |
|
71 |
| - data.forEach((repo) => { |
72 |
| - for (let i = 0; i < newArray.length; i++) { |
73 |
| - createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]}); |
74 |
| - } |
75 |
| - }); |
| 73 | + data.forEach((repo) => { |
| 74 | + for (let i = 0; i < newArray.length; i++) { |
| 75 | + createAndAppend('option', selectList, {id: "myOption", value: i, text: newArray[i]}); |
| 76 | + } |
| 77 | + }); |
76 | 78 |
|
77 |
| - function removeNodes(container){ |
78 |
| - while (ul.hasChildNodes()) { |
79 |
| - ul.removeChild(ul.firstChild); |
80 |
| - } |
81 |
| - while (contributorsUl.hasChildNodes()) { |
82 |
| - contributorsUl.removeChild(contributorsUl.firstChild); |
| 79 | + function removeNodes(container){ |
| 80 | + while (ul.hasChildNodes()) { |
| 81 | + ul.removeChild(ul.firstChild); |
| 82 | + } |
| 83 | + while (contributorsUl.hasChildNodes()) { |
| 84 | + contributorsUl.removeChild(contributorsUl.firstChild); |
| 85 | + } |
83 | 86 | }
|
84 |
| - } |
85 | 87 |
|
86 |
| - selectList.onchange = function(selectedIndex){ |
87 |
| - createAndAppend('li', ul, { text: "Repository: " + newArray[this.selectedIndex], class: 'nameInContainer', function: removeNodes()}); |
88 |
| - createAndAppend('a', ul, { text: htmlArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]}); |
89 |
| - createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'}); |
90 |
| - createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'}); |
91 |
| - createAndAppend('li', contributorsUl, { text: contributorsArray[this.selectedIndex], class: 'contributorsInContainer'}); |
92 |
| - } |
| 88 | + selectList.onchange = function(selectedIndex){ |
| 89 | + let RepoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()}); |
| 90 | + createAndAppend('a', RepoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]}); |
| 91 | + createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'}); |
| 92 | + createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'}); |
| 93 | + createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'}); |
| 94 | + createAndAppend('li', contributorsUl, { text: contributorsArray[this.selectedIndex], class: 'contributorsInContainer'}); |
| 95 | + } |
| 96 | + }); |
| 97 | + /* |
| 98 | + fetchJSON( theContributors_URL, (err, data) => { |
| 99 | + let theContributorsUrl = []; |
| 100 | + for (let i = 0; i < data.length; i++){ |
93 | 101 |
|
94 |
| - }); |
95 |
| - } |
| 102 | + } |
| 103 | + });*/ |
| 104 | + } |
96 | 105 |
|
97 | 106 | const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
|
98 | 107 | const theContributors_URL = 'https://api.github.com/repos/HackYourFuture/contributors';
|
|
0 commit comments