Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd30c3a

Browse files
authored
Merge pull request HackYourFuture#289 from HackYourFuture/prep-class22
Prep for class 22
2 parents 9bd7d0d + 0579f32 commit bd30c3a

27 files changed

+5867
-65
lines changed

.eslintrc.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
"extends": ["airbnb", "prettier"],
33
"plugins": ["prettier"],
44
"env": {
5-
"browser": true
5+
"browser": true,
6+
"jest": true
7+
},
8+
"globals": {
9+
"page": true,
10+
"browser": true,
11+
"context": true,
12+
"jestPuppeteer": true
613
},
714
"rules": {
815
"prettier/prettier": ["error"],

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ typings/
5959

6060
.netlify
6161
dist/
62+
iPhoneX.png

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"editor.detectIndentation": false,
66
"editor.tabSize": 2,
77
"cSpell.words": [
8+
"networkidle",
89
"tabindex"
910
]
1011
}

Week1/MAKEME.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ Figure 1 below shows an example of what your application could look like. Note t
3232

3333
<small>Figure 1. Example User Interface using [Material Design](https://material.io/guidelines/) principles.</small>
3434

35-
A live version of this application can be found here: http://hyf-github.netlify.com/
36-
3735
### 1.2 The GitHub API
3836

3937
#### 1.2.1 Get a list of HYF repositories
@@ -105,21 +103,12 @@ You will be working on the same application during the next three weeks. For eac
105103

106104
The files that make up the application are located in the `homework` folder. It contains the following files:
107105

108-
| Filename | Description |
109-
| -------------------- | --------------------------------- |
110-
| ~~`App.js`~~ | Not used in week 1 and 2. |
111-
| ~~`Contributor.js`~~ | Not used in week 1 and 2. |
112-
| `hyf.png` | Contains the HackYourFuture logo. |
113-
| `index.html` | The application's HTML file. |
114-
| ~~`index2.html`~~ | Not used in week 1 and 2. |
115-
| `index.js` | A starter JavaScript file. |
116-
| ~~`Repository.js`~~ | Not used in week 1 and 2. |
117-
| `style.css` | A starter CSS file. |
118-
| ~~`Util.js`~~ | Not used in week 1 and 2. |
119-
120-
In week 1, you should only modify `index.js` and `style.css`.
121-
122-
_**Do not modify any other files at this time!**_
106+
| Filename | Description |
107+
| ------------ | --------------------------------- |
108+
| `hyf.png` | Contains the HackYourFuture logo. |
109+
| `index.html` | The application's HTML file. |
110+
| `index.js` | A starter JavaScript file. |
111+
| `style.css` | A starter CSS file. |
123112

124113
Although you should only modify files in the `homework` folder, we recommend that you always open the `JavaScript3` folder rather than directly opening the `homework` folder in VSCode. The `JavaScript3` folder contains the actual git repository and the configuration files required by the installed tools.
125114

@@ -175,7 +164,7 @@ It should include the following components:
175164
3. When the user changes the selection, the information in the web page should be refreshed for the newly selected repository.
176165
4. You should be able to click on the repository name of the selected repository to open a new browser tab with the GitHub page for that repository.
177166
5. You should be able to click on a contributor to open a new browser tab with the GitHub page for that contributor.
178-
6. You should render network errors to the DOM (see Figure 2 below for an example). Do not use `console.log` as regular users will not see the console output.
167+
6. You should render network errors to the DOM (see Figure 2 below for an example). Do not use `console.log` as regular users will not see the console output. Use the predefined `alert-error` class from `style.css` to style your error.
179168
7. Your UI should be responsive. Try it with Chrome Developer Tools in the browser, using a mobile phone format and a tablet format, portrait and landscape. If necessary, you can also do this work in week 2.
180169

181170
![Error rendering](./assets/hyf-github-error.png)

Week2/MAKEME.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The homework for week 2 will build on the work you did in week 1. You will creat
4343
You will continue to work on the files `index.js` and (possibly) `style.css`.
4444

4545
- Complete your GitHub app code from the previous week, if needed, to meet the requirements from that week's assignment.
46-
- Replace all asynchronous callbacks (e.g. as used with XMLHttpRequest) by ES6 promises.
46+
- Replace all asynchronous callbacks (e.g. as used with `XMLHttpRequest`) by ES6 promises.
4747
- Beautify your app's styling.
4848
- If not yet completed in week 1, make your app responsive (use CSS media queries and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/)).
4949

Week3/MAKEME.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,42 @@ The homework for week 3 will build on the work you did in week 2. You will creat
3737

3838
This week you will work with all JavaScript files in the `src` folder. The assignment consists of two parts:
3939

