Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 28 additions & 29 deletions homework-classes/App.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,61 @@
'use strict';

/* global Util, Repository, Contributor */

class App {
constructor(url) {
this.mainContainer = null;
this.initialize(url);
}

/**
* Initialization
* @param {string} url The GitHub URL for obtaining the organization's repositories.
*/
async initialize(url) {
// Add code here to initialize your app
// 1. Create the fixed HTML elements of your page
// 2. Make an initial XMLHttpRequest using Util.fetchJSON() to populate your <select> element

const root = document.getElementById('root');
const header = Util.createAndAppend('header', root, { class: 'header' });
this.mainContainer = Util.createAndAppend('div', root, { id: 'container' });
Util.createAndAppend('h1', root, { text: 'REPOSITORIES' });
Util.createAndAppend('select', root, { id: 'dropdown-select' });
Util.createAndAppend('div', root, { id: 'details' });
Util.createAndAppend('div', root, { id: 'contributors' });

try {
const repos = await Util.fetchJSON(url);
this.repos = repos.map(repo => new Repository(repo));
// TODO: add your own code here
this.repos.forEach(repoDataObj => {
repoDataObj.render(document.getElementById('dropdown-select'));
});
} catch (error) {
this.renderError(error);
}
document.getElementById('dropdown-select').addEventListener('change', event => {
const selectedRepo = event.target.value;
const selectedData = this.repos.filter(
repoData => repoData.repository.name === selectedRepo,
)[0];
const index = this.repos.indexOf(selectedData);
this.fetchContributorsAndRender(index);
});
}

/**
* Removes all child elements from a container element
* @param {*} container Container element to clear
*/
clearContainer() {
while (this.mainContainer.firstChild) {
this.mainContainer.removeChild(this.mainContainer.firstChild);
static clearContainer(container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
}

/**
* Fetch contributor information for the selected repository and render the
* repo and its contributors as HTML elements in the DOM.
* @param {object} repo The selected repository object
* @param {number} index The array index of the repository.
*/
async selectRepository(repo) {
async fetchContributorsAndRender(index) {
try {
this.clearContainer();
const repo = this.repos[index];
const contributors = await repo.fetchContributors();
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem is here! Cant seem to go through this part


const repoContainer = Util.createAndAppend('div', this.mainContainer);
const contributorContainer = Util.createAndAppend('div', this.mainContainer);

const contributorList = Util.createAndAppend('ul', contributorContainer);

repo.render(repoContainer);

const container = document.getElementById('contributors');
App.clearContainer(container);
const leftDiv = Util.createAndAppend('div', container);
const rightDiv = Util.createAndAppend('div', container);
const contributorList = Util.createAndAppend('div', rightDiv);
repo.render(leftDiv);
contributors
.map(contributor => new Contributor(contributor))
.forEach(contributor => contributor.render(contributorList));
Expand All @@ -70,7 +69,7 @@ class App {
* @param {Error} error An Error object describing the error.
*/
renderError(error) {
console.error(error); // TODO: replace with your own code
console.error(error);
}
}

Expand Down
19 changes: 13 additions & 6 deletions homework-classes/Contributor.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
'use strict';

/* global Util */

// eslint-disable-next-line no-unused-vars
class Contributor {
constructor(contributor) {
this.contributor = contributor;
}

/**
* Render the contributor info to the DOM.
* @param {HTMLElement} container The container element in which to render the contributor.
*/
render(container) {
// TODO: replace the next line with your code.
Util.createAndAppend('pre', container, { text: JSON.stringify(this.contributor, null, 2) });
const contributorsDiv = Util.createAndAppend('div', root, { id: 'contributorDiv' });
Util.createAndAppend('img', container, {
src: this.contributor.avatar_url,
class: 'contributors-detail',
});
Util.createAndAppend('p', container, {
text: this.contributor.login,
class: 'contributors-detail',
});
Util.createAndAppend('p', container, {
text: this.contributor.contributions,
class: 'contributors-detail',
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to use the container :)

  render(container) {
    Util.createAndAppend('img', container, {
      src: this.contributor.avatar_url,
      class: 'contributors-detail',
    });
    Util.createAndAppend('p', container, {
      text: this.contributor.login,
      class: 'contributors-detail',
    });
    Util.createAndAppend('p', container, {
      text: this.contributor.contributions,
      class: 'contributors-detail',
    });
  }
}

}
}
Binary file added homework-classes/OlJVkf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 5 additions & 12 deletions homework-classes/Repository.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
'use strict';

/* global Util */

// eslint-disable-next-line no-unused-vars
class Repository {
constructor(repository) {
this.repository = repository;
}

/**
* Render the repository info to the DOM.
* @param {HTMLElement} container The container element in which to render the repository.
*/
render(container) {
// TODO: replace the next line with your code.
Util.createAndAppend('pre', container, { text: JSON.stringify(this.repository, null, 2) });
Util.createAndAppend('option', container, { text: this.name() });
}

/**
* Returns an array of contributors as a promise
*/
fetchContributors() {
App.clearContainer(details);
Util.createAndAppend('div', details, { text: `Description: ${this.repository.description}` });
Util.createAndAppend('div', details, { text: `Forks: ${this.repository.forks}` });
Util.createAndAppend('div', details, { text: `Last Update: ${this.repository.updated_at}` });
return Util.fetchJSON(this.repository.contributors_url);
}

/**
* Returns the name of the repository
*/
name() {
return this.repository.name;
}
Expand Down
47 changes: 23 additions & 24 deletions homework-classes/index.html
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>
55 changes: 54 additions & 1 deletion homework-classes/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
.alert-error {
color: red;
color: red;
}

body {
background-color: darkslategrey
}

h1 {
color: rgb(180, 244, 255);
font-family: Helvetica;
text-transform: uppercase;
text-align: center;
font-size: 3em;
}

#dropdown-select {
width: 25em;
height: 3em;
border-radius: 5px;
}

select {
width: 20em;
font-family: helvetica;
text-transform: uppercase;
position: relative;
color: rgb(13, 96, 110);
padding: 10px;
}

#root {
display: flex;
flex-direction: column;
flex-wrap: wrap;
}

img {
width: 50px;
}

#contributors {
display: flex;
flex-direction: row;
align-content: space-around;
margin-left: 35%;
flex-wrap: wrap;
list-style-type: none;
}

.contributors-detail {
color: white;
flex-wrap: wrap;
margin: 20px;
flex-grow: 1;
}
Binary file added homework/OlJVkf.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added homework/Simple-Background-Images-53.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 16 additions & 13 deletions homework/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
<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">
<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="./index.js"></script>
<h1>Repositories</h1>
<div id="root"></div>


<script src="./index1.js"></script>
</body>

</html>
40 changes: 39 additions & 1 deletion homework/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,51 @@
}

function main(url) {
fetchJSON(url, (err, repositories) => {
// create the layout with a div
// 2 - get repo from github
// add listener on select
createLayout();
getRepoData();
/* fetchJSON(url, (err, repositories) => {
const root = document.getElementById('root');
if (err) {
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
return;
}
createAndAppend('pre', root, { text: JSON.stringify(repositories, null, 2) });
}); */
}

function createLayout() {
const root = document.getElementById('root');
createAndAppend('select', root, { id: 'repo-select' });
createAndAppend('div', root, { id: 'repo-details' });
createAndAppend('div', root, { id: 'contributors' });
}

function getRepoData() {
const REPO_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
fetchJSON(REPO_URL, (err, listOfRepo) => {
listOfRepo.forEach(repoDataObj => {
createAndAppend(
'option',
document.getElementById('repo-select'),
{ id: 'repo-select' },
{
text: listOfRepo.name,
},
);
});

listenerOnSelect(listofRepo);
});
}

function listenerOnSelect(listOfRepo) {
document.getElementById('repo-select').addEventListener('change', event => {
const selectedRepo = event.target.value;

const selectedData = listOfRepo.filter(repoData => repoData.name === selectedRepo);
});
}

Expand Down
Loading