Skip to content

Commit 9db42bc

Browse files
authored
Merge pull request #2628 from onzfonz/autofix_markdown_10
markdownlint autofix part 10
2 parents 1d049f4 + fd862d6 commit 9db42bc

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/content/10/en/part10a.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,17 @@ Let's look at the <i>scripts</i> section of the <i>package.json</i> file which h
8080
}
8181
```
8282

83-
Let us now run the script _npm start_
83+
Let us now run the script *npm start*
8484

85-
![](../../images/10/25new.png)
85+
![metro bundler console output](../../images/10/25new.png)
8686

8787
> <i>If the script fails with error</i>
8888
>
89-
>```
89+
>```bash
9090
>error:03000086:digital envelope routines::initialization
9191
>```
9292
>
93-
> <i>the problem is most likely your Node version. In case of problems, switch to version _16.19.0_. See eg. [here](https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported) for more.</i>
94-
93+
> <i>the problem is most likely your Node version. In case of problems, switch to version *16.19.0*. See eg. [here](https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported) for more.</i>
9594
9695
The script starts the [Metro bundler](https://facebook.github.io/metro/) which is a JavaScript bundler for React Native. It can be described as the [Webpack](https://webpack.js.org/) of the React Native ecosystem. In addition to the Metro bundler, the Expo command-line interface should be open in the terminal window. The command-line interface has a useful set of commands for viewing the application logs and starting the application in an emulator or in Expo's mobile application. We will get to emulators and Expo's mobile application soon, but first, let's open our application.
9796

src/content/10/en/part10c.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ Next, let's try the Fetch API in practice. The rate-repository-api server provid
6060

6161
Unfortunately, we can't access the server directly in our application by using the <i>http://localhost:5000/api/repositories</i> URL. To make a request to this endpoint in our application we need to access the server using its IP address in its local network. To find out what it is, open the Expo development tools by running <em>npm start</em>. In the console you should be able to see an URL starting with <i>exp://</i> below the QR code, after the "Metro waiting on" text:
6262

63-
![](../../images/10/26new.png)
63+
![metro console output with highlight over exp://<ip> url](../../images/10/26new.png)
6464

65-
Copy the IP address between the <i>exp://</i> and <i>:</i>, which is in this example <i>192.168.1.33</i>. Construct an URL in format <i>http://<IP_ADDRESS>:5000/api/repositories</i> and open it in the browser. You should see the same response as you did with the <i>localhost</i> URL.
65+
Copy the IP address between the <i>exp://</i> and <i>:</i>, which is in this example <i>192.168.1.33</i>. Construct an URL in format <i><http://><IP_ADDRESS>:5000/api/repositories</i> and open it in the browser. You should see the same response as you did with the <i>localhost</i> URL.
6666

6767
Now that we know the end point's URL let's use the actual server-provided data in our reviewed repositories list. We are currently using mock data stored in the <em>repositories</em> variable. Remove the <em>repositories</em> variable and replace the usage of the mock data with this piece of code in the <i>RepositoryList.jsx</i> file in the <i>components</i> directory:
6868

@@ -284,7 +284,7 @@ Once our application grows larger there might be times when certain files grow t
284284

285285
- Create files <i>B.jsx</i> and <i>C.jsx</i> in the <i>components</i> directory. This results in the following structure:
286286

287-
```
287+
```bash
288288
components/
289289
A.jsx
290290
B.jsx
@@ -294,7 +294,7 @@ components/
294294

295295
- Create a directory <i>A</i> in the <i>components</i> directory and create files <i>B.jsx</i> and <i>C.jsx</i> there. To avoid breaking components that import the <i>A.jsx</i> file, move the <i>A.jsx</i> file to the <i>A</i> directory and rename it to <i>index.jsx</i>. This results in the following structure:
296296

297-
```
297+
```bash
298298
components/
299299
A/
300300
B.jsx
@@ -309,13 +309,13 @@ The first option is fairly decent, however, if components <em>B</em> and <em>C</
309309

310310
<div class="tasks">
311311

312-
### Exercise 10.11.
312+
### Exercise 10.11
313313

314314
#### Exercise 10.11: fetching repositories with Apollo Client
315315

316316
We want to replace the Fetch API implementation in the <em>useRepositories</em> hook with a GraphQL query. Open the Apollo Sandbox at [http://localhost:4000](http://localhost:4000) and take a look at the documentation next to the operations editor. Look up the <em>repositories</em> query. The query has some arguments, however, all of these are optional so you don't need to specify them. In the Apollo Sandbox form a query for fetching the repositories with the fields you are currently displaying in the application. The result will be paginated and it contains the up to first 30 results by default. For now, you can ignore the pagination entirely.
317317

318-
Once the query is working in the Apollo Sandbox, use it to replace the Fetch API implementation in the <em>useRepositories</em> hook. This can be achieved using the [useQuery](https://www.apollographql.com/docs/react/api/react/hooks/#usequery) hook. The <em>gql</em> template literal tag can be imported from the <i>@apollo/client</i> library as instructed earlier. Consider using the structure recommended earlier for the GraphQL related code. To avoid future caching issues, use the _cache-and-network_ [fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy) in the query. It can be used with the <em>useQuery</em> hook like this:
318+
Once the query is working in the Apollo Sandbox, use it to replace the Fetch API implementation in the <em>useRepositories</em> hook. This can be achieved using the [useQuery](https://www.apollographql.com/docs/react/api/react/hooks/#usequery) hook. The <em>gql</em> template literal tag can be imported from the <i>@apollo/client</i> library as instructed earlier. Consider using the structure recommended earlier for the GraphQL related code. To avoid future caching issues, use the *cache-and-network* [fetch policy](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy) in the query. It can be used with the <em>useQuery</em> hook like this:
319319

320320
```javascript
321321
useQuery(MY_QUERY, {
@@ -431,7 +431,7 @@ npm install dotenv
431431

432432
Next, add a <em>.env</em> file in the root directory of our project with the following content:
433433

434-
```
434+
```text
435435
ENV=development
436436
```
437437

@@ -457,7 +457,7 @@ Note that it is <i>never</i> a good idea to put sensitive data into the applicat
457457

458458
<div class="tasks">
459459

460-
### Exercise 10.12.
460+
### Exercise 10.12
461461

462462
#### Exercise 10.12: environment variables
463463

@@ -545,13 +545,13 @@ We can add an item to the storage using the [AsyncStorage.setItem](https://react
545545

546546
<div class="tasks">
547547

548-
### Exercises 10.13. - 10.14.
548+
### Exercises 10.13. - 10.14
549549

550550
#### Exercise 10.13: the sign in form mutation
551551

552552
The current implementation of the sign in form doesn't do much with the submitted user's credentials. Let's do something about that in this exercise. First, read the rate-repository-api server's [authentication documentation](https://github.com/fullstack-hy2020/rate-repository-api#-authentication) and test the provided queries and mutations in the Apollo Sandbox. If the database doesn't have any users, you can populate the database with some seed data. Instructions for this can be found in the [getting started](https://github.com/fullstack-hy2020/rate-repository-api#-getting-started) section of the README.
553553

554-
Once you have figured out how the authentication works, create a file _useSignIn.js_ file in the <i>hooks</i> directory. In that file implement a <em>useSignIn</em> hook that sends the <em>authenticate</em> mutation using the [useMutation](https://www.apollographql.com/docs/react/api/react/hooks/#usemutation) hook. Note that the <em>authenticate</em> mutation has a <i>single</i> argument called <em>credentials</em>, which is of type <em>AuthenticateInput</em>. This [input type](https://graphql.org/graphql-js/mutations-and-input-types) contains <em>username</em> and <em>password</em> fields.
554+
Once you have figured out how the authentication works, create a file *useSignIn.js* file in the <i>hooks</i> directory. In that file implement a <em>useSignIn</em> hook that sends the <em>authenticate</em> mutation using the [useMutation](https://www.apollographql.com/docs/react/api/react/hooks/#usemutation) hook. Note that the <em>authenticate</em> mutation has a <i>single</i> argument called <em>credentials</em>, which is of type <em>AuthenticateInput</em>. This [input type](https://graphql.org/graphql-js/mutations-and-input-types) contains <em>username</em> and <em>password</em> fields.
555555

556556
The return value of the hook should be a tuple <em>[signIn, result]</em> where <em>result</em> is the mutations result as it is returned by the <em>useMutation</em> hook and <em>signIn</em> a function that runs the mutation with a <em>{ username, password }</em> object argument. Hint: don't pass the mutation function to the return value directly. Instead, return a function that calls the mutation function like this:
557557

@@ -782,14 +782,14 @@ const useSignIn = () => {
782782
```
783783

784784
The ability to provide data to component's descendants opens tons of use cases for React Context, as we already saw in the [last chapter](/en/part6/react_query_use_reducer_and_the_context) of part 6.
785-
785+
786786
To learn more about these use cases, read Kent C. Dodds' enlightening article [How to use React Context effectively](https://kentcdodds.com/blog/how-to-use-react-context-effectively) to find out how to combine the [useReducer](https://reactjs.org/docs/hooks-reference.html#usereducer) hook with the context to implement state management. You might find a way to use this knowledge in the upcoming exercises.
787787

788788
</div>
789789

790790
<div class="tasks">
791791

792-
### Exercises 10.15. - 10.16.
792+
### Exercises 10.15. - 10.16
793793

794794
#### Exercise 10.15: storing the access token step2
795795

@@ -816,7 +816,7 @@ The final step in completing the sign in feature is to implement a sign out feat
816816
}
817817
```
818818

819-
You will probably end up with the <em>null</em> result. This is because the Apollo Sandbox is not authenticated, meaning that it doesn't send a valid access token with the request. Revise the [authentication documentation](https://github.com/fullstack-hy2020/rate-repository-api#-authentication) and retrieve an access token using the <em>authenticate</em> mutation. Use this access token in the _Authorization_ header as instructed in the documentation. Now, run the <em>me</em> query again and you should be able to see the authenticated user's information.
819+
You will probably end up with the <em>null</em> result. This is because the Apollo Sandbox is not authenticated, meaning that it doesn't send a valid access token with the request. Revise the [authentication documentation](https://github.com/fullstack-hy2020/rate-repository-api#-authentication) and retrieve an access token using the <em>authenticate</em> mutation. Use this access token in the *Authorization* header as instructed in the documentation. Now, run the <em>me</em> query again and you should be able to see the authenticated user's information.
820820

821821
Open the <em>AppBar</em> component in the <i>AppBar.jsx</i> file where you currently have the tabs "Repositories" and "Sign in". Change the tabs so that if the user is signed in the tab "Sign out" is displayed, otherwise show the "Sign in" tab. You can achieve this by using the <em>me</em> query with the [useQuery](https://www.apollographql.com/docs/react/api/react/hooks/#usequery) hook.
822822

0 commit comments

Comments
 (0)