40-
1. Refactor all `.then()` and `.catch()` methods with `async`/`await` and `try...catch`.
41-
2. Make your app ARIA-compliant (see below).
42-
3. Refactor your application to use ES6 classes.
40+
1. Replace `XMLHttpRequest` with the `fetch` API.
41+
2. Refactor all `.then()` and `.catch()` methods with `async`/`await` and `try...catch`.
42+
3. Make your app ARIA-compliant (see below).
43+
4. Refactor your application to use ES6 classes.
44+
45+
#### 2.2.1 Replace XMLHttpRequest with fetch
46+
47+
Replace `XMLHttpRequest` in the `fetchJSON` function with `fetch`. Because `fetch` returns a promise out of the box there is no need create a promise yourself with `new Promise(...)`.
4348

44-
#### 2.2.1 async/await
49+
> `fetch` does not throw an error for HTTP errors. Review the documentation for [`response.ok`](https://developer.mozilla.org/en-US/docs/Web/API/Response/ok) for a clue how detect HTTP errors.
50+
51+
#### 2.2.2 async/await
4552

4653
**Instructions:**
4754

4855
1. Refactor all `.then()` and `.catch()` methods with `async`/`await` and `try...catch`.
4956

5057
2. Make sure that your error handling code still works. See the week2 MAKEME on how to force an error response from GitHub.
5158

52-
#### 2.2.2 ES6 Classes
59+
#### 2.2.3 ES6 Classes
5360

5461
**_Deadline Saturday_**
5562

5663
This final assignment requires you to go the extra mile and master Object Oriented Programming and ES6 classes.
5764

65+
> The files to be modified are in the **homework-classes** folder.
66+
5867
In this assignment you need to redistribute and adapt the code from `index.js` to the files `App.js`, `Repository.js` and `Contributor.js`. You do not need to modify `Util.js`.
5968

60-
| File | Description |
61-
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
62-
| `index2.html` | You should load this HTML file in your browser instead of `index.html` to work with the classes version of your homework. It loads the following JavaScript files through `<script>` tags in the `<body>` element: |
63-
| `App.js` | The `App` class contains the start-up code and manages the overall orchestration of the app. |
64-
| `Repository.js` | The `Repository` class holds code and data for a single repository. |
65-
| `Contributor.js` | The `Contributor` class holds code and data for a single contributor. |
66-
| `Util.js` | The `Util` class contains static helper methods for use in the other classes. |
69+
| File | Description |
70+
| ---------------- | -------------------------------------------------------------------------------------------- |
71+
| `index.html` | The application's HTML file. |
72+
| `App.js` | The `App` class contains the start-up code and manages the overall orchestration of the app. |
73+
| `Repository.js` | The `Repository` class holds code and data for a single repository. |
74+
| `Contributor.js` | The `Contributor` class holds code and data for a single contributor. |
75+
| `Util.js` | The `Util` class contains static helper methods for use in the other classes. |
6776

6877
The `App.js`, `Repository.js` and `Contributor.js` files each contain skeleton code that you can use to migrate portions of your code from `index.js` to.
6978

@@ -72,17 +81,17 @@ _Read:_
7281
- HYF fundamental: [ES6 Classes](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/oop_classes.md#es6-classes)
7382
- More on ES6 classes: [ES6 Classes in Depth](https://ponyfoo.com/articles/es6-classes-in-depth)
7483

75-
#### 2.2.3 ARIA-compliance (BONUS)
84+
#### 2.2.4 ARIA-compliance (BONUS)
7685

7786
Please review the material from the HTML/CSS module: [Get familiar with Accessible Rich Internet Applications (ARIA)](https://github.com/HackYourFuture/HTML-CSS/tree/master/Week1#get-familiar-with-accessible-rich-internet-applications-aria).
7887

7988
For the GitHub application ARIA-compliance means that the Contributors list should either be a native HTML list (i.e. using `ul` and `li` elements) or otherwise marked with an appropriate ARIA **role**. Furthermore, a user should be able to navigate through all interactive elements using the keyboard (e.g., using the **Tab** key). Pressing **Enter** on such an element should be equivalent to clicking the mouse.
8089

81-
#### 2.2.4 Handing in your homework
90+
#### 2.2.5 Handing in your homework
8291

8392
If necessary, review the instructions how to [Hand in homework](https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/homework_pr.md) using GitHub pull request.
8493

85-
To test whether your code will be accepted when you submit your homework as a pull request you need to ensure that it does not contain ESLinr errors. Open a terminal window in VSCode and type the following command:
94+
To test whether your code will be accepted when you submit your homework as a pull request you need to ensure that it does not contain ESLint errors. Open a terminal window in VSCode and type the following command:
8695

8796
```
8897
npm test

homework/App.js renamed to homework-classes/App.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
class App {
66
constructor(url) {
7+
this.mainContainer = null;
78
this.initialize(url);
89
}
910

@@ -17,8 +18,8 @@ class App {
1718
// 2. Make an initial XMLHttpRequest using Util.fetchJSON() to populate your <select> element
1819

1920
const root = document.getElementById('root');
20-
21-
Util.createAndAppend('h1', root, { text: 'It works!' }); // TODO: replace with your own code
21+
const header = Util.createAndAppend('header', root, { class: 'header' });
22+
this.mainContainer = Util.createAndAppend('div', root, { id: 'container' });
2223

2324
try {
2425
const repos = await Util.fetchJSON(url);
@@ -33,31 +34,28 @@ class App {
3334
* Removes all child elements from a container element
3435
* @param {*} container Container element to clear
3536
*/
36-
static clearContainer(container) {
37-
while (container.firstChild) {
38-
container.removeChild(container.firstChild);
37+
clearContainer() {
38+
while (this.mainContainer.firstChild) {
39+
this.mainContainer.removeChild(this.mainContainer.firstChild);
3940
}
4041
}
4142

4243
/**
4344
* Fetch contributor information for the selected repository and render the
4445
* repo and its contributors as HTML elements in the DOM.
45-
* @param {number} index The array index of the repository.
46+
* @param {object} repo The selected repository object
4647
*/
47-
async fetchContributorsAndRender(index) {
48+
async selectRepository(repo) {
4849
try {
49-
const repo = this.repos[index];
50+
this.clearContainer();
5051
const contributors = await repo.fetchContributors();
5152

52-
const container = document.getElementById('container');
53-
App.clearContainer(container);
54-
55-
const leftDiv = Util.createAndAppend('div', container);
56-
const rightDiv = Util.createAndAppend('div', container);
53+
const repoContainer = Util.createAndAppend('div', this.mainContainer);
54+
const contributorContainer = Util.createAndAppend('div', this.mainContainer);
5755

58-
const contributorList = Util.createAndAppend('ul', rightDiv);
56+
const contributorList = Util.createAndAppend('ul', contributorContainer);
5957

60-
repo.render(leftDiv);
58+
repo.render(repoContainer);
6159

6260
contributors
6361
.map(contributor => new Contributor(contributor))
@@ -68,14 +66,13 @@ class App {
6866
}
6967

7068
/**
71-
* Render an error to the DOM.
69+
* Render an error to the page.
7270
* @param {Error} error An Error object describing the error.
7371
*/
7472
renderError(error) {
75-
console.log(error); // TODO: replace with your own code
73+
console.error(error); // TODO: replace with your own code
7674
}
7775
}
7876

7977
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
80-
8178
window.onload = () => new App(HYF_REPOS_URL);
File renamed without changes.
File renamed without changes.

homework/Util.js renamed to homework-classes/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Util {
2222
xhr.open('GET', url);
2323
xhr.responseType = 'json';
2424
xhr.onload = () => {
25-
if (xhr.status < 400) {
25+
if (xhr.status >= 200 && xhr.status <= 299) {
2626
resolve(xhr.response);
2727
} else {
2828
reject(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));

homework-classes/hyf.png

6.81 KB
Loading
File renamed without changes.

homework-classes/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.alert-error {
2+
color: red;
3+
}

homework/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xhr.open('GET', url);
77
xhr.responseType = 'json';
88
xhr.onload = () => {
9-
if (xhr.status < 400) {
9+
if (xhr.status >= 200 && xhr.status <= 299) {
1010
cb(null, xhr.response);
1111
} else {
1212
cb(new Error(`Network error: ${xhr.status} - ${xhr.statusText}`));
@@ -31,17 +31,16 @@
3131
}
3232

3333
function main(url) {
34-
fetchJSON(url, (err, data) => {
34+
fetchJSON(url, (err, repositories) => {
3535
const root = document.getElementById('root');
3636
if (err) {
3737
createAndAppend('div', root, { text: err.message, class: 'alert-error' });
38-
} else {
39-
createAndAppend('pre', root, { text: JSON.stringify(data, null, 2) });
38+
return;
4039
}
40+
createAndAppend('pre', root, { text: JSON.stringify(repositories, null, 2) });
4141
});
4242
}
4343

4444
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
45-
4645
window.onload = () => main(HYF_REPOS_URL);
4746
}

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/jest-puppeteer.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
server: {
3+
command: 'serve ../homework',
4+
port: 5000,
5+
},
6+
launch: {
7+
headless: true,
8+
},
9+
// could use for example: 1920 x 1080
10+
defaultViewPort: {
11+
width: 800,
12+
height: 600,
13+
},
14+
};

0 commit comments

Comments
 (0)