diff --git a/homework-classes/ContributorsView.js b/homework-classes/ContributorsView.js
index 58cb2b984..4a5e2a90b 100755
--- a/homework-classes/ContributorsView.js
+++ b/homework-classes/ContributorsView.js
@@ -19,8 +19,13 @@
* @param {Object[]} contributors An array of contributor objects
*/
render(contributors) {
- // TODO: replace this comment and the console.log with your own code
- console.log('ContributorsView', contributors);
+ contributors.forEach(contributor => {
+ createAndAppend('li', document.getElementById('contributors-list'), {
+ text: `
+ ${contributor.login}
+ ${contributor.contributions}`
+ });
+ })
}
}
diff --git a/homework-classes/Model.js b/homework-classes/Model.js
index 25884a133..7fd581376 100755
--- a/homework-classes/Model.js
+++ b/homework-classes/Model.js
@@ -39,13 +39,12 @@
this.notify(this.state);
}
- static fetchJSON(url) {
- return fetch(url).then(res => {
- if (!res.ok) {
- return new Error(`HTTP ${res.status} - ${res.statusText}`);
- }
- return res.status === 200 ? res.json() : null;
- });
+ static async fetchJSON(url) {
+ const fetched = await fetch(url);
+ if (!fetched.ok) {
+ return new Error(`HTTP ${fetched.status} - ${fetched.statusText}`);
+ }
+ return fetched.status === 200 ? fetched.json() : null;
}
}
diff --git a/homework-classes/RepoView.js b/homework-classes/RepoView.js
index 073166fea..26d190323 100755
--- a/homework-classes/RepoView.js
+++ b/homework-classes/RepoView.js
@@ -1,7 +1,7 @@
'use strict';
{
- const { createAndAppend } = window.Util;
+ const { createAndAppend, formatDate } = window.Util;
class RepoView {
constructor(container) {
@@ -19,8 +19,14 @@
* @param {Object} repo A repository object.
*/
render(repo) {
- // TODO: replace this comment and the console.log with your own code
- console.log('RepoView', repo);
+ createAndAppend('div', document.getElementById('root'), {
+ text: `
+ Repository: ${repo.name}
+ Description: ${repo.description}
+ Forks: ${repo.forks_count}
+ Updated: ${formatDate(repo.updated_at)}`,
+ class: 'repo'
+ });
}
}
diff --git a/homework-classes/Util.js b/homework-classes/Util.js
index dc5d79a87..61d40aaa6 100755
--- a/homework-classes/Util.js
+++ b/homework-classes/Util.js
@@ -14,13 +14,35 @@
parent.appendChild(elem);
Object.entries(options).forEach(([key, value]) => {
if (key === 'text') {
- elem.textContent = value;
+ elem.innerHTML = value;
} else {
elem.setAttribute(key, value);
}
});
return elem;
}
+
+ static formatDate(date) {
+ const newDate = new Date(date);
+ let hours = newDate.getHours();
+ let amPm;
+ let minutes = newDate.getMinutes().toString();
+ let seconds = newDate.getSeconds().toString();
+
+ if (minutes < 10) {
+ minutes = `0${hours}`;
+ }
+ if (seconds < 10) {
+ seconds = `0${seconds}`;
+ }
+ if (newDate.getHours() > 12) {
+ hours = hours - 12;
+ amPm = 'PM'
+ } else {
+ amPm = 'AM'
+ }
+ return `${newDate.getMonth() + 1}/${newDate.getDate()}/${newDate.getFullYear()}, ${hours}:${minutes}:${seconds} ${amPm}`;
+ }
}
window.Util = Util;
diff --git a/homework-classes/index.html b/homework-classes/index.html
index ad75b0d08..ab1ae15b7 100755
--- a/homework-classes/index.html
+++ b/homework-classes/index.html
@@ -1,33 +1,32 @@
-