forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Week03 #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
Open
EliaYazdi
wants to merge
18
commits into
master
Choose a base branch
from
week03
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Week03 #3
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
029a974
Created branch
EliaYazdi 370485e
some JS
EliaYazdi 8dae6a6
Week 01
EliaYazdi 8a2a6bc
week01
EliaYazdi f006de3
week- 1
EliaYazdi 45fee40
media Query added!
EliaYazdi a263bff
Week- 1
EliaYazdi 4e1b1bf
Week- 1
EliaYazdi 98ec109
week01.comment deleted!
EliaYazdi bd11d0f
Did the recommended changes!
EliaYazdi ff283c4
First try!
EliaYazdi 64e84a8
changes after the first comments!
EliaYazdi 0fcf093
Doesn't show contribs!
EliaYazdi 59153e2
failed to fetch contributors!
EliaYazdi 0a42ee2
Shows contributors, doesn't update them!
EliaYazdi bfdfa66
appends the contributors!
EliaYazdi f1dd2a7
It's Working!
EliaYazdi 31b0141
week3.classes!
EliaYazdi 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //promises.them and catch | ||
| //build small app that shows ransom dogs and cats | ||
| // try and catch | ||
|
|
||
| //event loop |
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
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 |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta | ||
| name="viewport" | ||
| content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" | ||
| /> | ||
| <meta name="theme-color" content="#000000" /> | ||
| <meta name="apple-mobile-web-app-capable" content="yes" /> | ||
| <meta name="mobile-web-app-capable" content="yes" /> | ||
| <meta name="format-detection" content="telephone=no" /> | ||
| <link rel="apple-touch-icon" href="./hyf.png" /> | ||
| <link rel="shortcut icon" type="image/png" href="./hyf.png" /> | ||
| <title>HYF-GITHUB</title> | ||
| <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" /> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="root"></div> | ||
| <script src="./Util.js"></script> | ||
| <script src="./Repository.js"></script> | ||
| <script src="./Contributor.js"></script> | ||
| <script src="./App.js"></script> | ||
| </body> | ||
| </html> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> | ||
| <meta name="theme-color" content="#000000" /> | ||
| <meta name="apple-mobile-web-app-capable" content="yes" /> | ||
| <meta name="mobile-web-app-capable" content="yes" /> | ||
| <meta name="format-detection" content="telephone=no" /> | ||
| <link rel="apple-touch-icon" href="./hyf.png" /> | ||
| <link rel="shortcut icon" type="image/png" href="./hyf.png" /> | ||
| <title>HYF-GITHUB</title> | ||
| <link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet" /> | ||
| <link rel="stylesheet" href="./style.css" /> | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="root"></div> | ||
| <script src="./Util.js"></script> | ||
| <script src="./Repository.js"></script> | ||
| <script src="./Contributor.js"></script> | ||
| <script src="./App.js"></script> | ||
| </body> | ||
|
|
||
| </html> |
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 |
|---|---|---|
| @@ -1,3 +1,37 @@ | ||
| .alert-error { | ||
| color: red; | ||
| } | ||
|
|
||
| body { | ||
| background-color: rgb(194, 238, 240); | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: flex-start; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| #root { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: flex-start; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| p { | ||
|
|
||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| justify-content: center; | ||
|
|
||
| } | ||
|
|
||
| .img { | ||
| padding: 16px; | ||
| margin-right: 25px; | ||
| flex: row; | ||
| background-color: rgb(170, 218, 240); | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| } |
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 |
|---|---|---|
| @@ -1,46 +1,90 @@ | ||
| 'use strict'; | ||
|
|
||
| { | ||
| function fetchJSON(url, cb) { | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', url); | ||
| xhr.responseType = 'json'; | ||
| xhr.onload = () => { | ||
| if (xhr.status >= 200 && xhr.status <= 299) { | ||
| cb(null, xhr.response); | ||
| } else { | ||
| cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`)); | ||
| } | ||
| }; | ||
| xhr.onerror = () => cb(new Error('Network request failed')); | ||
| xhr.send(); | ||
| } | ||
|
|
||
| function 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; | ||
| } | ||
| function 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; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| async function main(url) { | ||
|
|
||
| createAndAppend('h1', root, { class: 'h1', text: 'Hack Your Future Repositories' }) | ||
| try { | ||
| const response = await fetch(url); | ||
| const json = await response.json(); | ||
| const root = document.getElementById('root'); | ||
| const select = createAndAppend('select', root, { class: 'select' }); | ||
| createAndAppend('option', select, { text: 'Choose your favorite repo' }); | ||
| let sorted = json.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : -1); | ||
|
|
||
| sorted.forEach(repo => { | ||
| const name = repo.name; | ||
|
|
||
| createAndAppend('option', select, { text: name }); | ||
| }) | ||
|
|
||
| function main(url) { | ||
| fetchJSON(url, (err, repositories) => { | ||
| const root = document.getElementById('root'); | ||
| if (err) { | ||
| createAndAppend('div', root, { text: err.message, class: 'alert-error' }); | ||
| return; | ||
|
|
||
| select.addEventListener('change', evt => { | ||
| const selectedRepo = evt.target.value; | ||
| const repo = json.filter(r => r.name == selectedRepo)[0]; | ||
| getContributorInformation(repo); | ||
| repoData(); | ||
|
|
||
| function repoData() { | ||
| repoInfo.innerHTML = 'Repository Information:'; | ||
|
|
||
| const addInfo = (label, value) => { | ||
| const container = createAndAppend('div', repoInfo, { class: 'container' }); | ||
| createAndAppend('span', container, { text: label }); | ||
| createAndAppend('span', container, { text: value }); | ||
| }; | ||
| addInfo('Name: ', repo.name); | ||
| addInfo('Desciption: ', repo.description); | ||
| addInfo('Number of forks: ', repo.forks); | ||
| addInfo('Updated: ', repo.updated_at) | ||
| const contributorsUrl = "https://api.github.com/repos/HackYourFuture/AngularJS/contributors"; | ||
| } | ||
| createAndAppend('pre', root, { text: JSON.stringify(repositories, null, 2) }); | ||
| }); | ||
| }) | ||
|
|
||
|
|
||
| } | ||
| catch (err) { | ||
| const root = document.getElementById('root'); | ||
| createAndAppend('div', root, { text: err.message, class: 'alert-error' }) | ||
| } | ||
|
|
||
| const wraper = createAndAppend('div', root, { class: 'wraper' }); | ||
| const repoInfo = createAndAppend('div', wraper, { class: 'repoinfo' }); | ||
| let contribs = createAndAppend('div', wraper, { class: 'contribs' }); | ||
| contribs.innerHTML = 'Contributors'; | ||
|
|
||
| async function getContributorInformation(data) { | ||
| contribs.innerHTML = ''; | ||
| try { | ||
|
|
||
| const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
| window.onload = () => main(HYF_REPOS_URL); | ||
| const contribsUrl = await fetch(data.contributors_url); | ||
| const contribsJson = await contribsUrl.json(); | ||
| contribsJson.forEach(contributor => { | ||
|
|
||
| createAndAppend('div', contribs, { text: contributor.login, class: 'contributor' }) | ||
| createAndAppend('img', contribs, { src: contributor.avatar_url, height: 150, widtth: 150, id: 'img' }) | ||
| createAndAppend('div', contribs, { text: contributor.contributions }) | ||
| }) | ||
| } catch (err) { | ||
| createAndAppend('div', contribs, { text: err.message, class: 'alert-error' }) | ||
| } | ||
| } | ||
| } | ||
| const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100'; | ||
| window.onload = () => main(HYF_REPOS_URL); | ||
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.
contribshere isn't what you expect. It's the promise from line 63 and not the dom-element from line 35, you need to get it from the dom again (like you do on line 35) and use it in this function.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 changed this. but now the contrinutors_url is undefined!
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.
Not related! Have a look at how you call
getContributorInformationand what arguments it requiresThere 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 I get your point. I forgot to put the argument 'data' in the getContributorInformation function.
I should figure out what to put there !