Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,270 --> 00:00:01,290
In this video.
2
00:00:01,290 --> 00:00:07,410
What we're going to do is we're going to solve this styling issue that we are facing currently.
3
00:00:07,800 --> 00:00:14,840
So you can see right now everything has a border radius to the left, which is not what we want.
4
00:00:14,850 --> 00:00:22,830
Instead, what we want is a border radius to the left for the leftmost button and no border radius for
5
00:00:22,830 --> 00:00:24,000
anything in the middle.
6
00:00:24,240 --> 00:00:29,460
And then at the very rightmost button, we should have a border radius to the right.
7
00:00:30,090 --> 00:00:34,620
So if we're thinking right away, there actually is a way to accomplish this.
8
00:00:34,860 --> 00:00:40,020
So let's go over here to our point of view and let's look at these buttons over here.
9
00:00:40,410 --> 00:00:46,080
So very simply, what we can do here is we can check the index of the element that we are iterating
10
00:00:46,080 --> 00:00:46,590
over.
11
00:00:46,860 --> 00:00:51,270
So remember over here we're iterating over the buttons.
12
00:00:51,570 --> 00:00:56,610
So the button's right over here and then we're rendering obviously a button for each one.
13
00:00:57,120 --> 00:01:04,890
Now, what we can also do over here inside of our v4 is grab the index of the element that we are iterating
14
00:01:04,890 --> 00:01:07,710
over so we can grab that index.
15
00:01:08,160 --> 00:01:09,510
Now over here we can check.
16
00:01:09,540 --> 00:01:15,720
Okay, if the index is zero, that means it is going to be the leftmost button and we need to apply
17
00:01:15,720 --> 00:01:17,940
the option left class.
18
00:01:18,240 --> 00:01:22,020
If it's somewhere in the middle, then we don't want to apply that.
19
00:01:22,320 --> 00:01:28,410
And if it's all the way to the right, meaning that it is the length of the array minus one, because
20
00:01:28,620 --> 00:01:35,460
index is work 012 this is going to be the length of three, so minus one it's going to be two.
21
00:01:35,610 --> 00:01:40,860
That means that this is at the very end and we should apply the option right class.
22
00:01:41,580 --> 00:01:43,620
So that is what we're going to need to do.
23
00:01:43,620 --> 00:01:48,000
We're going to need to create a function that is going to compute our class.
24
00:01:48,360 --> 00:01:53,730
However, it's a little bit more complicated because right over here we're also doing another computation
25
00:01:53,730 --> 00:01:55,380
to determine the class.
26
00:01:56,130 --> 00:02:02,580
Right over here, we're computing if this is the active class and then we're providing the option active.
27
00:02:02,760 --> 00:02:07,890
So we actually need to also include this right over here inside of our computation.
28
00:02:08,460 --> 00:02:11,470
So let's actually go ahead and create a function for this.
29
00:02:11,470 --> 00:02:16,350
So I'm going to go ahead and I'm going to create a function and I'm going to say I'm going to call this
30
00:02:16,350 --> 00:02:20,310
compute button classes like so.
31
00:02:20,700 --> 00:02:27,300
And this is going to take two values in the value and it's also going to take in the index.
32
00:02:28,230 --> 00:02:36,480
So the first thing that I want to do is I want to define all of the class names in an array because
33
00:02:36,480 --> 00:02:39,600
again, we could have multiple different class names that we want to add.
34
00:02:39,600 --> 00:02:45,420
For example, we could want to add in this case, for example, we want to add the option left as well
35
00:02:45,420 --> 00:02:46,980
as the option active.
36
00:02:47,190 --> 00:02:52,110
However, for other ones, we might just want to add option left or option active only.
37
00:02:52,260 --> 00:02:55,230
But again, we could have multiple or we could just have one.
38
00:02:55,470 --> 00:02:58,050
So if we have multiple, I just want to store them in an array.
39
00:02:58,260 --> 00:03:02,490
If you also have one, I'll just store that one element in that array as well.
40
00:03:03,330 --> 00:03:08,130
So the first thing that I want to do is let's actually just do this check right over here.
41
00:03:08,460 --> 00:03:15,120
And if this check this check right here is true, then I'm going to go ahead and push the option active
42
00:03:15,120 --> 00:03:16,110
into this array.
43
00:03:17,040 --> 00:03:20,910
So I'm going to say if and I'm going to get access to the props here.
44
00:03:20,970 --> 00:03:22,440
So I'm going to say props.
45
00:03:23,340 --> 00:03:27,660
And then over here I can pretty much just copy this check right over here.
46
00:03:28,020 --> 00:03:31,470
I can say if props and then.
47
00:03:32,740 --> 00:03:41,770
So if probes dot options and then over here we can say probs dot option dot category is equal to the
48
00:03:41,770 --> 00:03:43,240
value that we're going to pass in.
49
00:03:43,600 --> 00:03:44,980
Then what do I want to do?
50
00:03:45,310 --> 00:03:52,420
Well, I'm just going to say class name, dot push and then of course, I'm going to push option active.
51
00:03:53,570 --> 00:03:54,000
Okay.
52
00:03:54,020 --> 00:03:59,690
So that's the that's pretty much all it is that we need to do to handle the active class.
53
00:04:00,320 --> 00:04:06,320
Now, what we want to do is we want to start handling the either option left or option right class.
54
00:04:06,860 --> 00:04:07,910
So this was actually pretty easy.
55
00:04:07,910 --> 00:04:09,710
This is where we're going to start using the index.
56
00:04:09,710 --> 00:04:15,350
So we're going to say if the index is equal to zero, that means this is going to be the leftmost button.
57
00:04:15,830 --> 00:04:19,940
Then what we're going to do is we're going to say class names, dot push.
58
00:04:21,090 --> 00:04:23,610
And over here we're going to say option left.
59
00:04:23,670 --> 00:04:24,840
That's what we want to push.
60
00:04:25,800 --> 00:04:28,350
Now let's handle the rightmost button.
61
00:04:28,800 --> 00:04:36,030
So over here, what we're going to do is we're going to say if index is equal to props.
62
00:04:36,690 --> 00:04:38,130
Dot option.
63
00:04:39,430 --> 00:04:43,870
Dot button's dot length minus one.
64
00:04:44,440 --> 00:04:48,880
Then what we're going to do is we're going to say class name, dot push.
65
00:04:50,230 --> 00:04:53,170
And then over here we're going to say option, right?
66
00:04:53,170 --> 00:04:53,950
Like so.
67
00:04:54,520 --> 00:05:00,910
So this is going to give us an array of different classes, but obviously we cannot put that array inside
68
00:05:00,910 --> 00:05:01,630
of our class.
69
00:05:01,630 --> 00:05:02,830
We need a string for this.
70
00:05:03,340 --> 00:05:08,710
So at the very end, what we're going to do after we've done all these if statement, all these conditional
71
00:05:08,710 --> 00:05:14,470
checks, all we're going to do is we're going to return class name and then dot join and then we're
72
00:05:14,470 --> 00:05:16,690
going to join with a space.
73
00:05:16,700 --> 00:05:25,360
So what this is going to do is let's say we have an array like this option active and then over here
74
00:05:25,360 --> 00:05:26,710
we have option.
75
00:05:28,140 --> 00:05:29,350
Option left?
76
00:05:29,730 --> 00:05:34,680
Well, this is going to do it is going to take this first element and it's going to put it inside of
77
00:05:34,680 --> 00:05:35,280
a string.
78
00:05:35,280 --> 00:05:41,280
So it's going to say option active, and then it's going to take this element and also put it in the
79
00:05:41,280 --> 00:05:41,730
string.
80
00:05:41,730 --> 00:05:45,510
But before it does that, it's going to apply whatever we put over here, which is a space.
81
00:05:45,860 --> 00:05:48,930
So it's going to say space and then option left.
82
00:05:49,200 --> 00:05:51,510
And that's exactly how we're going to apply classes.
83
00:05:52,050 --> 00:05:53,940
So over here we can get rid of that.
84
00:05:54,900 --> 00:06:03,120
Now, what we can do here is actually grab this compute button class and right over here, inside of
85
00:06:03,120 --> 00:06:12,120
this class, we can just invoke it and we can pass that value in as well as the index.
86
00:06:12,630 --> 00:06:17,130
So now if you come back here and do a quick refresh.
87
00:06:18,450 --> 00:06:20,250
Let's do that little quick refresh.
88
00:06:20,250 --> 00:06:23,640
So seems as though we have a little bit of a bug here.
89
00:06:24,210 --> 00:06:25,460
Let's see why that is.
90
00:06:26,520 --> 00:06:28,260
We're still getting some of that.
91
00:06:28,270 --> 00:06:32,570
Uh, we're still getting some, uh, a radius to the left here.
92
00:06:32,580 --> 00:06:34,290
However, we're not getting anything here.
93
00:06:34,530 --> 00:06:35,480
Not going to be anything here.
94
00:06:35,490 --> 00:06:39,360
So it seems something in the middle is messing things up.
95
00:06:39,990 --> 00:06:42,780
So if the index is equal to zero.
96
00:06:43,170 --> 00:06:43,860
Okay.
97
00:06:44,040 --> 00:06:46,840
So for some reason, we're hitting this block right here.
98
00:06:47,430 --> 00:06:49,730
So let's actually see why we're doing that.
99
00:06:49,740 --> 00:06:57,450
So what I'm going to do here is I am going to console oh, I know exactly why this is happening.
100
00:06:58,080 --> 00:07:00,120
We need to remove this right here.
101
00:07:00,240 --> 00:07:04,170
So let's go ahead and remove that and there we go.
102
00:07:04,380 --> 00:07:06,330
So, yeah, that was pretty much.
103
00:07:06,600 --> 00:07:08,460
I accidentally left that cluster.
104
00:07:08,730 --> 00:07:09,580
But now there we go.
105
00:07:09,590 --> 00:07:11,340
So you can see that that is working.
106
00:07:11,580 --> 00:07:14,280
And let's just look at actually how much lines of code we save.
107
00:07:14,320 --> 00:07:20,190
So we were at 2a1, and now we're at 129.
108
00:07:20,550 --> 00:07:26,430
That's because now we extracted a lot of these h html as well as the assets into their own file, which
109
00:07:26,430 --> 00:07:30,540
is going to make our code significantly more reusable.
10675
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.