All language subtitles for 21. Active Tab Refresh Fix

af Afrikaans
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bn Bengali
bs Bosnian
bg Bulgarian
ca Catalan
ceb Cebuano
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
tl Filipino
fi Finnish
fr French
fy Frisian
gl Galician
ka Georgian
de German
el Greek
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
km Khmer
ko Korean
ku Kurdish (Kurmanji)
ky Kyrgyz
lo Lao
la Latin
lv Latvian
lt Lithuanian
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mn Mongolian
my Myanmar (Burmese)
ne Nepali
no Norwegian
ps Pashto
fa Persian Download
pl Polish
pt Portuguese
pa Punjabi
ro Romanian
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
st Sesotho
sn Shona
sd Sindhi
si Sinhala
sk Slovak
sl Slovenian
so Somali
es Spanish
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
te Telugu
th Thai
tr Turkish
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu
or Odia (Oriya)
rw Kinyarwanda
tk Turkmen
tt Tatar
ug Uyghur
Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated: 1 00:00:00,920 --> 00:00:10,010 We saw in the last video that there's a problem when we refresh the page the active tab is always defaulting. 2 00:00:10,010 --> 00:00:12,580 Back to the home. 3 00:00:12,770 --> 00:00:19,970 Now you can see that up here in the U.R.L. we're still on the correct U.R.L. and we're still rendering 4 00:00:19,970 --> 00:00:21,340 the correct content. 5 00:00:21,380 --> 00:00:25,130 We're just not setting the correct active tab. 6 00:00:25,310 --> 00:00:33,470 The fix for this would then be to check the U.R.L. any time the page loads or refreshes and make sure 7 00:00:33,470 --> 00:00:41,720 that we are set to the correct active tab now doing something every time the component updates. 8 00:00:41,720 --> 00:00:49,910 Sounds like a lifecycle method and so that's actually exactly what we are going to do using the use 9 00:00:50,030 --> 00:00:55,920 effect hook from react the use effect. 10 00:00:55,920 --> 00:01:03,750 Hook is similar to the component did mount lifecycle method but using the hook enables us to use this 11 00:01:03,750 --> 00:01:12,010 for our functional components so if we come down to the beginning of our header function and above the 12 00:01:12,070 --> 00:01:18,450 return statement we can call use effect and open this up. 13 00:01:18,460 --> 00:01:22,100 I actually know that is it going to be an arrow function. 14 00:01:22,120 --> 00:01:28,630 So we are going to create this but inside we're going to set up an arrow function and we'll open that 15 00:01:28,630 --> 00:01:34,050 up and inside of here we can specify the code that we want to run. 16 00:01:34,060 --> 00:01:42,510 Anytime this component updates this is where we want to check the current you are Rel and then set the 17 00:01:42,510 --> 00:01:49,840 appropriate state value for whichever you are real that we are on to find the current U.R.L.. 18 00:01:49,950 --> 00:02:00,090 We're going to use the window object and so we're going to check if the window dot location dot path 19 00:02:00,090 --> 00:02:11,440 name is equal to the route that we want to specify we also want to make sure that the correct value 20 00:02:11,440 --> 00:02:13,150 is not already set. 21 00:02:13,240 --> 00:02:24,310 And so we're going to add a condition to make sure that the value is not already equal equal to zero 22 00:02:24,340 --> 00:02:28,390 which would be the appropriate value for the home screen. 23 00:02:28,390 --> 00:02:38,890 So if we are trying to access adjust the slash home page route and we have not already set that correct 24 00:02:38,890 --> 00:02:49,240 value well then we're going to go in and call set value with zero to set the correct active tab. 25 00:02:49,240 --> 00:02:54,150 We can go ahead and copy this statement and then add in. 26 00:02:54,190 --> 00:03:04,450 Else if front and now we have in else if statement and we'll set the path here to the services page 27 00:03:05,110 --> 00:03:11,860 that would mean then that we need a value of one here and a value of one there as well. 28 00:03:12,400 --> 00:03:15,410 We can continue and copy this. 29 00:03:15,410 --> 00:03:20,490 Again actually inks as it don't like how to copy the first time and then paste it again. 30 00:03:20,530 --> 00:03:23,850 And it looks like it really didn't do a great job here either. 31 00:03:23,950 --> 00:03:28,760 And add the else in front so make sure bring that down. 32 00:03:28,780 --> 00:03:39,310 So else if we are on the revolution revolution page then we would need the second index to be set. 33 00:03:39,370 --> 00:03:50,230 And then if we were on let's fix this if we're on slash about that's going to be our third index and 34 00:03:50,230 --> 00:04:00,900 then else if we are on the slash contact routes that is our fourth index. 35 00:04:01,150 --> 00:04:10,480 And if we do this one last time we fix that up and we do this for the estimate route slash estimate. 36 00:04:10,480 --> 00:04:19,020 And that would be the fifth index if we go ahead and save this that's going ahead and reformat that 37 00:04:19,020 --> 00:04:26,040 code to look a little bit nicer but you'll see we do have an E lint warning here and that's saying that 38 00:04:26,070 --> 00:04:36,570 the use effect contains a call to set value and without providing the use effect hook a list of dependencies. 39 00:04:36,570 --> 00:04:44,430 This could possibly trigger an infinite chain of updating so as part of the built in functionality to 40 00:04:44,430 --> 00:04:53,880 prevent this we can pass along with our object and array of the dependencies that we're using in this 41 00:04:53,970 --> 00:04:55,410 use effect function. 42 00:04:55,500 --> 00:04:58,970 In this case being the value constant. 43 00:04:59,100 --> 00:05:06,510 So by providing that value here in this array that tells the use affect hook that we are depending on 44 00:05:06,540 --> 00:05:12,900 this state value and we want to make sure that if that hasn't changed we don't want to run this code 45 00:05:12,900 --> 00:05:13,490 again. 46 00:05:13,560 --> 00:05:18,990 Otherwise we could potentially get into situations where it runs infinitely. 47 00:05:18,990 --> 00:05:25,590 Now let's go ahead and we'll come over to our application and let's try going to the revolution page. 48 00:05:25,710 --> 00:05:31,950 You can see we're on the revolution here the revolution in the URL and you can see we're highlighted 49 00:05:32,130 --> 00:05:39,240 and let's go ahead and refresh the page and bam you can see that the revolution has stayed highlighted 50 00:05:39,480 --> 00:05:48,120 because now it detected using the use effect hook that when this page updated we were already on the 51 00:05:48,150 --> 00:05:56,520 revolution route and it made sure to then set the correct value for the active tab instead of the default 52 00:05:56,790 --> 00:05:58,650 of 0. 53 00:05:58,650 --> 00:06:05,910 So now that really cleans up our application and really sets up the navigation how we wanted it to except 54 00:06:05,910 --> 00:06:12,840 for one small thing which we're going to fix right now which is this logo here in the header should 55 00:06:12,900 --> 00:06:20,190 also act as a link to the home page because a lot of people simply expect to be able to press that and 56 00:06:20,190 --> 00:06:23,340 return to the landing page of your application. 57 00:06:23,370 --> 00:06:30,510 So let's go ahead and turn that logo into a button real quick by coming down and we're going to wrap 58 00:06:30,570 --> 00:06:34,020 our image here with a button component. 59 00:06:34,350 --> 00:06:44,100 So I'm just going to make sure that you are outside of the image and wrap with a button components and 60 00:06:44,100 --> 00:06:46,710 then we want this button to be a link. 61 00:06:46,740 --> 00:06:54,990 So like the rest of the tabs we're going to have to specify the component prop and set that to our imported 62 00:06:54,990 --> 00:07:03,150 react router link component as well as specifying the to property and setting that to slash for our 63 00:07:03,150 --> 00:07:07,000 home screen if we go ahead and save that. 64 00:07:07,000 --> 00:07:08,550 We'll see how it looks. 65 00:07:08,770 --> 00:07:16,300 And you can see now that there is a bit of a problem we have this boundary around the logo now but that 66 00:07:16,300 --> 00:07:22,180 is actually coming from the button component that we just wrapped it with which has a little bit of 67 00:07:22,180 --> 00:07:23,200 padding. 68 00:07:23,200 --> 00:07:33,180 So let's go ahead and add a class name to our button and we're going to call that classes dot logo container. 69 00:07:33,180 --> 00:07:41,980 Then let's go up to our styles object and underneath the logo let's put our logo container styles and 70 00:07:41,980 --> 00:07:45,580 make sure you get that comma underneath it as well. 71 00:07:45,610 --> 00:07:50,890 And here we're going to set all of the padding equal to zero. 72 00:07:50,950 --> 00:07:58,860 So save that and you can see that that already solved our problem there is one thing I noticed though 73 00:07:58,860 --> 00:08:03,560 in the logo is actually smaller now than it was before. 74 00:08:03,570 --> 00:08:11,370 So let's go ahead and just change the logo height here from 7 M where we had set previously to now 8 75 00:08:11,490 --> 00:08:11,880 m. 76 00:08:11,910 --> 00:08:14,050 So go ahead and save that. 77 00:08:14,160 --> 00:08:18,520 And I think that that looks more about where we were. 78 00:08:18,530 --> 00:08:23,270 So now we can go ahead and we're on the revolution page and let's try out. 79 00:08:23,270 --> 00:08:26,000 You can see it when we hover over the logo. 80 00:08:26,090 --> 00:08:27,460 You can see it does. 81 00:08:27,460 --> 00:08:29,570 It has a little darker opacity right there. 82 00:08:29,570 --> 00:08:36,140 And we get the clicking pointer so let's go ahead and click that and we're taken to our home screen. 83 00:08:36,140 --> 00:08:39,560 But you can see the active tab did not update. 84 00:08:39,560 --> 00:08:47,330 So that's because even though we are using the react router link to navigate to the home page we aren't 85 00:08:47,330 --> 00:08:54,090 doing anything to tell the state value managing our active tab that that has changed. 86 00:08:54,500 --> 00:09:02,300 So what we need to do is come down and up to our button component wrapping our image and we're going 87 00:09:02,300 --> 00:09:09,340 to add in on click handler to the button and we're going to set this just to an arrow function. 88 00:09:09,800 --> 00:09:16,100 So an arrow function in here where we are going to call set value with zero. 89 00:09:16,100 --> 00:09:24,230 And so that will set the value of our state to the default of 0 which should it set it back to the home 90 00:09:24,290 --> 00:09:25,200 page. 91 00:09:25,220 --> 00:09:32,150 So if we go ahead and we save that won't come over here and you can now see that we're on the home page. 92 00:09:32,210 --> 00:09:35,240 Let's try and navigate back to the revolution. 93 00:09:35,360 --> 00:09:42,410 And now let's use the logo to navigate back to the home screen and you can see that the active tab is 94 00:09:42,410 --> 00:09:49,480 managed as well real quick last things that I wanted to do is I really don't like how when you click 95 00:09:49,480 --> 00:09:53,080 this you see the little ripple effect on the logo. 96 00:09:53,080 --> 00:09:55,180 You can see that kind of go through the text there. 97 00:09:55,190 --> 00:10:01,480 The little shadows as well as the corner here when you hover that little darkened opacity I really don't 98 00:10:01,480 --> 00:10:05,800 like that and I don't think they on the logo that's really what you would expect. 99 00:10:05,860 --> 00:10:10,790 But thankfully material UI makes it really easy to fix this. 100 00:10:10,810 --> 00:10:17,860 So for the little ripple effect that you see whenever we press it you can actually set on any button 101 00:10:18,100 --> 00:10:22,120 the disable ripple effect or prop. 102 00:10:22,210 --> 00:10:31,510 And if you save that you can now see that anytime we click this it is not using that ripple effect anymore. 103 00:10:31,510 --> 00:10:35,850 We do still have that little opacity highlights going on though. 104 00:10:35,980 --> 00:10:42,780 And to get rid of that we need to come up to our styles object and on our logo container. 105 00:10:42,880 --> 00:10:52,180 Let's add a property inside of quotation marks and set this to at colon hover. 106 00:10:52,180 --> 00:11:00,010 And then outside the quotation marks a colon in an object which opens up to then set the background 107 00:11:00,370 --> 00:11:06,100 color equal to trans parents. 108 00:11:06,360 --> 00:11:13,140 And that is going to stop that little opacity overlay when we hover on top of the logo. 109 00:11:13,170 --> 00:11:20,790 So if we save that and now the page refreshes we go up and now we've seen no little opacity and if we 110 00:11:20,790 --> 00:11:23,040 click it we don't see any ripple. 111 00:11:23,100 --> 00:11:29,220 So we can go to any of the other pages and we can click that logo to immediately snap back to the home 112 00:11:29,220 --> 00:11:33,030 page like you would expect with that. 113 00:11:33,050 --> 00:11:39,360 I think all of the functionality for the navigation in our header is completely set up. 114 00:11:39,530 --> 00:11:47,390 And now we're going to level this up a little bit by adding a little dropdown to our services tab so 115 00:11:47,390 --> 00:11:53,300 that you can see a menu of the different services appearing underneath it without having to go to the 116 00:11:53,300 --> 00:11:59,980 services page each time but start looking at how to set up this menu in the next video. 13321

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.