Skip to content

Commit 80828cc

Browse files
committed
change css and dates
1 parent a2aa39e commit 80828cc

2 files changed

Lines changed: 70 additions & 57 deletions

File tree

homework/src/index.js

Lines changed: 42 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
});
3131
return elem;
3232
}
33-
34-
33+
3534
function main(url) {
3635
while (root.firstChild) {
3736
root.removeChild(root.firstChild);
@@ -41,40 +40,47 @@
4140
if (err) {
4241
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
4342
}
44-
const newArray = [];
43+
let newArray = [];
4544
let forkArray = [];
4645
let languageArray = [];
4746
let descriptionArray = [];
4847
let updatedAt = [];
4948
let htmlArray = [];
50-
let contributorsArray = [];
49+
data.sort((a, b) => (a.name).localeCompare(b.name));
50+
51+
5152
for (let i = 0; i < data.length; i++){
5253
newArray.push(data[i].name);
53-
newArray.sort();
5454
descriptionArray.push(data[i].description);
5555
forkArray.push(data[i].forks);
5656
languageArray.push(data[i].language);
5757
updatedAt.push(data[i].updated_at);
58-
contributorsArray.push(data[i].contributors_url);
59-
contributorsArray.sort();
60-
htmlArray.push(data[i].html_url);
61-
htmlArray.sort();
58+
htmlArray.push(data[i].html_url);
59+
var date = new Date ((data[i].updated_at));
60+
date = date.toUTCString();
6261
}
6362

6463

65-
let app = document.getElementById('root');
66-
const header = createAndAppend('h1', app, { text: "Hack Your Future Repositories", class: 'title' });
67-
const subHeader = createAndAppend('h3', app, { text: "Select a repository: ", class: 'subtitle'});
68-
const selectList = createAndAppend('select', app, { text: 'Select a Repo', id: "mySelect" });
69-
const container = createAndAppend('div', app, {class: 'container'});
70-
const card = createAndAppend('div', container, {text: "Information about this repository: ", class: 'card'});
64+
const root = document.getElementById('root');
65+
createAndAppend('h1', root, { text: "Hack Your Future Repositories", class: 'title' });
66+
createAndAppend('h3', root, { text: "Select a repository: ", class: 'subtitle'});
67+
const selectList = createAndAppend('select', root, {id: "mySelect" });
68+
const headerDiv = createAndAppend('div', root, {class: 'headerdiv'});
69+
createAndAppend('h3', headerDiv, { text: "Repository Information", class: 'subtitle', id: 'repoHeader' });
70+
createAndAppend('h3', headerDiv, { text: "Contributors", class: 'subtitle', id:'contributorHeader' });
71+
const container = createAndAppend('div', root, {class: 'container'});
72+
const card = createAndAppend('div', container, { class: 'card'});
7173
const ul = createAndAppend('ul', card, {id: "myUl", });
72-
const contributorsheader = createAndAppend('h1', root, { text: "Contributors", class: 'title' });
73-
const contributorsContainer = createAndAppend('div', root, { class: 'container'})
74-
const contributorsCard = createAndAppend('div', contributorsContainer, {text: "Contributors to this Repository", class: 'card'});
74+
const contributorsCard = createAndAppend('div', container, {class: 'card'});
7575
const contributorsUl = createAndAppend('ul', contributorsCard, {id: 'contributorsUl'});
76-
77-
76+
const Index0Name = createAndAppend ('li', ul, {text: "Repository: ", class: 'nameInContainer'});
77+
const Index0Link = createAndAppend ('a', Index0Name, {text: newArray[0], target: "_blank", href: htmlArray[0]});
78+
const Index0Description = createAndAppend('li', ul, {text: "Description: " + descriptionArray[0], class:"descriptionInContainer"});
79+
const Index0Fork = createAndAppend ('li', ul, {text: "Number of Forks: " + forkArray[0], class: 'forksInContainer'});
80+
const Index0Language = createAndAppend ('li', ul, {text: "Language: " + languageArray[0], class: 'updatedAtInContainer'});
81+
const Index0UpdatedAt = createAndAppend ('li', ul, {text: "Updated at: " + date, class: 'updatedAtInContainer'})
82+
83+
7884

7985
data.forEach((repo) => {
8086
for (let i = 0; i < newArray.length; i++) {
@@ -90,41 +96,30 @@
9096
contributorsUl.removeChild(contributorsUl.firstChild);
9197
}
9298
} //end removeNodes
93-
99+
94100
selectList.onchange = function(selectedIndex){
95-
let repoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()});
96-
createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
97-
createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'});
98-
createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
99-
createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
100-
createAndAppend('li', ul, {text: "Updated at: " + updatedAt[this.selectedIndex], id: 'updatedAtInContainer'})
101-
fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[this.selectedIndex] + '/contributors', (err, data) => {
102-
let getName = [];
103-
let getLink = [];
104-
let getBadge = [];
105-
let login = [];
106-
for (let i = 0; i < data.length; i++){
107-
getName.push(data[i].avatar_url);
108-
getLink.push(data[i].html_url);
109-
getBadge.push(data[i].contributions);
110-
login.push(data[i].login);
111-
101+
fetchJSON('https://api.github.com/repos/HackYourFuture/' + newArray[this.selectedIndex] + '/contributors', (err, data) => {
102+
for (let i = 0; i < data.length; i++){
112103
let imageLink = createAndAppend('li', contributorsUl, {})
113-
let contributorName = createAndAppend('img', imageLink, {src: data[i].avatar_url});
104+
let contributorName = createAndAppend('img', imageLink, {src: data[i].avatar_url, class: 'imageSrc'});
114105
let contributorLink = createAndAppend('a', imageLink, {text: data[i].login, target: "_blank", href: data[i].html_url, id: 'link'});
115106
let contributorBadge = createAndAppend('li', imageLink, {text:"Contributions: " + data[i].contributions, class: 'badge'});
116107
} //end for
117-
data.forEach((repo) => {
118-
});//end for each
119108
}); //end fetchJSON
109+
let repoName = createAndAppend('li', ul, { text: "Repository: ", class: 'nameInContainer', function: removeNodes()});
110+
createAndAppend('a', repoName, { text: newArray[this.selectedIndex], id: 'linkInContainer', target: "_blank", href: htmlArray[this.selectedIndex]});
111+
createAndAppend('li', ul, {text: "Description: " + descriptionArray[this.selectedIndex], class: 'descriptionInContainer'});
112+
createAndAppend('li', ul, { text: "Number of Forks: " + forkArray[this.selectedIndex], class: 'forksInContainer'});
113+
createAndAppend('li', ul, { text: "Language: " + languageArray[this.selectedIndex], class: 'languageInContainer'});
114+
let dates = new Date (updatedAt[this.selectedIndex]);
115+
dates = dates.toUTCString();
116+
createAndAppend('li', ul, {text: "Updated at: " + dates, class: 'updatedAtInContainer'});
120117

121-
}// end of onchange
122-
}); //end of Fetch
123-
124-
118+
}// end of onchange
125119

