1 00:00:00,990 --> 00:00:02,790 Instructor: Now that we've got our project installed 2 00:00:02,790 --> 00:00:04,830 and we've got our dependencies installed, 3 00:00:04,830 --> 00:00:06,810 and on top of that, we've got a better idea 4 00:00:06,810 --> 00:00:08,490 of what higher order components are 5 00:00:08,490 --> 00:00:09,600 and what we're gonna use them for 6 00:00:09,600 --> 00:00:11,220 in this particular project, 7 00:00:11,220 --> 00:00:13,650 let's get started with some real development. 8 00:00:13,650 --> 00:00:15,150 Now, in this project we're gonna go ahead 9 00:00:15,150 --> 00:00:16,800 and make use of React Router. 10 00:00:16,800 --> 00:00:18,570 And so just like in the last section 11 00:00:18,570 --> 00:00:19,560 where it was kind of assumed 12 00:00:19,560 --> 00:00:21,540 that you knew what was going on with React 13 00:00:21,540 --> 00:00:23,640 and what was going on with Redux, 14 00:00:23,640 --> 00:00:25,980 I'm also going to assume inside of this section 15 00:00:25,980 --> 00:00:27,840 that you're going to know 16 00:00:27,840 --> 00:00:30,090 what's going on with React Router as well. 17 00:00:30,090 --> 00:00:31,980 So if you're not familiar with React Router, 18 00:00:31,980 --> 00:00:34,890 I advise you to look up the documentation 19 00:00:34,890 --> 00:00:36,030 a little bit, and what have you. 20 00:00:36,030 --> 00:00:38,280 I've got another course that includes React Router 21 00:00:38,280 --> 00:00:40,230 if you want to go learn it from scratch. 22 00:00:40,230 --> 00:00:44,250 Otherwise, we're really gonna dive in headfirst here. 23 00:00:44,250 --> 00:00:46,080 So thinking back to the mockup 24 00:00:46,080 --> 00:00:47,730 that we were looking at of our application, 25 00:00:47,730 --> 00:00:50,310 we had three buttons up at the top, 26 00:00:50,310 --> 00:00:52,800 and then we had kind of a body to the document as well. 27 00:00:52,800 --> 00:00:56,280 So let's start by working on the header of sorts. 28 00:00:56,280 --> 00:00:58,980 The header is gonna have our three buttons up on the top, 29 00:00:58,980 --> 00:01:01,230 the home route, a link to the home route, 30 00:01:01,230 --> 00:01:03,180 a link to the resources route, 31 00:01:03,180 --> 00:01:05,670 and then a button to toggle the login state 32 00:01:05,670 --> 00:01:07,290 so the user can either set themselves 33 00:01:07,290 --> 00:01:09,063 as being logged in or not. 34 00:01:10,170 --> 00:01:12,240 So this is definitely gonna be a component 35 00:01:12,240 --> 00:01:13,470 that we're gonna create inside 36 00:01:13,470 --> 00:01:16,050 of our source components directory. 37 00:01:16,050 --> 00:01:19,203 I'm gonna make a new file and I'm gonna call it header. 38 00:01:20,580 --> 00:01:22,470 Now, as I've said several times, 39 00:01:22,470 --> 00:01:24,240 we're really focused more on the 40 00:01:24,240 --> 00:01:25,740 higher order component side, 41 00:01:25,740 --> 00:01:27,420 so as we're putting this component together, 42 00:01:27,420 --> 00:01:28,590 we're gonna kind of just speed 43 00:01:28,590 --> 00:01:30,630 through things a little bit here. 44 00:01:30,630 --> 00:01:35,630 I'm gonna import React and Component up at the top, 45 00:01:37,920 --> 00:01:39,783 and then we'll make a class header. 46 00:01:43,350 --> 00:01:45,000 And this header is going to have 47 00:01:45,000 --> 00:01:46,380 several elements inside of it. 48 00:01:46,380 --> 00:01:47,213 It'll have 49 00:01:50,070 --> 00:01:52,770 a parent nav of sorts 50 00:01:52,770 --> 00:01:55,290 and we're gonna be making use of some bootstrap classes 51 00:01:55,290 --> 00:01:57,000 just to make things look nice. 52 00:01:57,000 --> 00:02:02,000 So our nav will have className navbar and navbar-light. 53 00:02:08,130 --> 00:02:10,460 And then inside of the nav we're going to have 54 00:02:10,460 --> 00:02:15,460 an unordered list, className nav navbar-nav. 55 00:02:16,770 --> 00:02:19,890 What a goofy class name that is. 56 00:02:19,890 --> 00:02:21,570 You'd think that they could just reduce it down 57 00:02:21,570 --> 00:02:23,310 to just be nav. 58 00:02:23,310 --> 00:02:25,440 I don't know what navbar-nav is supposed to be, 59 00:02:25,440 --> 00:02:28,053 but that's a complaint for another day. 60 00:02:29,070 --> 00:02:32,370 So we'll show a class name on an li of nav-item. 61 00:02:32,370 --> 00:02:34,800 So this is gonna represent a single clickable thing 62 00:02:34,800 --> 00:02:36,420 that the user can click on. 63 00:02:36,420 --> 00:02:39,450 And we're gonna end up having three of these things, 64 00:02:39,450 --> 00:02:41,190 one for each of our buttons. 65 00:02:41,190 --> 00:02:43,530 The first one is gonna be a link to the homepage, 66 00:02:43,530 --> 00:02:46,290 which will be our unauthenticated route. 67 00:02:46,290 --> 00:02:49,110 The second one is gonna be a link to the protected route, 68 00:02:49,110 --> 00:02:51,540 the resources route of sorts. 69 00:02:51,540 --> 00:02:55,260 And the final one is gonna be for our actual login button. 70 00:02:55,260 --> 00:02:57,360 So it'll have a button that says 71 00:02:57,360 --> 00:02:59,940 log in, or log out, or what have you. 72 00:02:59,940 --> 00:03:01,980 It also looks like I made a little bit of a typo here. 73 00:03:01,980 --> 00:03:02,940 Be aware of it. 74 00:03:02,940 --> 00:03:05,100 I did not close the li tags. 75 00:03:05,100 --> 00:03:09,660 So I'm gonna just put on a closing one like so. 76 00:03:09,660 --> 00:03:11,670 It should be normal jsx. 77 00:03:11,670 --> 00:03:14,163 Opening and closing tag underneath it. 78 00:03:16,290 --> 00:03:19,290 So we're going to assume that we're going to have 79 00:03:19,290 --> 00:03:21,720 link tags to each of our different routes. 80 00:03:21,720 --> 00:03:25,350 Remember, link tags are a part of React Router. 81 00:03:25,350 --> 00:03:30,210 A link tag is a component that we import from React Router, 82 00:03:30,210 --> 00:03:32,190 and whenever we place one down, 83 00:03:32,190 --> 00:03:33,960 when it actually gets rendered onto the page, 84 00:03:33,960 --> 00:03:37,260 it's gonna show up as an anchored tag. 85 00:03:37,260 --> 00:03:40,350 So we'll put a link to forward-slash. 86 00:03:40,350 --> 00:03:41,883 So this will be our homepage. 87 00:03:43,350 --> 00:03:45,057 And we'll put text "home." 88 00:03:46,050 --> 00:03:48,150 We'll have a link to... 89 00:03:48,150 --> 00:03:49,950 Now this is the protected route here. 90 00:03:49,950 --> 00:03:51,697 This is the one that we're going to want to say, 91 00:03:51,697 --> 00:03:52,957 "Hey, if you're trying to visit this 92 00:03:52,957 --> 00:03:55,357 "and you're not authenticated, I'm gonna boot you out. 93 00:03:55,357 --> 00:03:57,870 "You're gonna go back to the home route." 94 00:03:57,870 --> 00:04:00,870 So on this one, the path doesn't necessarily matter, 95 00:04:00,870 --> 00:04:01,950 but we're gonna come up with a 96 00:04:01,950 --> 00:04:06,510 at least somewhat meaningful route name here. 97 00:04:06,510 --> 00:04:08,370 So we'll call it resources. 98 00:04:08,370 --> 00:04:11,460 And so again, resources is gonna be our protected route. 99 00:04:11,460 --> 00:04:14,070 If someone tries to go to slash-resources 100 00:04:14,070 --> 00:04:15,630 and they aren't authenticated, 101 00:04:15,630 --> 00:04:18,360 we're gonna kick them back to the home screen, 102 00:04:18,360 --> 00:04:19,923 which is just forward-slash. 103 00:04:23,520 --> 00:04:24,900 And then the text for this one 104 00:04:24,900 --> 00:04:27,600 we'll say is just "resources." 105 00:04:27,600 --> 00:04:31,220 And finally, at the bottom we'll say this.authButton. 106 00:04:32,610 --> 00:04:35,160 So we'll make a helper method to render our authButton. 107 00:04:35,160 --> 00:04:38,580 And the reasons for that will be clear very shortly. 108 00:04:38,580 --> 00:04:41,520 For right now, let's just go ahead 109 00:04:41,520 --> 00:04:43,980 and show a single button on the screen. 110 00:04:43,980 --> 00:04:45,357 So we'll just say "button," 111 00:04:49,170 --> 00:04:52,950 and we'll say "sign in." 112 00:04:52,950 --> 00:04:54,840 So by default right now, 113 00:04:54,840 --> 00:04:56,220 the button's always gonna say "sign in," 114 00:04:56,220 --> 00:04:59,160 but later on we'll give it a little bit more interaction. 115 00:04:59,160 --> 00:05:01,380 We'll give users the ability to kind of toggle 116 00:05:01,380 --> 00:05:04,530 between the sign-in and sign-out states. 117 00:05:04,530 --> 00:05:07,080 So at the bottom, one more step: 118 00:05:07,080 --> 00:05:09,693 we will export default header. 119 00:05:10,980 --> 00:05:12,780 All right, so this works for our header right now. 120 00:05:12,780 --> 00:05:14,070 Pretty straightforward. 121 00:05:14,070 --> 00:05:17,220 Just show a header, three links at the top. 122 00:05:17,220 --> 00:05:20,160 Let's make sure that this header is always visible 123 00:05:20,160 --> 00:05:22,740 no matter what route the user is on. 124 00:05:22,740 --> 00:05:24,120 Now, to make sure that it's visible 125 00:05:24,120 --> 00:05:26,250 no matter what route the user's on, 126 00:05:26,250 --> 00:05:29,430 we're going to go back into app.js, 127 00:05:29,430 --> 00:05:33,540 and we'll say that app.js should show the header. 128 00:05:33,540 --> 00:05:38,043 So we'll import Header from header. 129 00:05:39,210 --> 00:05:41,660 I'm gonna remove the text that's already in here, 130 00:05:43,320 --> 00:05:44,820 and we'll just show header. 131 00:05:44,820 --> 00:05:47,880 Always show the header inside of our app. 132 00:05:47,880 --> 00:05:50,730 So I would love to do a quick test of this in the browser, 133 00:05:50,730 --> 00:05:53,040 make sure that everything is working. 134 00:05:53,040 --> 00:05:57,153 So I'm going to flip over to my terminal: npm run start. 135 00:06:04,230 --> 00:06:07,380 Looks like I've already got my server running here. 136 00:06:07,380 --> 00:06:09,830 Just make sure that you're running yours as well. 137 00:06:10,980 --> 00:06:13,860 And then I should be able to pick up my browser, 138 00:06:13,860 --> 00:06:16,860 go to localhost:8080, and at the top, 139 00:06:16,860 --> 00:06:19,830 I'll see home, resources, and sign in. 140 00:06:19,830 --> 00:06:22,050 Perfect. Just what we want for right now. 141 00:06:22,050 --> 00:06:23,880 So this is really gonna form kind of 142 00:06:23,880 --> 00:06:25,320 the backbone of our application right here, 143 00:06:25,320 --> 00:06:26,700 at least on the Vue side. 144 00:06:26,700 --> 00:06:28,410 The only other big things we have to do 145 00:06:28,410 --> 00:06:31,440 are create the kind of protected resources route. 146 00:06:31,440 --> 00:06:32,910 We need to implement the idea 147 00:06:32,910 --> 00:06:34,800 of signing in and signing out. 148 00:06:34,800 --> 00:06:37,020 And then we'll focus on the higher-order component. 149 00:06:37,020 --> 00:06:38,010 So we're still gonna do a 150 00:06:38,010 --> 00:06:39,630 little bit more setup inside this app 151 00:06:39,630 --> 00:06:41,940 until we get to the higher-order component part, 152 00:06:41,940 --> 00:06:44,040 but as we're going through the app setup, 153 00:06:44,040 --> 00:06:46,680 at least it's a good review of React Router 154 00:06:46,680 --> 00:06:48,900 and a little bit of Redux in there as well. 155 00:06:48,900 --> 00:06:52,170 So let's continue with the baseline setup of this app 156 00:06:52,170 --> 00:06:53,433 inside the next section.