Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,620 --> 00:00:01,453
So I'm going
2
00:00:01,453 --> 00:00:04,059
to remove my comments here
3
00:00:04,059 --> 00:00:05,450
so that we again
4
00:00:05,450 --> 00:00:07,140
show it all the time
5
00:00:07,140 --> 00:00:09,410
and in the Modal JS file,
6
00:00:09,410 --> 00:00:10,930
I got an on click listener
7
00:00:10,930 --> 00:00:12,100
on the dismiss button
8
00:00:12,100 --> 00:00:14,860
where I admitted this closed event.
9
00:00:14,860 --> 00:00:15,780
Now let's say,
10
00:00:15,780 --> 00:00:17,150
I want to control
11
00:00:17,150 --> 00:00:19,366
whether the model is displayed or not
12
00:00:19,366 --> 00:00:23,420
inside this modal JavaScript file for now
13
00:00:23,420 --> 00:00:26,600
by simply showing or hiding the modal.
14
00:00:26,600 --> 00:00:27,440
Now that is of course,
15
00:00:27,440 --> 00:00:29,050
something we can do
16
00:00:29,050 --> 00:00:30,570
and we can easily do this
17
00:00:30,570 --> 00:00:32,670
by going into the modal CSS file
18
00:00:32,670 --> 00:00:34,850
where we define a style for this.
19
00:00:34,850 --> 00:00:35,750
I'm by the way
20
00:00:35,750 --> 00:00:37,900
not using CSS modules here
21
00:00:37,900 --> 00:00:39,710
but still this is the only file
22
00:00:39,710 --> 00:00:42,650
I used as modal CSS class.
23
00:00:42,650 --> 00:00:44,680
So there we could control
24
00:00:44,680 --> 00:00:46,820
whether it is modal as visible or not
25
00:00:46,820 --> 00:00:50,540
by adding a modal open class
26
00:00:50,540 --> 00:00:52,180
to it when it should be shown
27
00:00:52,180 --> 00:00:54,390
and a modal closed class
28
00:00:54,390 --> 00:00:56,300
when it should not be shown
29
00:00:56,300 --> 00:00:57,340
and then of course,
30
00:00:57,340 --> 00:00:59,050
one trivial way of
31
00:00:59,050 --> 00:01:01,860
sure controlling this is to set display
32
00:01:01,860 --> 00:01:05,180
to block when we have modal open
33
00:01:05,180 --> 00:01:08,610
and display to none,
34
00:01:08,610 --> 00:01:11,120
if it is should be closed
35
00:01:11,120 --> 00:01:12,650
and we should do the same
36
00:01:12,650 --> 00:01:14,030
for the backdrop.
37
00:01:14,030 --> 00:01:16,130
So when you backdrop CSS file,
38
00:01:16,130 --> 00:01:17,356
I'm also going to add
39
00:01:17,356 --> 00:01:22,356
backdrop open and backdrop closed.
40
00:01:23,000 --> 00:01:23,833
Now with div,
41
00:01:23,833 --> 00:01:25,310
we just have to add some codes
42
00:01:25,310 --> 00:01:26,860
to both files to make sure
43
00:01:26,860 --> 00:01:28,830
we actually take advantage of that.
44
00:01:28,830 --> 00:01:29,740
So, first of all
45
00:01:29,740 --> 00:01:31,730
I'm going to refactor this
46
00:01:31,730 --> 00:01:33,530
backdrop component function,
47
00:01:33,530 --> 00:01:34,670
you're into a function
48
00:01:34,670 --> 00:01:36,620
with curly braces where I then
49
00:01:36,620 --> 00:01:38,380
will return to JSX eventually
50
00:01:38,380 --> 00:01:39,890
but before I do so
51
00:01:39,890 --> 00:01:41,064
and that's the reason why
52
00:01:41,064 --> 00:01:43,820
I converted this, I want to create
53
00:01:43,820 --> 00:01:46,940
my classes array basically.
54
00:01:46,940 --> 00:01:48,370
So my CSS classes,
55
00:01:48,370 --> 00:01:49,660
I want to attach here
56
00:01:49,660 --> 00:01:50,750
should be an array.
57
00:01:50,750 --> 00:01:52,580
It should always be backdrop
58
00:01:52,580 --> 00:01:53,413
but then it should be
59
00:01:53,413 --> 00:01:55,770
backdrop open or closed
60
00:01:55,770 --> 00:01:58,290
depending on some prop I receive.
61
00:01:58,290 --> 00:01:59,170
So let's say I check
62
00:01:59,170 --> 00:02:01,570
if props show is true
63
00:02:01,570 --> 00:02:02,920
and only if that is true,
64
00:02:02,920 --> 00:02:05,770
I want to add backdrop open
65
00:02:05,770 --> 00:02:09,630
otherwise I'd add backdrop closed.
66
00:02:09,630 --> 00:02:11,730
Now, finally what I need to do is
67
00:02:11,730 --> 00:02:15,090
I need to attach this class here
68
00:02:15,090 --> 00:02:18,610
so the CSS class is constant
69
00:02:18,610 --> 00:02:19,870
and call join
70
00:02:19,870 --> 00:02:21,673
to join us into a string.
71
00:02:22,510 --> 00:02:24,040
Now with that we can control
72
00:02:24,040 --> 00:02:26,040
the displayer of the backdrop
73
00:02:26,040 --> 00:02:27,019
I'm going to copy that code
74
00:02:27,019 --> 00:02:29,197
into my modal JS file
75
00:02:29,197 --> 00:02:33,000
add there to all refactored is
76
00:02:33,000 --> 00:02:35,350
to take advantage of the fact
77
00:02:35,350 --> 00:02:36,760
that we do have a function
78
00:02:36,760 --> 00:02:38,900
where we don't just return something
79
00:02:38,900 --> 00:02:40,810
but we will return something
80
00:02:40,810 --> 00:02:42,130
before we do so,
81
00:02:42,130 --> 00:02:43,270
I also want to control
82
00:02:43,270 --> 00:02:45,250
my CSS classes here.
83
00:02:45,250 --> 00:02:46,110
So let's make sure
84
00:02:46,110 --> 00:02:48,690
we return the JSX code here too
85
00:02:48,690 --> 00:02:51,110
but then as I just said
86
00:02:51,110 --> 00:02:52,580
we should have CSS classes
87
00:02:52,580 --> 00:02:53,780
where we have modal
88
00:02:53,780 --> 00:02:54,613
and then we have
89
00:02:54,613 --> 00:02:58,190
modal open or modal closed
90
00:02:58,190 --> 00:02:59,814
and I actually used that
91
00:02:59,814 --> 00:03:03,550
as my CSS class name here,
92
00:03:03,550 --> 00:03:06,000
again joining it into one string
93
00:03:06,000 --> 00:03:08,250
with that join method.
94
00:03:08,250 --> 00:03:09,510
Now with that we just need
95
00:03:09,510 --> 00:03:10,930
to pass the show prop
96
00:03:10,930 --> 00:03:12,670
to backdrop and modal.
97
00:03:12,670 --> 00:03:13,503
We can do that
98
00:03:13,503 --> 00:03:15,150
in the app JS file.
99
00:03:15,150 --> 00:03:17,110
There we have a class based component.
100
00:03:17,110 --> 00:03:18,630
Let's now add a state
101
00:03:18,630 --> 00:03:21,260
where we add modal is open
102
00:03:21,260 --> 00:03:22,650
and set this to false.
103
00:03:22,650 --> 00:03:24,350
So let's say at the beginning
104
00:03:24,350 --> 00:03:26,650
and then I will simply
105
00:03:26,650 --> 00:03:28,370
change this state.
106
00:03:28,370 --> 00:03:29,240
So in this class,
107
00:03:29,240 --> 00:03:31,500
I'll add show modal.
108
00:03:31,500 --> 00:03:33,710
That should be a function
109
00:03:33,710 --> 00:03:36,140
where I simply call this set state
110
00:03:36,140 --> 00:03:40,220
and set modal is, open to true
111
00:03:40,220 --> 00:03:41,660
and then I will have
112
00:03:41,660 --> 00:03:43,970
a close modal function
113
00:03:43,970 --> 00:03:44,803
and that of course
114
00:03:44,803 --> 00:03:46,940
is all pretty much straight forward.
115
00:03:46,940 --> 00:03:49,990
Nothing new in the closed modal function
116
00:03:49,990 --> 00:03:52,370
I will set modal is open to false,
117
00:03:52,370 --> 00:03:53,820
just like that.
118
00:03:53,820 --> 00:03:55,410
Show modal and close modal.
119
00:03:55,410 --> 00:03:58,113
Now in the modal component, again
120
00:03:58,113 --> 00:04:01,170
I do call this closed prop
121
00:04:01,170 --> 00:04:03,190
on a click on the dismiss button.
122
00:04:03,190 --> 00:04:05,290
So that is the close prop
123
00:04:05,290 --> 00:04:06,540
is what I should bind
124
00:04:06,540 --> 00:04:08,832
to my close modal method here.
125
00:04:08,832 --> 00:04:11,830
So closed will be equal
126
00:04:11,830 --> 00:04:14,600
to this close modal
127
00:04:14,600 --> 00:04:16,459
and the backdrop and modal,
128
00:04:16,459 --> 00:04:19,300
now both need to receive the show prop
129
00:04:19,300 --> 00:04:20,132
that should be
130
00:04:20,132 --> 00:04:22,560
this state modal is open
131
00:04:22,560 --> 00:04:23,830
because that will determine
132
00:04:23,830 --> 00:04:24,820
whether we want to show
133
00:04:24,820 --> 00:04:26,300
or hide the modal.
134
00:04:26,300 --> 00:04:27,690
Finally, we need a way
135
00:04:27,690 --> 00:04:29,500
to show the modal and we've got this
136
00:04:29,500 --> 00:04:30,810
open modal button here.
137
00:04:30,810 --> 00:04:32,060
Now, all we have to do is
138
00:04:32,060 --> 00:04:34,380
hookup the on click listener there
139
00:04:34,380 --> 00:04:37,760
to this show modal
140
00:04:37,760 --> 00:04:39,620
and now with all these things,
141
00:04:39,620 --> 00:04:41,290
if we save this
142
00:04:41,290 --> 00:04:42,870
we go back to the application.
143
00:04:42,870 --> 00:04:43,940
I click open modal
144
00:04:43,940 --> 00:04:44,970
we see the modal.
145
00:04:44,970 --> 00:04:47,350
I click dismiss, we dismiss it.
146
00:04:47,350 --> 00:04:48,340
Now that's all nice
147
00:04:48,340 --> 00:04:50,020
but we have no animation.
148
00:04:50,020 --> 00:04:51,270
So again, finally,
149
00:04:51,270 --> 00:04:52,890
let's work on this animation
150
00:04:52,890 --> 00:04:54,223
in the next lecture.
9659
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.