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

Skip to content

Commit 99d49ad

Browse files
committed
preparation for homework as PR
1 parent 8b3184c commit 99d49ad

File tree

19 files changed

+632
-179
lines changed

19 files changed

+632
-179
lines changed

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
.netlify
61+
dist/

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
2+
"editor.formatOnSave": true,
3+
"editor.formatOnType": true,
4+
"editor.formatOnPaste": true,
5+
"editor.detectIndentation": false,
6+
"editor.tabSize": 2,
27
"cSpell.words": [
3-
"orgs",
4-
"repos"
8+
"tabindex"
59
]
610
}

LICENSE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This work is licensed under the Creative Commons Attribution 4.0 International License.
2+
To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
3+
or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Here you can find course content and homework for the JavaScript3 modules
88
|----|-----|----|--------|
99
|1.|• Structure for a basic SPA (Single Page Application) <br>• [XMLHttpRequests](../../../fundamentals/blob/master/fundamentals/XMLHttpRequest.md) <br>• API calls|[Reading Week 1](/Week1/README.md)|[Homework Week 1](/Week1/MAKEME.md)|
1010
|2.|[Event Loop (order of execution)](../../../fundamentals/blob/master/fundamentals/event_loop.md)<br>• [Promises](../../../fundamentals/blob/master/fundamentals/promises.md)|[Reading Week 2](/Week2/README.md)|[Homework Week 2](/Week2/MAKEME.md)|
11-
|3.|[try...catch](../../../fundamentals/blob/master/fundamentals/try_catch.md)<br>• [async/await](../../../fundamentals/blob/master/fundamentals/async_await.md)<br>• [Object Oriented Programming and ES6 Classes](../../../fundamentals/blob/master/fundamentals/oop_classes.md)<br>• [The `this` keyword](../../../fundamentals/blob/master/fundamentals/this.md)<br>• call, apply, bind |[Reading Week 3](/Week3/README.md)|[Homework Week 3](/Week3/MAKEME.md)|
11+
|3.|[try...catch](../../../fundamentals/blob/master/fundamentals/try_catch.md)<br>• [async/await](../../../fundamentals/blob/master/fundamentals/async_await.md)<br>• [The `this` keyword](../../../fundamentals/blob/master/fundamentals/this.md)<br>• call, apply, bind<BR>• [Object Oriented Programming and ES6 Classes](../../../fundamentals/blob/master/fundamentals/oop_classes.md)|[Reading Week 3](/Week3/README.md)|[Homework Week 3](/Week3/MAKEME.md)|
1212

1313
__Kind note:__
1414

@@ -18,3 +18,5 @@ We expect you to __always__ come prepared to the class on Sunday.
1818
A good understanding of all the above mentioned topics. Want to check your Knowledge? Go through the [JavaScript Fundamentals README](../../../fundamentals/blob/master/README.md) and research/ ask for help (Slack!) with the concepts that are not entirely clear.
1919

2020
*The HackYourFuture curriculum is subject to CC BY copyright. This means you can freely use our materials, but just make sure to give us credit for it :)*
21+
22+
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.

Week1/MAKEME.md

