From a977b1abe803089eadba52d89f158381fa7aaeef Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Mon, 27 May 2019 10:58:42 +0200 Subject: [PATCH 1/9] first commit --- alfi.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 alfi.txt diff --git a/alfi.txt b/alfi.txt new file mode 100644 index 000000000..16dd8b77b --- /dev/null +++ b/alfi.txt @@ -0,0 +1 @@ +Master Javascript3 From a123136b328ffaae7616247161d1af3bdeb781ab Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Mon, 27 May 2019 11:01:02 +0200 Subject: [PATCH 2/9] first commit branch week 1 --- alfi.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alfi.txt b/alfi.txt index 16dd8b77b..8ab9d8d2b 100644 --- a/alfi.txt +++ b/alfi.txt @@ -1 +1 @@ -Master Javascript3 +Week 1 Homework From 328920a75008c8ecd13b84ce9fd8ac562ced6256 Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Thu, 30 May 2019 15:25:58 +0200 Subject: [PATCH 3/9] first commit --- homework/index.js | 102 ++++++++++++++++++++++++++++++++++++++++++++- homework/style.css | 92 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 192 insertions(+), 2 deletions(-) diff --git a/homework/index.js b/homework/index.js index d3a97645e..db6d101fe 100644 --- a/homework/index.js +++ b/homework/index.js @@ -31,14 +31,114 @@ } 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 rootContainer = document.getElementById("root"); + const header = document.createElement("header"); + header.className = "header"; + const titleHeader = document.createElement("p"); + titleHeader.innerHTML = "HYF Repositories: "; + const repoSelector = document.createElement("select"); + repoSelector.className = "repo-selector"; + header.appendChild(titleHeader); + header.appendChild(repoSelector); + + const container = document.createElement("div"); + container.className = "container"; + + const containerLeft = document.createElement("div"); + containerLeft.className = "left-div"; + containerLeft.className += " whiteframe"; + + const containerRight = document.createElement("div"); + containerRight.className = "right-div"; + containerRight.className += " whiteframe"; + + const table = document.createElement("table"); + const tableBody = document.createElement("tbody"); + table.appendChild(tableBody); + containerLeft.appendChild(table); + const removeAllChildren = (parent) => { + while (parent.firstChild) { + parent.removeChild(parent.firstChild); + } + }; + const contributorHeader = document.createElement("p"); + contributorHeader.className = "contributor-header"; + contributorHeader.innerHTML = "Contributors"; + const contributorList = document.createElement("ul"); + contributorList.className = "contributor-list"; + containerRight.appendChild(contributorHeader); + containerRight.appendChild(contributorList); + + container.appendChild(containerLeft); + container.appendChild(containerRight); + rootContainer.appendChild(header); + rootContainer.appendChild(container); + + + const repos = document.querySelector(".repo-selector"); + data.sort(function (a, b) { + return a.name.localeCompare(b.name); + }); + + repos.innerHTML = data.map( + (repo, i) => `` + ).join(""); + + const tableRow = document.createElement("tr"); + tableBody.appendChild(tableRow); + + const makeRow = (label, content) => { + const tableRow = document.createElement("tr"); + tableBody.appendChild(tableRow); + const tableData = document.createElement("td"); + const repoName = document.createElement("td"); + tableRow.appendChild(tableData); + tableRow.appendChild(repoName); + tableData.innerHTML = label; + tableData.className = "label"; + repoName.innerHTML = content; + }; + const createContributorItems = (url) => { + fetch(url) + .then(response => response.json()) + .then(data => { + contributorList.innerHTML = data.map((item, i) => + `
  • + +
    + ${item.login} + ${item.contributions} +
    +
  • `) + .join(""); + + }); + }; + const createRepoInfo = (repoId) => { + makeRow("Repository: ", `${data[repoId].name}`); + makeRow("Description: ", data[repoId].description); + makeRow("Forks: ", data[repoId].forks); + makeRow("Updated: ", new Date(data[repoId].updated_at).toLocaleDateString("en-US")); + }; + const setRepo = (repoId) => { + removeAllChildren(tableRow); + createRepoInfo(repoId); + createContributorItems(data[repoId].contributors_url); + }; + setRepo(0); + repos.addEventListener("change", function(){ + const repoId = this.value; + setRepo(repoId); + }); } }); + } const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; diff --git a/homework/style.css b/homework/style.css index a8985a8a5..b7faec3cb 100644 --- a/homework/style.css +++ b/homework/style.css @@ -1,3 +1,93 @@ +body { + font-family: 'Roboto', sans-serif; +} +header { + background-color: #a1c7cb; + display: flex; + padding-left: 2em; + align-items: center; + margin-bottom: 2em; +} +#root { + margin: 0 auto; + width: 960px; +} +.repo-selector { + margin-left: 2em; + font-size: 14px; + width: 250px; + height: 32px; +} +.container { + display: flex; + align-items: flex-start; + flex-direction: row; +} +.left-div { + display: flex; + flex-direction: column; + padding: 16px; + margin-right: 16px; + flex: 1; +} +.right-div { + display: flex; + flex-direction: column; + padding: 16px; + margin-right: 16px; + flex: 1; +} + +td { + vertical-align: top; +} +td.label { + font-weight: bold; +} +.whiteframe { + margin-bottom: 8px; + border: none; + border-radius: 2px; + background-color: #fff; + box-shadow: 0 1px 8px 0 rgba(0, 0, 0, .2), 0 3px 4px 0 rgba(0, 0, 0, .14), 0 3px 3px -2px rgba(0, 0, 0, .12); +} +.contributor-avatar { + border-radius: 3px; + margin-right: 16px; +} +.contributor-list { + list-style-type: none; + padding: 0; + margin: 0; +} +.contributor-header { + font-size: 0.8rem; + color: rgb(0, 0, 0, 54%); + padding: 8px 16px 4px 16px; +} +.contributor-item { + border-bottom: solid 1px rgb(0, 0, 0, 12%); + padding: 16px; + display: flex; + flex-direction: row; + align-items: center; + cursor: pointer; +} +.contributor-data { + flex: 1; + display: flex; + flex-direction: row; + justify-content: space-between; + align-content: center; +} +.contributor-badge { + font-size: 12px; + padding: 2px 8px; + line-height: 1rem; + background-color: gray; + color: white; + border-radius: 4px; +} .alert-error { color: red; -} \ No newline at end of file +} From 4010b41524646e877c538847fd81582abaf3174e Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Thu, 6 Jun 2019 20:15:30 +0200 Subject: [PATCH 4/9] fixing a bug at setRepo() --- homework/index.js | 110 +++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/homework/index.js b/homework/index.js index db6d101fe..1cf565547 100644 --- a/homework/index.js +++ b/homework/index.js @@ -31,47 +31,46 @@ } function main(url) { - fetchJSON(url, (err, data) => { const root = document.getElementById('root'); if (err) { - createAndAppend('div', root, { text: err.message, class: 'alert-error' }); + createAndAppend('div', root, {text: err.message, class: 'alert-error'}); } else { - const rootContainer = document.getElementById("root"); - const header = document.createElement("header"); - header.className = "header"; - const titleHeader = document.createElement("p"); - titleHeader.innerHTML = "HYF Repositories: "; - const repoSelector = document.createElement("select"); - repoSelector.className = "repo-selector"; + const rootContainer = document.getElementById('root'); + const header = document.createElement('header'); + header.className = 'header'; + const titleHeader = document.createElement('p'); + titleHeader.innerHTML = 'HYF Repositories: '; + const repoSelector = document.createElement('select'); + repoSelector.className = 'repo-selector'; header.appendChild(titleHeader); header.appendChild(repoSelector); - const container = document.createElement("div"); - container.className = "container"; + const container = document.createElement('div'); + container.className = 'container'; - const containerLeft = document.createElement("div"); - containerLeft.className = "left-div"; - containerLeft.className += " whiteframe"; + const containerLeft = document.createElement('div'); + containerLeft.className = 'left-div'; + containerLeft.className += ' whiteframe'; - const containerRight = document.createElement("div"); - containerRight.className = "right-div"; - containerRight.className += " whiteframe"; + const containerRight = document.createElement('div'); + containerRight.className = 'right-div'; + containerRight.className += ' whiteframe'; - const table = document.createElement("table"); - const tableBody = document.createElement("tbody"); + const table = document.createElement('table'); + const tableBody = document.createElement('tbody'); table.appendChild(tableBody); containerLeft.appendChild(table); - const removeAllChildren = (parent) => { + const removeAllChildren = parent => { while (parent.firstChild) { parent.removeChild(parent.firstChild); } }; - const contributorHeader = document.createElement("p"); - contributorHeader.className = "contributor-header"; - contributorHeader.innerHTML = "Contributors"; - const contributorList = document.createElement("ul"); - contributorList.className = "contributor-list"; + const contributorHeader = document.createElement('p'); + contributorHeader.className = 'contributor-header'; + contributorHeader.innerHTML = 'Contributors'; + const contributorList = document.createElement('ul'); + contributorList.className = 'contributor-list'; containerRight.appendChild(contributorHeader); containerRight.appendChild(contributorList); @@ -80,65 +79,68 @@ rootContainer.appendChild(header); rootContainer.appendChild(container); + const repos = document.querySelector('.repo-selector'); + data.sort((a, b) => a.name.localeCompare(b.name)); - const repos = document.querySelector(".repo-selector"); - data.sort(function (a, b) { - return a.name.localeCompare(b.name); - }); - - repos.innerHTML = data.map( - (repo, i) => `` - ).join(""); + repos.innerHTML = data + .map((repo, i) => ``) + .join(''); - const tableRow = document.createElement("tr"); + const tableRow = document.createElement('tr'); tableBody.appendChild(tableRow); const makeRow = (label, content) => { - const tableRow = document.createElement("tr"); + const tableRow = document.createElement('tr'); tableBody.appendChild(tableRow); - const tableData = document.createElement("td"); - const repoName = document.createElement("td"); + const tableData = document.createElement('td'); + const repoName = document.createElement('td'); tableRow.appendChild(tableData); tableRow.appendChild(repoName); tableData.innerHTML = label; - tableData.className = "label"; + tableData.className = 'label'; repoName.innerHTML = content; }; - const createContributorItems = (url) => { + const createContributorItems = url => { fetch(url) .then(response => response.json()) .then(data => { - contributorList.innerHTML = data.map((item, i) => - `
  • + contributorList.innerHTML = data + .map( + (item, i) => + `
  • ${item.login} - ${item.contributions} + ${item.contributions}
    -
  • `) - .join(""); - + `, + ) + .join(''); }); }; - const createRepoInfo = (repoId) => { - makeRow("Repository: ", `${data[repoId].name}`); - makeRow("Description: ", data[repoId].description); - makeRow("Forks: ", data[repoId].forks); - makeRow("Updated: ", new Date(data[repoId].updated_at).toLocaleDateString("en-US")); + const createRepoInfo = repoId => { + makeRow( + 'Repository: ', + `${ + data[repoId].name + }`, + ); + makeRow('Description: ', data[repoId].description); + makeRow('Forks: ', data[repoId].forks); + makeRow('Updated: ', new Date(data[repoId].updated_at).toLocaleDateString('en-US')); }; - const setRepo = (repoId) => { - removeAllChildren(tableRow); + const setRepo = repoId => { + removeAllChildren(tableBody); createRepoInfo(repoId); createContributorItems(data[repoId].contributors_url); }; setRepo(0); - repos.addEventListener("change", function(){ + repos.addEventListener('change', function() { const repoId = this.value; setRepo(repoId); }); } }); - } const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; From f1169bee4ec39191404331e69e320acd71c94f65 Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Thu, 6 Jun 2019 20:32:19 +0200 Subject: [PATCH 5/9] styling error message --- homework/index.js | 18 +++++++++++------- homework/style.css | 7 ++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/homework/index.js b/homework/index.js index 1cf565547..cc8fa1998 100644 --- a/homework/index.js +++ b/homework/index.js @@ -1,7 +1,7 @@ 'use strict'; { - function fetchJSON(url, cb) { + const fetchJSON = (url, cb) => { const xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = 'json'; @@ -9,14 +9,18 @@ if (xhr.status < 400) { cb(null, xhr.response); } else { - cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`)); + cb( + new Error( + `Sorry, there's something wrong. Network error : ${xhr.status} - ${xhr.statusText}.`, + ), + ); } }; xhr.onerror = () => cb(new Error('Network request failed')); xhr.send(); - } + }; - function createAndAppend(name, parent, options = {}) { + const createAndAppend = (name, parent, options = {}) => { const elem = document.createElement(name); parent.appendChild(elem); Object.keys(options).forEach(key => { @@ -28,9 +32,9 @@ } }); return elem; - } + }; - function main(url) { + const main = url => { fetchJSON(url, (err, data) => { const root = document.getElementById('root'); if (err) { @@ -141,7 +145,7 @@ }); } }); - } + }; const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; diff --git a/homework/style.css b/homework/style.css index b7faec3cb..b7429ba8f 100644 --- a/homework/style.css +++ b/homework/style.css @@ -89,5 +89,10 @@ td.label { border-radius: 4px; } .alert-error { - color: red; + color: white; + background-color: pink; + font-size: 1.4em; + font-family: Roboto; + padding: 1em; + border-radius: 1em; } From 65347d1cdcc870d4d06917cf65d53eb81cc123a0 Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Fri, 7 Jun 2019 00:16:58 +0200 Subject: [PATCH 6/9] responsive and fetch promises --- homework/index.js | 58 ++++------------ homework/style.css | 160 ++++++++++++++++++++++++++++++--------------- 2 files changed, 120 insertions(+), 98 deletions(-) diff --git a/homework/index.js b/homework/index.js index cc8fa1998..94b148f05 100644 --- a/homework/index.js +++ b/homework/index.js @@ -1,45 +1,10 @@ 'use strict'; { - const fetchJSON = (url, cb) => { - const xhr = new XMLHttpRequest(); - xhr.open('GET', url); - xhr.responseType = 'json'; - xhr.onload = () => { - if (xhr.status < 400) { - cb(null, xhr.response); - } else { - cb( - new Error( - `Sorry, there's something wrong. Network error : ${xhr.status} - ${xhr.statusText}.`, - ), - ); - } - }; - xhr.onerror = () => cb(new Error('Network request failed')); - xhr.send(); - }; - - const createAndAppend = (name, parent, options = {}) => { - const elem = document.createElement(name); - parent.appendChild(elem); - Object.keys(options).forEach(key => { - const value = options[key]; - if (key === 'text') { - elem.textContent = value; - } else { - elem.setAttribute(key, value); - } - }); - return elem; - }; - const main = url => { - fetchJSON(url, (err, data) => { - const root = document.getElementById('root'); - if (err) { - createAndAppend('div', root, {text: err.message, class: 'alert-error'}); - } else { + fetch(url) + .then(response => response.json()) + .then(data => { const rootContainer = document.getElementById('root'); const header = document.createElement('header'); header.className = 'header'; @@ -112,12 +77,12 @@ .map( (item, i) => `
  • - -
    - ${item.login} - ${item.contributions} -
    -
  • `, + +
    + ${item.login} + ${item.contributions} +
    + `, ) .join(''); }); @@ -143,8 +108,9 @@ const repoId = this.value; setRepo(repoId); }); - } - }); + }) + .catch(() => {}); + // const root = document.getElementById('root'); }; const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; diff --git a/homework/style.css b/homework/style.css index b7429ba8f..672d59b6c 100644 --- a/homework/style.css +++ b/homework/style.css @@ -1,70 +1,100 @@ body { - font-family: 'Roboto', sans-serif; -} -header { - background-color: #a1c7cb; - display: flex; - padding-left: 2em; - align-items: center; - margin-bottom: 2em; -} -#root { - margin: 0 auto; - width: 960px; -} -.repo-selector { - margin-left: 2em; - font-size: 14px; - width: 250px; - height: 32px; + width: 768px; + margin-left: auto; + margin-right: auto; + + font-family: 'Roboto', sans-serif; + color: rgb(0, 0, 0, 87%); + margin-top: 0; } + .container { - display: flex; - align-items: flex-start; - flex-direction: row; + display: flex; + flex-direction: row; + align-items: flex-start; } -.left-div { - display: flex; - flex-direction: column; - padding: 16px; - margin-right: 16px; - flex: 1; + +@media (max-width: 767px) { + body { + width: 100%; + } + .container { + margin: 0; + flex-direction: column; + align-items: stretch; + } } -.right-div { - display: flex; - flex-direction: column; - padding: 16px; - margin-right: 16px; - flex: 1; + +h1, +h2, +h3, +h4 { + color: rgb(0, 0, 0, 54%); } -td { - vertical-align: top; +.header { + color: white; + background-color: #a1c7cb; + padding: 8px 16px; + margin-bottom: 16px; + display: flex; + flex-direction: row; + align-items: center; } -td.label { - font-weight: bold; + +.repo-selector { + margin-left: 16px; + font-size: 14px; + width: 250px; + height: 32px; + padding: 2px; } -.whiteframe { - margin-bottom: 8px; - border: none; - border-radius: 2px; - background-color: #fff; - box-shadow: 0 1px 8px 0 rgba(0, 0, 0, .2), 0 3px 4px 0 rgba(0, 0, 0, .14), 0 3px 3px -2px rgba(0, 0, 0, .12); + +.left-div, +.right-div { + background-color: white; + flex: 1; } -.contributor-avatar { - border-radius: 3px; + +.left-div { + padding: 16px; margin-right: 16px; } + +@media (max-width: 767px) { + .left-div { + margin: 0; + } +} + .contributor-list { list-style-type: none; padding: 0; margin: 0; } + +.alert { + padding: .75rem 1.25rem; + margin-bottom: 1rem; + border-radius: .25rem; + flex: 1; +} + +.alert-error { + color: white; + background-color: pink; + font-size: 1.4em; + font-family: Roboto; + padding: 1em; + border-radius: 1em; +} + .contributor-header { font-size: 0.8rem; color: rgb(0, 0, 0, 54%); padding: 8px 16px 4px 16px; } + .contributor-item { border-bottom: solid 1px rgb(0, 0, 0, 12%); padding: 16px; @@ -73,6 +103,12 @@ td.label { align-items: center; cursor: pointer; } + +.contributor-avatar { + border-radius: 3px; + margin-right: 16px; +} + .contributor-data { flex: 1; display: flex; @@ -80,6 +116,7 @@ td.label { justify-content: space-between; align-content: center; } + .contributor-badge { font-size: 12px; padding: 2px 8px; @@ -88,11 +125,30 @@ td.label { color: white; border-radius: 4px; } -.alert-error { - color: white; - background-color: pink; - font-size: 1.4em; - font-family: Roboto; - padding: 1em; - border-radius: 1em; + +table { + table-layout: fixed; + color: rgb(0, 0, 0, 81%); +} + +td { + vertical-align: top; +} + +td:first-child { + width: 100px; + min-width: 100px; + max-width: 100px; +} + +td.label { + font-weight: bold; +} + +.whiteframe { + margin-bottom: 8px; + border: none; + border-radius: 2px; + background-color: #fff; + box-shadow: 0 1px 8px 0 rgba(0, 0, 0, .2), 0 3px 4px 0 rgba(0, 0, 0, .14), 0 3px 3px -2px rgba(0, 0, 0, .12); } From 7389763510986857743bf2acbc81ef739e1ceefb Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Sat, 8 Jun 2019 13:55:12 +0200 Subject: [PATCH 7/9] text error added --- homework/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/homework/index.js b/homework/index.js index 94b148f05..aadb3a0e2 100644 --- a/homework/index.js +++ b/homework/index.js @@ -2,10 +2,13 @@ { const main = url => { + const rootContainer = document.getElementById('root'); + const container = document.createElement('div'); + container.className = 'container'; + const containerDiv = document.querySelector('.container'); fetch(url) .then(response => response.json()) .then(data => { - const rootContainer = document.getElementById('root'); const header = document.createElement('header'); header.className = 'header'; const titleHeader = document.createElement('p'); @@ -15,9 +18,6 @@ header.appendChild(titleHeader); header.appendChild(repoSelector); - const container = document.createElement('div'); - container.className = 'container'; - const containerLeft = document.createElement('div'); containerLeft.className = 'left-div'; containerLeft.className += ' whiteframe'; @@ -109,11 +109,16 @@ setRepo(repoId); }); }) - .catch(() => {}); - // const root = document.getElementById('root'); + .catch(() => { + container.parentNode.removeChild(container); + const divError = document.createElement('div'); + rootContainer.appendChild(divError); + divError.className = 'alert-error '; + divError.innerHTML = `Sorry, there's something wrong.`; + }); }; - const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; + const HYF_REPOS_URL = 'https://api.github.com/orgs1x/HackYourFuture/repos?per_page=100'; window.onload = () => main(HYF_REPOS_URL); } From c232ecd0fb6941de8f691b682db6a8cf0ffd0399 Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Sun, 9 Jun 2019 12:14:42 +0200 Subject: [PATCH 8/9] fixed minors --- homework/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homework/index.js b/homework/index.js index aadb3a0e2..c59e994b1 100644 --- a/homework/index.js +++ b/homework/index.js @@ -5,7 +5,7 @@ const rootContainer = document.getElementById('root'); const container = document.createElement('div'); container.className = 'container'; - const containerDiv = document.querySelector('.container'); + fetch(url) .then(response => response.json()) .then(data => { @@ -118,7 +118,7 @@ }); }; - const HYF_REPOS_URL = 'https://api.github.com/orgs1x/HackYourFuture/repos?per_page=100'; + const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; window.onload = () => main(HYF_REPOS_URL); } From 67d2a5d0aaccadc427e3372204b9f644ba8ba2ee Mon Sep 17 00:00:00 2001 From: Alfi Yusrina Date: Sun, 16 Jun 2019 00:59:23 +0200 Subject: [PATCH 9/9] added by using classes now --- homework/App.js | 34 ++++++++++++++++++++++++++++------ homework/Contributor.js | 17 ++++++++++++++++- homework/Repository.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/homework/App.js b/homework/App.js index 32b71e34b..84263c424 100644 --- a/homework/App.js +++ b/homework/App.js @@ -12,23 +12,37 @@ class App { * @param {string} url The GitHub URL for obtaining the organization's repositories. */ async initialize(url) { - // Add code here to initialize your app - // 1. Create the fixed HTML elements of your page // 2. Make an initial XMLHttpRequest using Util.fetchJSON() to populate your