-
Notifications
You must be signed in to change notification settings - Fork 280
Conversation
remarcmij
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @whitepiolin, overall pretty good work. Check again the correct order of .catch() and .then() methods in a promise chain (see the link provided in the detail comment).
homework/src/index.js
Outdated
| const repoSelect = createAndAppend("select", divSelect); | ||
| const divFlex = createAndAppend("section", root); | ||
| const divInfo = createAndAppend("article", divFlex, { id: "divInfo" }); | ||
| const divCont = createAndAppend("article", divFlex, { id: "divCont" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Lines 33-44 are best placed inside the
main()function, at the beginning, just before the call tofetchJSON(). This will ensure that this code is executed after the web page has been fully loaded. If you place it outside any function like you do here there is a change, for instance, that thedivwith anidofroothasn't been created in the DOM yet. In that case your code will fail. -
I like that you are using semantic HTML tags here instead of just
divtag. It reminds me that I should do this more often myself 😉.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| const trForks = createAndAppend("tr", tBody); | ||
| createAndAppend("td", trForks, { html: "Forks : " }); | ||
| const tdForksLink = createAndAppend("td", trForks, ); | ||
| const linkForks = createAndAppend('a', tdForksLink, { html: repository.forks, href: repository.forks_url }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linkForks variable is unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| const trRepository = createAndAppend("tr", tBody); | ||
| createAndAppend("td", trRepository, { html: "Repository : " }); | ||
| const tdRepoLink = createAndAppend("td", trRepository, ); | ||
| const linkRepository = createAndAppend('a', tdRepoLink, { html: repository.name, href: repository.html_url }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linkRepository variable is unused (you can probably see in VSCode a wavy underline on the variable warning about this). You should only define variables if you have a need for them, otherwise they just become noise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
| return; | ||
| }) | ||
| .then(repositories => { | ||
| repositories.forEach((repository, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assignment asked for the list of repositories to be sorted alphabetically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| createAndAppend('pre', root, { html: JSON.stringify(data, null, 2) }); | ||
| const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
| const root = document.getElementById('root'); | ||
| createAndAppend("img", root, { src: "./hyf.png", id: "imgLogo" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This HYF logo is the least important to have in UI but takes up the most prominent place on the web page. It pushes the relevant content down. So, not a JavaScript issue, but more of a UX (User Experience) issue. Make sure that you use screen space (we sometimes call it screen real-estate) in the most effective way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| .catch(error => { | ||
| const divError = createAndAppend("container", root, { id: "divError" }); | ||
| divError.innerHTML = ""; | ||
| divError.innerHTML = error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @JawharBairakdar already pointed to line 51 serving no purpose in the week 1 review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| function main(HYF_REPOS_URL) { | ||
|
|
||
| fetchJSON(HYF_REPOS_URL) | ||
| .catch(error => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .catch() method should (almost) always be placed as the last method in the promise chain. See the link to the fundamental on promises below. When I force an error by tweaking the url a bit I can see that you are rendering the error in the UI but I also see this error message in the console:
index.js:56 Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined
at fetchJSON.catch.then.repositories (index.js:56)
After the catch() method is executed the JavaScript runtime happily continues executing the next .then() in the chain, which gets the value of undefined for its repositories parameter. That is why you a complaint about trying to use forEach of undefined.
https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/promises.md#promise-chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| createAndAppend('h2', divCont, { html: "Contributions", class: "h2" }); | ||
|
|
||
| fetchJSON(repository.contributors_url) | ||
| .catch(error => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This catch() should go to the end of the chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| fetchJSON(repository.contributors_url) | ||
| .catch(error => { | ||
| createAndAppend('div', root, { html: error.message, class: 'alert-error' }); | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return is useless. It just return from the arrow function passed to catch(). It would return anyway on the ending curly brace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
homework/src/index.js
Outdated
| const divError = createAndAppend("container", root, { id: "divError" }); | ||
| divError.innerHTML = ""; | ||
| divError.innerHTML = error; | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return is useless. It just return from the arrow function passed to catch(). It would return anyway on the ending curly brace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected
remarcmij
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! (but still think the logo needs to go or placed elsewhere).
No description provided.