You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/5/en/part5a.md
+26-25Lines changed: 26 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,7 +86,7 @@ const App = () => {
86
86
exportdefaultApp
87
87
```
88
88
89
-
The current application code can be found on [Github](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-1), branch <i>part5-1</i>. If you clone the repo, don't forget to run _npm install_ before attempting to run the frontend.
89
+
The current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-1), in the branch <i>part5-1</i>. If you clone the repo, don't forget to run _npm install_ before attempting to run the frontend.
90
90
91
91
The frontend will not display any notes if it's not connected to the backend. You can start the backend with _npm run dev_ in its folder from Part 4. This will run the backend on port 3001. While that is active, in a separate terminal window you can start the frontend with _npm start_, and now you can see the notes that are saved in your MongoDB database from Part 4.
92
92
@@ -294,10 +294,11 @@ return (
294
294
295
295
<Notification message={errorMessage} />
296
296
297
-
{!user &&loginForm()}
298
-
{user &&<div>
299
-
<p>{user.name} logged in</p>
300
-
{noteForm()}
297
+
{user ===null?
298
+
loginForm() :
299
+
<div>
300
+
<p>{user.name} logged-in</p>
301
+
{noteForm()}
301
302
</div>
302
303
}
303
304
@@ -309,11 +310,11 @@ return (
309
310
)
310
311
```
311
312
312
-
The solution isn't perfect, but we'll leave it for now.
313
+
The solution isn't perfect, but we'll leave it like this for now.
313
314
314
315
Our main component <i>App</i> is at the moment way too large. The changes we did now are a clear sign that the forms should be refactored into their own components. However, we will leave that for an optional exercise.
315
316
316
-
The current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-2), branch <i>part5-2</i>.
317
+
The current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-2), in the branch <i>part5-2</i>.
The noteService module contains a private variable _token_. Its value can be changed with a function _setToken_, which is exported by the module. _create_, now with async/await syntax, sets the token to the <i>Authorization</i> header. The header is given to axios as the third parameter of the <i>post</i> method.
380
+
The noteService module contains a private variable called _token_. Its value can be changed with the _setToken_ function, which is exported by the module. _create_, now with async/await syntax, sets the token to the <i>Authorization</i> header. The header is given to axios as the third parameter of the <i>post</i> method.
380
381
381
382
The event handler responsible for login must be changed to call the method <code>noteService.setToken(user.token)</code> with a successful login:
382
383
@@ -420,7 +421,7 @@ The value of a key can be found with the method [getItem](https://developer.mozi
420
421
window.localStorage.getItem('name')
421
422
```
422
423
423
-
and[removeItem](https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem) removes a key.
424
+
while[removeItem](https://developer.mozilla.org/en-US/docs/Web/API/Storage/removeItem) removes a key.
424
425
425
426
Values in the local storage are persisted even when the page is re-rendered. The storage is [origin](https://developer.mozilla.org/en-US/docs/Glossary/Origin)-specific so each web application has its own storage.
426
427
@@ -453,13 +454,13 @@ Changes to the login method are as follows:
453
454
}
454
455
```
455
456
456
-
The details of a logged-in user are now saved to the local storage, and they can be viewed on the console (by typing _window.localStorage_to the console):
457
+
The details of a logged-in user are now saved to the local storage, and they can be viewed on the console (by typing _window.localStorage_in it):
457
458
458
-

459
+

459
460
460
-
You can also inspect the local storage using the developer tools. On Chrome, go to the <i>Application</i> tab and select <i>Local Storage</i> (more details [here](https://developers.google.com/web/tools/chrome-devtools/storage/localstorage)). On Firefox go to the <i>Storage</i> tab and select <i>Local Storage</i> (details [here](https://developer.mozilla.org/en-US/docs/Tools/Storage_Inspector)).
461
+
You can also inspect the local storage using the developer tools. On Chrome, go to the <i>Application</i> tab and select <i>Local Storage</i> (more details [here](https://developer.chrome.com/docs/devtools/storage/localstorage)). On Firefox go to the <i>Storage</i> tab and select <i>Local Storage</i> (details [here](https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html)).
461
462
462
-
We still have to modify our application so that when we enter the page, the application checks if user details of a logged-in user can already be found on the local storage. If they can, the details are saved to the state of the application and to <i>noteService</i>.
463
+
We still have to modify our application so that when we enter the page, the application checks if user details of a logged-in user can already be found on the local storage. If they are there, the details are saved to the state of the application and to <i>noteService</i>.
463
464
464
465
The right way to do this is with an [effect hook](https://react.dev/reference/react/useEffect): a mechanism we first encountered in [part 2](/en/part2/getting_data_from_server#effect-hooks), and used to fetch notes from the server.
465
466
@@ -514,34 +515,34 @@ or with the command which empties <i>localstorage</i> completely:
514
515
window.localStorage.clear()
515
516
```
516
517
517
-
The current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-3), branch <i>part5-3</i>.
518
+
The current application code can be found on [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-3), in the branch <i>part5-3</i>.
518
519
519
520
</div>
520
521
521
522
<divclass="tasks">
522
523
523
524
### Exercises 5.1.-5.4.
524
525
525
-
We will now create a frontend for the bloglist backend we created in the last part. You can use [this application](https://github.com/fullstack-hy2020/bloglist-frontend) from GitHub as the base of your solution. You need to connect your backend with proxy as shown in [part 3](https://fullstackopen.com/en/part3/deploying_app_to_internet#proxy).
526
+
We will now create a frontend for the blog list backend we created in the last part. You can use [this application](https://github.com/fullstack-hy2020/bloglist-frontend) from GitHub as the base of your solution. You need to connect your backend with a proxy as shown in [part 3](/en/part3/deploying_app_to_internet#proxy).
526
527
527
-
It is enough to submit your finished solution. You can do a commit after each exercise, but that is not necessary.
528
+
It is enough to submit your finished solution. You can commit after each exercise, but that is not necessary.
528
529
529
530
The first few exercises revise everything we have learned about React so far. They can be challenging, especially if your backend is incomplete.
530
531
It might be best to use the backend that we marked as the answer for part 4.
531
532
532
533
While doing the exercises, remember all of the debugging methods we have talked about, especially keeping an eye on the console.
533
534
534
-
**Warning:** If you notice you are mixing in the functions _async/await_ and _then_ commands, it's 99.9% certain you are doing something wrong. Use either or, never both.
535
+
**Warning:** If you notice you are mixing in the _async/await_ and _then_ commands, it's 99.9% certain you are doing something wrong. Use either or, never both.
535
536
536
-
#### 5.1: bloglist frontend, step1
537
+
#### 5.1: Blog List Frontend, step 1
537
538
538
539
Clone the application from [GitHub](https://github.com/fullstack-hy2020/bloglist-frontend) with the command:
<i>remove the git configuration of the cloned application</i>
545
+
<i>Remove the git configuration of the cloned application</i>
545
546
546
547
```bash
547
548
cd bloglist-frontend // go to cloned repository
@@ -563,7 +564,7 @@ If a user is not logged in, <i>only</i> the login form is visible.
563
564
564
565
If the user is logged-in, the name of the user and a list of blogs is shown.
565
566
566
-

567
+

567
568
568
569
User details of the logged-in user do not have to be saved to the local storage yet.
569
570
@@ -592,29 +593,29 @@ User details of the logged-in user do not have to be saved to the local storage
592
593
}
593
594
```
594
595
595
-
#### 5.2: bloglist frontend, step2
596
+
#### 5.2: Blog List Frontend, step 2
596
597
597
598
Make the login 'permanent' by using the local storage. Also, implement a way to log out.
598
599
599
600

600
601
601
602
Ensure the browser does not remember the details of the user after logging out.
602
603
603
-
#### 5.3: bloglist frontend, step3
604
+
#### 5.3: Blog List Frontend, step 3
604
605
605
606
Expand your application to allow a logged-in user to add new blogs:
606
607
607
608

608
609
609
-
#### 5.4: bloglist frontend, step4
610
+
#### 5.4: Blog List Frontend, step 4
610
611
611
612
Implement notifications that inform the user about successful and unsuccessful operations at the top of the page. For example, when a new blog is added, the following notification can be shown:
0 commit comments