-
Notifications
You must be signed in to change notification settings - Fork 12
Week1 #7
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
Week1 #7
Changes from all commits
b31ceb0
3c9d14c
d042bfd
939b992
fa369fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,14 +33,68 @@ | |
| 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 header = createAndAppend('header', root, { class: 'header' }); | ||
| const h1 = createAndAppend('h1', header, { text: 'FooCoding Repos', class: 'h1' }); | ||
|
|
||
| const select = createAndAppend('select', root, { class: 'select' }); | ||
| createAndAppend('option', select, { text: 'Choose your favorite repo below:' }); | ||
|
Collaborator
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. One of the requirements is that information for the first repo is shown when the page loads, can you have a look at that?
Author
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. Trying... |
||
|
|
||
| data.forEach(repo => { | ||
| const name = repo.name; | ||
| data.sort((a, b) => a.name.localeCompare(b.name)); | ||
| createAndAppend('option', select, { text: name }); | ||
| console.log(name); | ||
| }); | ||
|
|
||
| const repoInfo = createAndAppend('div', root, { class: 'left-div' }); | ||
| const contribs = createAndAppend('div', root, { class: 'right-div' }); | ||
|
|
||
| select.addEventListener('change', evt => { | ||
| const selectedRepo = evt.target.value; | ||
| const repo = data.filter(r => r.name == selectedRepo)[0]; | ||
| console.log(repo.name); | ||
| repoInfo.innerHTML = repo.name; | ||
| contribs.innerHTML = repo.name; | ||
|
|
||
| const addInfo = (label, value) => { | ||
| const container = createAndAppend('div', repoInfo); | ||
| createAndAppend('span', container, { text: label }); | ||
| createAndAppend('span', container, { text: value }); | ||
| }; | ||
|
|
||
| addInfo('Name: ', repo.name); | ||
| addInfo('Description: ', repo.description); | ||
| addInfo('Number of forks: ', repo.forks); | ||
| addInfo('Updated: ', repo.updated_at); | ||
|
|
||
| const contribsUrl = repo.contributors_url; | ||
| fetchJSON(contribsUrl, (err, contribData) => { | ||
| if (err) { | ||
| createAndAppend('div', root, { text: err.message, class: 'alert-error' }); | ||
| } else { | ||
| } | ||
| contribData.forEach(contributor => { | ||
| createAndAppend('div', contribs, { text: contributor.login }); | ||
| createAndAppend('a', contribs, { | ||
| text: contributor.login, | ||
| href: contributor.html_url, | ||
| }); | ||
| createAndAppend('img', contribs, { | ||
|
Collaborator
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. Nice! |
||
| src: contributor.avatar_url, | ||
| height: 150, | ||
| width: 150, | ||
| id: 'img', | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| const REPOS_URL = 'https://api.github.com/orgs/foocoding/repos?per_page=100'; | ||
|
|
||
| window.onload = () => main(REPOS_URL); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,64 @@ | ||
| #root { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| justify-content: center; | ||
| } | ||
| @media screen and (max-width: 768px) { | ||
| .h1.h1 { | ||
| width: 100%; | ||
| } | ||
| .right-div { | ||
| width: 100%; | ||
| } | ||
| .left-div { | ||
| width: 100%; | ||
| } | ||
| } | ||
| .alert-error { | ||
| color: red; | ||
| } | ||
| color: red; | ||
| } | ||
| .h1 { | ||
| text-align: center; | ||
| } | ||
| .container { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: flex-start; | ||
| margin: 10px; | ||
| } | ||
|
|
||
| .right-div { | ||
| color: green; | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| flex-wrap: wrap; | ||
| margin: 10px; | ||
| flex-grow: 1; | ||
| height: 200px; | ||
| width: 200px; | ||
| } | ||
|
|
||
| .left-div { | ||
| color: brown; | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| flex-direction: column; | ||
| flex-grow: 1; | ||
|
|
||
| align-items: right; | ||
| margin: 10px; | ||
| } | ||
| header { | ||
| width: 800px; | ||
| height: 70px; | ||
| background-color: purple; | ||
| text-emphasis-color: white; | ||
| text-align: left; | ||
| } | ||
| .info-container { | ||
| text-align: left; | ||
| width: 40; | ||
| height: 30; | ||
| } |
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.
Nice usage of
createAndAppend!