Repository navigation
Homework week3 #6
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
annagabain
wants to merge
5
commits into
master
Choose a base branch
from
homework-week3
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c4d93b
async-await- try-catch
annagabain 2188805
just my class trainer function so far :S
annagabain 9ed323d
tested steps in the end
annagabain 9c3776f
worked with Util. in app.js
annagabain 5d27d2d
Repository and Contributor classes
annagabain 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
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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
|
|
||
|
|
||
| class Person { | ||
| constructor (name, age, height, eyecolour) { | ||
| this.name = name; | ||
| this.age = age; | ||
| this.height = height; | ||
| this.eyecolour = eyecolour; | ||
| } | ||
|
|
||
| descriptiveSentence(){ | ||
| return this.name + ' is ' + this.age + ' years old'+ ', ' + this.height + ' cm tall'+ ' and has ' + this.eyecolour + ' eyes.' | ||
| } | ||
| } | ||
|
|
||
|
|
||
| class People { | ||
| constructor(person1, person2) { | ||
| this.person1=person1 | ||
| this.person2=person2 | ||
| } | ||
| descriptiveSentence(){ | ||
| return this.person1.descriptiveSentence() + '\n' + this.person2.descriptiveSentence() | ||
| //return this.name + ' is ' + this.age + ', ' + this.height + ' cm tall'+ ' and has ' + this.eyecolour + ' eyes' | ||
| } | ||
|
|
||
| } | ||
|
|
||
| class MorePeople { | ||
| constructor(peopleList) { | ||
| this.peopleList=peopleList | ||
| } | ||
| descriptiveSentence(){ | ||
| let collectAllthePersons = "" | ||
| for ( let person of peopleList){ | ||
|
|
||
| collectAllthePersons += person.descriptiveSentence() + '\n' | ||
|
|
||
| } | ||
|
|
||
| return collectAllthePersons | ||
| } | ||
| } | ||
|
|
||
| let person1 = new Person('John', 25, 180, 'blue') | ||
| let person2 = new Person('Jane', 28, 160, 'green') | ||
|
|
||
| let person3 = new Person('Jack', 64, 190, 'brown') | ||
| let person4 = new Person('Anna', 30, 168, 'gray-green') | ||
|
|
||
| const people = new People (person1, person2,) | ||
|
|
||
| const peopleList = [person1, person2, person3, person4] | ||
| const morePeople = new MorePeople (peopleList) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| console.log(morePeople.descriptiveSentence()) | ||
|
|
||
|
|
||
| // Tested Steps | ||
| // console.log(person1.name + ' is ' + person1.age + ', ' + person1.height + ' cm tall'+ ' and has ' + person1.eyecolour + ' eyes') | ||
| // console.log(person1.descriptiveSentence()) //John is 25, 180 cm tall and has blue eyes | ||
| // console.log(person2.descriptiveSentence()) //Jane is 28, 160 cm tall and has green eyes. | ||
| // console.log(people.descriptiveSentence()) | ||
| //John is 25, 180 cm tall and has blue eyes | ||
| //Jane is 28, 160 cm tall and has green eyes. | ||
|
|
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 |
|---|---|---|
|
|
@@ -30,4 +30,4 @@ class Repository { | |
| name() { | ||
| return this.repository.name; | ||
| } | ||
| } | ||
| } | ||
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,23 +1,43 @@ | ||
| <!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> | ||
|
|
||
| <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> | ||
| <header> | ||
| <div id="root"> | ||
| <label>HYF Repositories </label> | ||
| </div> | ||
|
|
||
| <body> | ||
| <div id="root"></div> | ||
| <script src="./index.js"></script> | ||
| </body> | ||
| </header> | ||
|
|
||
| <body> | ||
|
|
||
| <div id="container"> | ||
| <div id="forRepoBlock"><p>Repositories</p></div> | ||
|
|
||
| <div id="forContributorsBlock"> | ||
| <div><p>Contributions</p></div> | ||
| <!-- <div><p>Name</p></div> | ||
| <div><p>Number of contributions</p></div> | ||
| <div><p>Picture</p></div> --> | ||
|
|
||
| </html> | ||
| </div> | ||
|
|
||
| <script src="./index.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,21 +1,27 @@ | ||
| 'use strict'; | ||
|
|
||
| { | ||
| function 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(`Network error: ${xhr.status} - ${xhr.statusText}`)); | ||
| } | ||
| }; | ||
| xhr.onerror = () => cb(new Error('Network request failed')); | ||
| xhr.send(); | ||
| function fetchJSON(url) { | ||
| return new Promise((resolve, reject) => { | ||
| const xhr = new XMLHttpRequest(); | ||
| xhr.open('GET', url); | ||
| xhr.responseType = 'json'; | ||
| xhr.onload = () => { | ||
| if (xhr.status < 400) { | ||
| resolve(xhr.response); | ||
| } else { | ||
| reject(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`)); | ||
| } | ||
| }; | ||
| xhr.onerror = () => { | ||
| reject(new Error('Network request failed')); | ||
| }; | ||
| xhr.send(); | ||
| }) | ||
|
|
||
| } | ||
|
|
||
|
|
||
| function createAndAppend(name, parent, options = {}) { | ||
| const elem = document.createElement(name); | ||
| parent.appendChild(elem); | ||
|
|
@@ -30,18 +36,80 @@ | |
| return elem; | ||
| } | ||
|
|
||
| function main(url) { | ||
| fetchJSON(url, (err, data) => { | ||
| function compare(a, b) { | ||
| if (a.name<b.name){ | ||
| return -1; | ||
| } | ||
| if (a.name>b.name){ | ||
| return 1 | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| async function main(url) { | ||
| try { | ||
| const repositoryData = await fetchJSON(url); | ||
|
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. The async/await rewrite looks good! |
||
| const select = createAndAppend('select', root); | ||
| // createAndAppend('option', select, { text: 'Click here to choose a Repository' }); | ||
|
|
||
| let alphabeticalSorting = repositoryData.sort(compare); | ||
| alphabeticalSorting.forEach(repo => { | ||
| const name = repo.name; | ||
| createAndAppend('option', select, { text: name }); | ||
| }); | ||
|
|
||
| const repoInfo = createAndAppend('div', forRepoBlock); | ||
| const contribs = createAndAppend('div', forContributorsBlock); | ||
|
|
||
| select.addEventListener('change', evt => { | ||
| const selectedRepo = evt.target.value; | ||
| const repo = alphabeticalSorting.filter(r => r.name == selectedRepo)[0]; | ||
| getRepoData(repo, repoInfo, contribs); | ||
| }); | ||
|
|
||
| let firstRepo = alphabeticalSorting[0] | ||
| getRepoData(firstRepo, repoInfo, contribs); | ||
| } | ||
| catch(err) { | ||
| 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) }); | ||
| } | ||
| }); | ||
| createAndAppend('div', root, { text: err.message, class: 'alert-error' }); | ||
| } | ||
| } | ||
|
|
||
| async function getRepoData(repo, repoInfo, contribs) { | ||
|
|
||
| // console.log(repo); | ||
| repoInfo.innerHTML = ''; | ||
| contribs.innerHTML = ''; | ||
|
|
||
| const addInfo = (label, value) => { | ||
| const container = createAndAppend('div', repoInfo); | ||
| 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: ', new Date(repo.updated_at)); | ||
|
|
||
| const contribsUrl = repo.contributors_url; | ||
| try { | ||
| const contribData = await fetchJSON(contribsUrl); | ||
| contribData.forEach(contributor => { | ||
| // createAndAppend('p', contribs, { text: 'hej'}); | ||
| createAndAppend('img', contribs, { src: contributor.avatar_url, height: 40, class: 'picture' }); | ||
| createAndAppend('span', contribs, { text: contributor.login, class: 'contributorName' }); | ||
| createAndAppend('span', contribs, { text: contributor.contributions, class: 'numberContributions'}); | ||
| createAndAppend('div', contribs, { text: '\n'}); | ||
| }); | ||
| } | ||
| catch(err) { | ||
| const root = document.getElementById('root'); | ||
| createAndAppend('div', root, { 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.
I can't pass you on this part. You need to use the classes
ContributorandRepositorywith the appropriate render methods, this is important to understand before the react module. Let me know if you need any assistance with this!Uh oh!
There was an error while loading. Please reload this page.
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.
Alright :) I have watched a bunch of tutorials on this and hope to finally to be able to solve it especially since we got even more additional guidance on Slack. It takes a while to find out how these all .js files are connected, but once I understand it, I hope to be able to use it over and over again in the future projects. My main issue is being able to put apart and use small parts of the huge functions without damaging the functionality.