Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homework/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
</head>

<body>
<div id="root"></div>
<header>
<div id="root"></div>
</header>
<script src="./index.js"></script>
</body>
</html>
58 changes: 56 additions & 2 deletions homework/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,68 @@
function main(url) {
fetchJSON(url, (err, data) => {
const root = document.getElementById('root');

if (err) {
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
} else {
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
const header = createAndAppend('header', root, { class: 'header' });
const h1 = createAndAppend('h1', header, { text: 'FooCoding Repos', class: 'h1' });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice usage of createAndAppend!


const select = createAndAppend('select', root, { class: 'select' });
createAndAppend('option', select, { text: 'Choose your favorite repo below:' });
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the requirements is that information for the first repo is shown when the page loads, can you have a look at that?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying...


data.forEach(repo => {
const name = repo.name;
data.sort((a, b) => a.name.localeCompare(b.name));
createAndAppend('option', select, { text: name });
console.log(name);
});

const repoInfo = createAndAppend('div', root, { class: 'left-div' });
const contribs = createAndAppend('div', root, { class: 'right-div' });

select.addEventListener('change', evt => {
const selectedRepo = evt.target.value;
const repo = data.filter(r => r.name == selectedRepo)[0];
console.log(repo.name);
repoInfo.innerHTML = repo.name;
contribs.innerHTML = repo.name;

const addInfo = (label, value) => {
const container = createAndAppend('div', repoInfo);
createAndAppend('span', container, { text: label });
createAndAppend('span', container, { text: value });
};

addInfo('Name: ', repo.name);
addInfo('Description: ', repo.description);
addInfo('Number of forks: ', repo.forks);
addInfo('Updated: ', repo.updated_at);

const contribsUrl = repo.contributors_url;
fetchJSON(contribsUrl, (err, contribData) => {
if (err) {
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
} else {
}
contribData.forEach(contributor => {
createAndAppend('div', contribs, { text: contributor.login });
createAndAppend('a', contribs, {
text: contributor.login,
href: contributor.html_url,
});
createAndAppend('img', contribs, {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

src: contributor.avatar_url,
height: 150,
width: 150,
id: 'img',
});
});
});
});
}
});
}

const REPOS_URL = 'https://api.github.com/orgs/foocoding/repos?per_page=100';

window.onload = () => main(REPOS_URL);
Expand Down
65 changes: 63 additions & 2 deletions homework/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
#root {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
}
@media screen and (max-width: 768px) {
.h1.h1 {
width: 100%;
}
.right-div {
width: 100%;
}
.left-div {
width: 100%;
}
}
.alert-error {
color: red;
}
color: red;
}
.h1 {
text-align: center;
}
.container {
display: flex;
flex-direction: row;
align-items: flex-start;
margin: 10px;
}

.right-div {
color: green;
display: flex;
flex-direction: row;
justify-content: space-between;
flex-wrap: wrap;
margin: 10px;
flex-grow: 1;
height: 200px;
width: 200px;
}

.left-div {
color: brown;
display: flex;
flex-wrap: wrap;
flex-direction: column;
flex-grow: 1;

align-items: right;
margin: 10px;
}
header {
width: 800px;
height: 70px;
background-color: purple;
text-emphasis-color: white;
text-align: left;
}
.info-container {
text-align: left;
width: 40;
height: 30;
}