forked from foocoding/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Week3 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Week3 #3
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6dbf67a
Week1-Assignment
Radhikajram 625ee8e
removed console.log statement
Radhikajram 5e79378
changed naming conventions as per the review comments
Radhikajram ad0433e
Changed css Ids to Kebab-case
Radhikajram 76a1726
Use Fetch/Promise to get API data
Radhikajram d43ea2b
Merge pull request #1 from Radhikajram/Week1
Radhikajram c8a7ee9
Modified all the for loops so as to remove eslint compliance.
Radhikajram f3d323c
Merge pull request #2 from Radhikajram/Week2
Radhikajram 10fbc8b
Week3- Changes
Radhikajram 57c0b74
removed the console.log
Radhikajram File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,14 +16,77 @@ class App { | |
| // 1. Create the fixed HTML elements of your page | ||
| // 2. Make an initial XMLHttpRequest using Util.fetchJSON() to populate your <select> element | ||
|
|
||
| const BodyEl = document.body; | ||
|
|
||
| const root = document.getElementById('root'); | ||
|
|
||
| Util.createAndAppend('h1', root, { text: 'It works!' }); // TODO: replace with your own code | ||
| // Create div element 'select' in document body to hold the label element and list box. | ||
|
|
||
| Util.createAndAppend('div', BodyEl, { id: 'select-container' }); | ||
| const select = document.getElementById('select-container'); | ||
| Util.createAndAppend('LABEL', select, { | ||
| text: 'HYF Repositories: ', | ||
| id: 'label', | ||
| for: 'repo', | ||
| }); | ||
| Util.createAndAppend('select', select, { id: 'select-repo' }); | ||
|
|
||
| // Create two div elements section1 and section2 under 'Root' div to have | ||
| // section1 - Repository Information. | ||
| // section2 - Contributions. | ||
|
|
||
| Util.createAndAppend('div', root, { id: 'repo-details' }); | ||
| Util.createAndAppend('div', root, { id: 'contributor-information' }); | ||
|
|
||
| // Insert section1 before section2 div element under 'root' div. | ||
| const newNode = document.getElementById('contributor-information'); | ||
| const referenceNode = document.querySelector('repo-details'); | ||
| root.insertBefore(newNode, referenceNode); | ||
|
|
||
| // Insert Select div first in the body before root div. | ||
| BodyEl.insertBefore(select, document.getElementById('root')); | ||
|
|
||
| try { | ||
| const repos = await Util.fetchJSON(url); | ||
|
|
||
| this.repos = repos.map(repo => new Repository(repo)); | ||
| // TODO: add your own code here | ||
|
|
||
| const sortRepoName = []; | ||
| // push all the HYP repo names to sort array. | ||
|
|
||
| Object.keys(repos).forEach(key => { | ||
| sortRepoName.push(repos[key].name); | ||
| }); | ||
| // sort the repo name using sort function and localeComapare for uppercase and lowercase sorting. | ||
| sortRepoName.sort((a, b) => a.localeCompare(b)); | ||
|
|
||
| const selectBox = document.getElementById('select-repo'); | ||
|
|
||
| // Create Option under Select element and attach the same with SELECT element. | ||
|
|
||
| sortRepoName.forEach(loadrepo => { | ||
| const option = document.createElement('option'); | ||
| option.value = loadrepo; | ||
| option.text = loadrepo; | ||
| selectBox.appendChild(option); | ||
| }); | ||
|
|
||
| let keyIndex; | ||
| Object.keys(repos).forEach(key => { | ||
| if (selectBox.value === repos[key].name) { | ||
| keyIndex = key; | ||
| } | ||
| }); | ||
| this.fetchContributorsAndRender(keyIndex); | ||
|
|
||
| selectBox.addEventListener('change', () => { | ||
| Object.keys(repos).forEach(key => { | ||
| if (selectBox.value === repos[key].name) { | ||
| keyIndex = key; | ||
| } | ||
| }); | ||
| this.fetchContributorsAndRender(keyIndex); | ||
| }); | ||
| } catch (error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This catch could probably just wrap the |
||
| this.renderError(error); | ||
| } | ||
|
|
@@ -46,14 +109,18 @@ class App { | |
| */ | ||
| async fetchContributorsAndRender(index) { | ||
| try { | ||
| console.log(index); | ||
| const repo = this.repos[index]; | ||
| const contributors = await repo.fetchContributors(); | ||
|
|
||
| const container = document.getElementById('container'); | ||
| const container = document.getElementById('repo-details'); | ||
| App.clearContainer(container); | ||
|
|
||
| const leftDiv = Util.createAndAppend('div', container); | ||
| const rightDiv = Util.createAndAppend('div', container); | ||
| const contributorContainer = document.getElementById('contributor-information'); | ||
| App.clearContainer(contributorContainer); | ||
|
|
||
| const leftDiv = 'repo-details'; | ||
| const rightDiv = document.getElementById('contributor-information'); | ||
|
|
||
| const contributorList = Util.createAndAppend('ul', rightDiv); | ||
|
|
||
|
|
@@ -69,13 +136,12 @@ class App { | |
|
|
||
| /** | ||
| * Render an error to the DOM. | ||
| * @param {Error} error An Error object describing the error. | ||
| * @param {Error} error An Error object describing the1 2 error. | ||
| */ | ||
| renderError(error) { | ||
| console.log(error); // TODO: replace with your own code | ||
| } | ||
| } | ||
|
|
||
| const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
|
|
||
| window.onload = () => new App(HYF_REPOS_URL); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Really solid comments 👍