Lines changed: 157 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,212 @@ Topics discussed this week:
77
• API calls
88
```
99

10-
1110
>[Here](/Week3/README.md) you find the readings you have to complete before the ninth lecture.
1211
1312
## Step 1: Feedback
1413

15-
_Deadline Monday_
16-
17-
Please provide feedback in an issue.
18-
19-
_Deadline Monday_
14+
**_Deadline Monday_**
2015

21-
## Step 2: FINISH ALL YOUR JAVASCRIPT HOMEWORK
16+
Please provide feedback on last week's homework from a fellow student as a GitHub issue.
2217

23-
_Deadline Saturday_
18+
## Step 2: Single Page Application :sweat_drops:
2419

25-
:point_up:
20+
**_Deadline Thursday_**
2621

27-
## Step 3: SPA :sweat_drops:
22+
_This homework is more extensive and challenging than previous homework! Please read the instructions below carefully and follow them precisely. Start this homework as soon as you can and allow time for discussion and questions (slack!)._
2823

29-
_Deadline Saturday_
24+
### 2.1 Introduction
3025

31-
You are going to write a SPA (Single Page Application) that uses the [GitHub API](https://developer.github.com/guides/getting-started/).
26+
You are going to write a _Single Page Application_ (SPA) that uses the [GitHub API](https://developer.github.com/guides/getting-started/).
3227

33-
This application should display information about the available [HYF repositories](https://github.com/hackyourfuture):
28+
This application should display information about the available [HYF GitHub repositories](https://github.com/hackyourfuture):
3429

3530
- You should be able to select a repository from a list of available repositories.
3631
- The application should display high-level information about the selected repository and show a list of its contributors.
32+
- When clicking on the name of the selected repository the GitHub page for the corresponding repository should be opened in a new browser tab.
33+
- When clicking on a contributor, the GitHub page for the contributor should be opened in a new browser tab.
3734

3835
Figure 1 below shows an example of what your application could look like. Note that this is just an example. If you find it boring or unimaginative, please improve on it! On the other hand, a simpler version is OK too, so long as you implement the expected functionality.
3936

4037
![UI Example](./assets/hyf-github.png)
4138

42-
Figure 1. Example User Interface using [Material Design](https://material.io/guidelines/) principles.
39+
<small>Figure 1. Example User Interface using [Material Design](https://material.io/guidelines/) principles.</small>
4340

44-
### Instructions
41+
A live version of this application can be found here: http://hyf-github.netlify.com/
4542

46-
1. Create this application in the `week1` folder of your `hyf-javascript1` repo. Your application should at minimum consist of the files `index.html`, `style.css` and `app.js`.
47-
2. Your `index.html` file should load the `style.css` and `app.js` files, using the appropriate HTML tags.
48-
3. The `body` of your `index.html` should contain a single `div` element like this: `<div id="root"></div>`.
49-
4. All other HTML elements should be generated programmatically by your `app.js` file and ultimately be hanging off the root `div` element.
50-
5. Implement the repository selection list by means of an HTML [\<select\>](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select) element.
43+
### 2.2 The GitHub API
5144

52-
You will need to use XMLHttpRequests against the GitHub API to get the relevant information. The GitHub API documentation is very extensive. An overview is given [here](https://developer.github.com/v3/) but we will point you to the relevant sections in the documentation needed for this assignment.
45+
#### 2.2.1 Get a list of HYF repositories
5346

54-
#### List of repositories
55-
56-
You can obtain a list of HYF repositories through this API endpoint ([What is an API Endpoint?](https://teamtreehouse.com/community/what-is-an-api-endpoint)):
47+
You can fetch a list of HYF repositories through this API endpoint ([What is an API Endpoint?](https://teamtreehouse.com/community/what-is-an-api-endpoint)):
5748

5849
```
5950
https://api.github.com/orgs/HackYourFuture/repos?per_page=100
6051
```
6152

62-
GitHub API documentation: [List organization repositories](https://developer.github.com/v3/repos/#list-organization-repositories)
53+
If you open this URL in the browser (_try it!_) you will receive JSON data about the available HYF repositories. This is the data that you will need to work with in this assignment.
54+
55+
<small>Note the query string `?per_page=100` in the above URL. If you don't specify this query string you will only get the first 30 repositories (the default `per_page` is 30). HackYourFuture has more than 30 repositories but less than 100.</small>
56+
57+
The returned JSON data contains some basic information about each repository, such as `name`, `full_name`, `description` etc. There are also many properties that contain URLs to obtain detail information about certain aspects of the repository.
58+
59+
#### 2.2.2 Get contributor information for a repository
60+
61+
The JSON data that is returned from the initial request to get repository information includes a property named `contributors_url`. Use the value of this property to fetch a list of contributors.
62+
63+
#### 2.2.3 GitHub API documentation
64+
65+
You can find detailed information about the GitHub API by means of the link listed below. However, the documentation is very extensive and not easy to digest. For this homework it is not necessary to study the GitHub API documentation. We provide the link here for completeness.
66+
67+
> GitHub API documentation: https://developer.github.com/v3/
68+
69+
### 2.3 Preparation
70+
71+
You will be working on this same application during the next three weeks. For each week you will need to create a new Git branch, as listed in the Table 1 below.
72+
73+
| Week | Branch | Assignment |
74+
|:----:|--------|------------|
75+
| 1 | `week1` | Create a basic application using callbacks to handle network requests. |
76+
| 2 | `week2` | 1. Refactor the callbacks to promises.<br>2. Make the UI responsive.|
77+
| 3 | `week3` | 1. Refactor the application to use ES6 Classes and async/await.<br>2. Make the app ARIA-compliant. |
78+
79+
<small>Table 1. Homework schedule</small>
80+
81+
**Instructions**
82+
83+
1. Fork the JavaScript3 repository (_this repository_) to your own GitHub account.
84+
2. Clone the fork to your laptop.
85+
3. Open the `homework` folder inside the cloned repository in VSCode.
86+
4. Create a new branch for the week 1 homework with the following command:
87+
88+
```
89+
git checkout -b week1
90+
```
91+
92+
### 2.4 Code Overview
93+
94+
The files that make up the application are located in the `src` folder. It contains the following files:
95+
96+
| Filename | Description |
97+
|------------------|-------------|
98+
| ~~`App.js`~~ | Not used in week 1 and 2. |
99+
| ~~`Contributor.js`~~ | Not used in week 1 and 2. |
100+
| `hyf.png` | Contains the HackYourFuture logo. |
101+
| `index.html` | The application's HTML file. |
102+
| `index.js` | A starter JavaScript file. |
103+
| ~~`Repository.js`~~ | Not used in week 1 and 2. |
104+
| `style.css` | A starter CSS file. |
105+
| ~~`Util.js`~~ | Not used in week 1 and 2. |
106+
107+
In week 1, you should only modify `index.js` and `style.css`.
108+
109+
_**Do not modify any other files at this time!**_
63110
64-
Note the query string `?per_page=100`. If you don't specify this query string you will only get the first 30 repositories (the default `per_page` is 30 and HYF has more than 30 - but less than 100).
111+
#### 2.4.1 A first examination
65112
66-
#### Get contributor information
113+
1. Open `index.html` and examine its contents (but don't modify anything). Notice that the HTML `body` looks like this:
67114
68-
The response object that is returned by GitHub from the request to get repository information includes a property with the `contributors_url`. Use the value of this property to make a new request to GitHub to obtain a list of contributors.
115+
```html
116+
<body>
117+
<div id="root"></div>
118+
<script src="./index.js"></script>
119+
</body>
120+
```
69121
70-
In the lecture we developed some utility functions to simplify making XMLHttpRequests (function `fetchJSON()`) and creating and manipulating HTML elements (function `createAndAppend()`). You are free to copy and use these utility functions, but if you do we expect that you can explain how they work.
122+
The `body` tag contains a single `div` to which you will need to dynamically append HTML elements through your JavaScript code in `index.js`.
71123
72-
### Refinements
124+
2. Open `index.js`. This file contains a starter set of code for you to expand. It contains the following three functions:
73125
74-
- Make all the repositories link to their own page in GitHub. Use the value of the key: `name` to make this work (hint: GitHub urls always look like this https://api.github.com/repos/HackYourFuture/[repositoryName] where [repositoryName] would be replaced by the actual `name` of the repository, for example `CommandLine`).
75-
- Make sure the link opens in a new tab.
126+
| Function | Description |
127+
|----------|-------------|
128+
| `fetchJSON` | Uses `XMLHttpRequest` to fetch JSON data from an API end point. This function uses an asynchronous callback. |
129+
| `createAndAppend` | A utility function for easily creating and appending HTML elements. |
130+
| `main` | Contains the start-up code for the application. |
131+
132+
`index.js` also contains a constant with the URL for the HYF repositories as listed in section 2.2.1:
76133
77-
### Important
134+
```js
135+
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
136+
```
78137
79-
- Do not duplicate code! This is especially important for making requests since we are making multiple ones with different urls and we want to do different actions based on the call we are making. Here are some handles to get you started:
80-
- Write a function called `fetchJSON` (or copy from the lecture code) which accepts (at least) the following parameters: `url` and `callback`.
81-
- Make sure your `callback` is called when the request errors or when it sends a response (look at the documentation)
82-
- Your `callback` functions should accept two parameters so it can handle both errors: `err` and `response`.
83-
So when a user selects a repository from the list you want to call `fetchJSON` with a different `url` and supply it with a function that handles both errors (display an error message to the user for example) and responses (render it correctly as HTML elements in your page).
84-
- When the user changes the selected repository, any existing repository information in your page should be cleared before displaying the new information.
85-
- Make your functions small and reusable (modular)! That means create separate functions to handle certain steps.
138+
3. Open the `index.html` file in your browser. Notice that it produces the same JSON output that you saw previously when you opened the URL directly in the browser.
86139
87-
Note:
140+
4. Review the `main()` function in `index.js` and examine how this code renders the JSON output in the browser by means of a `pre` HTML element (for demonstration purposes).
88141
89-
1. Please remove all redundant, commented-out code and console.log's from your files before pushing your homework as finished. There is no need for your mentors to review this stuff.
90-
2. Please make sure your code is well-formatted and follows the recommended naming conventions.
142+
### 2.5 Week 1 Assignment
91143
92-
_GO WILD_
144+
The assignment is to produce an application similar to the one illustrated in Figure 1 above.
93145
94-
Again, check out the GitHub API documentation to see what kind of magic stuff you can do with it.
146+
It should include the following components:
95147
96-
The assignment is to implement something extra that is not in the assignment :scream: (nice and vague, right?)
148+
1. An HTML `select` element from which the user can select a HYF repository. This `select` element must be populated with `option` elements, one for each HYF repository.
149+
2. A left-hand column that displays basic information about the selected repository.
150+
3. A right-hand column that displays a list of contributors to the repository.
97151
98-
Endless fun and possibilities. Need inspiration? Check out the GitHub API documentation. Oh, and please make it look nice (hint: use the stuff you learned in HTML/CSS)!
152+
**Functional Requirements:**
99153
154+
1. The list of repositories in the `select` element should be sorted (case-insensitive) on repository name.
155+
2. At start-up your application should display information about the first repository as displayed in the `select` element.
156+
3. When the user changes the selection, the information in the web page should be refreshed for the newly selected repository.
157+
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.
158+
5. You should be able to click on a contributor to open a new browser tab with the GitHub page for that contributor.
159+
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.
160+
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.
161+
162+
![Error rendering](./assets/hyf-github-error.png)
163+
164+
<small>Figure 2. Rendering of network errors.</small>
165+
166+
**Code modifications:**
167+
168+
**`index.js`**
169+
170+
- Add new functions and modify function `main()` as you see fit. It is not likely that you will need to modify `fetchJSON()` and `createAndAppend()`.
171+
172+
**`style.css`**
173+
174+
- Add your own styling.
175+
176+
**Hints:**
177+
178+
- Add one `option` element per repository to the `select` element, where each `option` element has the array index of the repository as its `value` attribute and the name of the repository as its text content:
179+
180+
```html
181+
<select>
182+
<option value="0">alumni</option>
183+
<option value="1">angular</option>
184+
<!-- etc -->
185+
</select>
186+
```
187+
188+
189+
- To sort the list repositories use [`.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) and [`.localeCompare()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare).
190+
191+
- Use CSS media queries and [Flexbox](https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to make the UI responsive.
192+
193+
- To force a 404 network error so that you can test the rendering of errors, change the URL to make an invalid GitHub request, e.g. append an `x` to `orgs`: `orgsx`.
194+
195+
196+
### 2.5 Handing in your homework
197+
198+
199+
1. Push your `week1` branch to GitHub:
200+
201+
```
202+
git push -u origin week1
203+
```
204+
205+
2. Create a pull request for your `week1` branch.
206+
207+
---
100208
101209
_BONUS_ : Code Kata Race
102210
103211
- [Codewars](https://www.codewars.com/collections/hyf-homework-number-2)
104212
105213
106-
## Step 5: Read before next lecture
214+
## Step 3: Read before next lecture
107215
108216
_Deadline Sunday morning_
109217
110-
Go trough the reading material in the [README.md](/Week2/README.md) to prepare for your next class.
111-
112-
>Commit and push your homework in your "hyf-javascript3" GitHub repository.
113-
Make sure that your commit message are meaningful.
114-
Place the link to your repository folder in Trello.
218+
Go through the reading material in the [README.md](/Week2/README.md) to prepare for your next class.

Week1/assets/hyf-github-error.png

10.5 KB
Loading

0 commit comments

Comments
 (0)