Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Merged
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
2 changes: 2 additions & 0 deletions Week1/MAKEME.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ It should include the following components:
2. A left-hand column that displays basic information about the selected repository.
3. A right-hand column that displays a list of contributors to the repository.

>In case you run out of time, you can also do the contributors list in week 2.

**Functional Requirements:**

1. The list of repositories in the `select` element should be sorted (case-insensitive) on repository name.
Expand Down
13 changes: 11 additions & 2 deletions homework/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ class App {
}
}

/**
* Removes all child elements from a container element
* @param {*} container Container element to clear
*/
clearContainer(container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
}

/**
* Fetch contributor information for the selected repository and render the
* repo and its contributors as HTML elements in the DOM.
Expand All @@ -40,8 +50,7 @@ class App {
const contributors = await repo.fetchContributors();

const container = document.getElementById('container');
// Erase previously generated inner HTML from the container div
container.innerHTML = '';
this.clearContainer(container);

const leftDiv = Util.createAndAppend('div', container);
const rightDiv = Util.createAndAppend('div', container);
Expand Down
4 changes: 2 additions & 2 deletions homework/src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Util {
parent.appendChild(elem);
Object.keys(options).forEach((key) => {
const value = options[key];
if (key === 'html') {
elem.innerHTML = value;
if (key === 'text') {
elem.innerText = value;
} else {
elem.setAttribute(key, value);
}
Expand Down
8 changes: 4 additions & 4 deletions homework/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
parent.appendChild(elem);
Object.keys(options).forEach((key) => {
const value = options[key];
if (key === 'html') {
elem.innerHTML = value;
if (key === 'text') {
elem.innerText = value;
} else {
elem.setAttribute(key, value);
}
Expand All @@ -34,9 +34,9 @@
fetchJSON(url, (err, data) => {
const root = document.getElementById('root');
if (err) {
createAndAppend('div', root, { html: err.message, class: 'alert-error' });
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
} else {
createAndAppend('pre', root, { html: JSON.stringify(data, null, 2) });
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
}
});
}
Expand Down