126-
127-
}
120+
}); //end of Fetch
121+
} //end main
122+
128123

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

homework/src/style.css

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ img{
99
margin: 10px;
1010
padding: 25px;
1111
width: 150px;
12-
float: center;
12+
display: flex;
13+
justify-content: center;
1314

1415
}
1516

@@ -33,37 +34,54 @@ img{
3334
flex-wrap: wrap;
3435
border: 2px solid gray;
3536
background-color: darkslateblue;
36-
}
37-
38-
.contributorsContainer {
39-
display: flex;
40-
flex-wrap: wrap;
41-
border: 2px solid gray;
42-
background-color: darkslateblue;
37+
clear: both;
4338
}
4439

4540
.card {
4641
margin: 1rem;
4742
border: 2px solid gray;
4843
background-color: white;
4944
color: black;
45+
display: flex;
46+
justify-content: left;
47+
font-size: 20px;
5048
}
5149
.contributorsCard {
5250
margin: 1rem;
5351
border: 2px solid gray;
5452
background-color: darkslateblue;
53+
display: flex;
54+
justify-content: right;
55+
font-size: 20px;
56+
text-align: center;
5557
}
5658
.card:hover {
5759
background-color: pink;
5860
}
61+
.header{
62+
float: center;
63+
clear: both;
64+
}
65+
.title {
66+
font-size: 3rem;
67+
text-align: center;
68+
}
5969

6070
.subtitle {
61-
color: white;
71+
color: white;
6272
margin: 1rem;
73+
font-size: 1.25rem;
74+
}
75+
#repoHeader {
76+
float: left;
77+
}
78+
#contributorHeader {
79+
float: right;
6380
}
6481
#mySelect{
6582
margin: 2rem;
66-
padding: 1rem;
83+
margin-top: 0;
84+
padding: 1.5rem;
6785
font-size: 1rem;
6886
background-color: white;
6987
color: black;

0 commit comments

Comments
 (0)