Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,050 --> 00:00:06,090
Now my goal here is to add a filter area
2
00:00:06,090 --> 00:00:08,240
on this AllEvents page
3
00:00:08,240 --> 00:00:10,290
above that list of events,
4
00:00:10,290 --> 00:00:14,880
where we can select a year and a month in dropdown menus.
5
00:00:14,880 --> 00:00:16,840
And when we selected a combination
6
00:00:16,840 --> 00:00:18,920
and clicked on find events,
7
00:00:18,920 --> 00:00:23,650
we change the URL and we go to this filter URL
8
00:00:23,650 --> 00:00:25,640
to this Slack page here.
9
00:00:25,640 --> 00:00:29,160
And on that page, we then read the filter values
10
00:00:29,160 --> 00:00:33,890
from the URL to pick the correct events.
11
00:00:33,890 --> 00:00:34,970
Sounds cryptic?
12
00:00:34,970 --> 00:00:37,493
Well, let's implement it together step-by-step.
13
00:00:38,829 --> 00:00:40,779
And the first step for that
14
00:00:40,779 --> 00:00:44,130
is to add a little filter box, a search box
15
00:00:44,130 --> 00:00:49,130
above that list of events on the AllEvents page.
16
00:00:49,130 --> 00:00:51,120
Now, for this, I'll add a new component
17
00:00:51,120 --> 00:00:52,780
in this events folder
18
00:00:52,780 --> 00:00:56,037
and I'll name it, events-search.js.
19
00:00:56,037 --> 00:00:58,850
Now this will hold functional component,
20
00:00:58,850 --> 00:01:02,318
the EventsSearch component,
21
00:01:02,318 --> 00:01:05,930
which receives props and which we, as always,
22
00:01:05,930 --> 00:01:07,453
export, of course.
23
00:01:08,950 --> 00:01:09,783
Like this.
24
00:01:10,667 --> 00:01:12,980
And then in here, we'll have a couple of things
25
00:01:12,980 --> 00:01:14,530
which we need to do.
26
00:01:14,530 --> 00:01:17,060
First of all, I'll start with the JSX code
27
00:01:17,060 --> 00:01:18,580
that should be returned.
28
00:01:18,580 --> 00:01:21,160
Here I wanna return a form
29
00:01:21,160 --> 00:01:23,180
because we'll have a couple of inputs
30
00:01:23,180 --> 00:01:26,250
and those inputs can take different values
31
00:01:26,250 --> 00:01:28,470
and ultimately they are submitted.
32
00:01:28,470 --> 00:01:30,440
So we have a form.
33
00:01:30,440 --> 00:01:34,730
And in that form, I have a div with another div inside
34
00:01:34,730 --> 00:01:38,010
with a label inside where I say year.
35
00:01:38,010 --> 00:01:42,070
And this label will then be for a select element,
36
00:01:42,070 --> 00:01:46,230
so for a dropdown which allows us to select a year.
37
00:01:46,230 --> 00:01:50,190
Therefore I'll give this label the htmlFor attribute
38
00:01:50,190 --> 00:01:51,910
and set this to year
39
00:01:51,910 --> 00:01:55,060
and give this the id attribute and set it to year
40
00:01:55,060 --> 00:01:59,270
so that we have this connection for accessibility reasons.
41
00:01:59,270 --> 00:02:01,290
Now, in this select input here,
42
00:02:01,290 --> 00:02:06,290
for the year I wanna present two options, 2021 and 2022.
43
00:02:06,870 --> 00:02:08,800
Of course you can pick any years here,
44
00:02:08,800 --> 00:02:12,310
though I picked these years because I have dummy data
45
00:02:12,310 --> 00:02:15,903
for those years here in my dummy data array.
46
00:02:17,910 --> 00:02:21,190
So these are my two options.
47
00:02:21,190 --> 00:02:25,070
I'll then give these options a value key each
48
00:02:25,070 --> 00:02:27,180
which is the internal identifier,
49
00:02:27,180 --> 00:02:28,803
which I'll get access to later.
50
00:02:29,741 --> 00:02:32,400
And I'll set this to 21 and 22 as well.
51
00:02:35,540 --> 00:02:36,950
Like this.
52
00:02:36,950 --> 00:02:39,760
So that's now the first dropdown.
53
00:02:39,760 --> 00:02:43,130
Now next to this div, so to this div here
54
00:02:43,130 --> 00:02:45,310
which holds that first dropdown,
55
00:02:45,310 --> 00:02:49,650
I'll add another div with a second dropdown for the month.
56
00:02:49,650 --> 00:02:52,680
So here we'll have a label for the month.
57
00:02:52,680 --> 00:02:57,100
and hence I'll set the htmlFor attribute to month.
58
00:02:57,100 --> 00:02:58,978
And then below that,
59
00:02:58,978 --> 00:03:02,520
I'll add another select element.
60
00:03:02,520 --> 00:03:05,060
And looks like I accidentally deleted a div here,
61
00:03:05,060 --> 00:03:07,040
so let me re-add it.
62
00:03:07,040 --> 00:03:09,770
So then here I have another dropdown
63
00:03:09,770 --> 00:03:13,713
and this will get an id of month, like this.
64
00:03:14,670 --> 00:03:17,500
And then we need to add the options.
65
00:03:17,500 --> 00:03:20,893
And here we'll have 12 options because we have 12 months.
66
00:03:21,947 --> 00:03:23,840
So I'll start with January
67
00:03:23,840 --> 00:03:27,350
and set the internal value here to one,
68
00:03:27,350 --> 00:03:29,750
and then replicate this a couple of times
69
00:03:30,776 --> 00:03:33,803
so that here, we also have February.
70
00:03:36,430 --> 00:03:38,424
And set this to two.
71
00:03:38,424 --> 00:03:41,090
Here we have three and March and, well,
72
00:03:41,090 --> 00:03:43,690
you can probably guess what comes through after.
73
00:03:43,690 --> 00:03:47,070
April and May and four and five
74
00:03:47,070 --> 00:03:50,600
and then six and June and so on.
75
00:03:50,600 --> 00:03:55,083
So I'll quickly complete this list here, July.
76
00:03:56,250 --> 00:03:59,947
And then also here we have August.
77
00:04:01,660 --> 00:04:04,563
And then we also need September.
78
00:04:06,879 --> 00:04:11,060
And October and November.
79
00:04:11,060 --> 00:04:15,111
And December, and then also update those numbers
80
00:04:15,111 --> 00:04:19,750
so that here we have nine and 10 and 11.
81
00:04:19,750 --> 00:04:23,970
Oops, 11 and 12.
82
00:04:23,970 --> 00:04:27,173
So now these are the options for the second dropdown here.
83
00:04:28,826 --> 00:04:30,200
And now below that, below all the divs,
84
00:04:30,200 --> 00:04:33,683
but inside of the form, I'll then also add my Button again.
85
00:04:34,869 --> 00:04:36,380
So my Button component and therefor, of course,
86
00:04:36,380 --> 00:04:38,730
we need to import that at the top.
87
00:04:38,730 --> 00:04:42,540
We want to import Button from, going up one level,
88
00:04:42,540 --> 00:04:45,653
diving into ui, and then the Button file.
89
00:04:47,590 --> 00:04:50,860
So that here, we then have this button component
90
00:04:50,860 --> 00:04:54,423
and on the button, we can say Find Events.
91
00:04:55,300 --> 00:04:58,430
However, this button here shouldn't be a link.
92
00:04:58,430 --> 00:05:01,140
It should be a real button, which submits the form
93
00:05:01,140 --> 00:05:03,080
of which it is part.
94
00:05:03,080 --> 00:05:07,070
And hence, we need to go back into this button component
95
00:05:07,070 --> 00:05:10,520
in the ui folder and tweak it a little bit
96
00:05:10,520 --> 00:05:14,860
because this button component should either render a link,
97
00:05:14,860 --> 00:05:18,160
as it currently does, or a normal button.
98
00:05:18,160 --> 00:05:21,630
And it should render a link if the link prop is set.
99
00:05:21,630 --> 00:05:24,683
If it is not set, it should render a normal button.
100
00:05:25,620 --> 00:05:30,620
So here I will simply check if props link is truthy.
101
00:05:31,320 --> 00:05:33,200
So if that is set.
102
00:05:33,200 --> 00:05:37,740
And if it is I'll return my link as I did before.
103
00:05:37,740 --> 00:05:40,410
Otherwise, if we make it past this if check,
104
00:05:40,410 --> 00:05:44,150
we don't have a link and then I'll return a regular button,
105
00:05:44,150 --> 00:05:46,980
a button where we output props.children.
106
00:05:46,980 --> 00:05:49,610
So where we still pass on the content
107
00:05:49,610 --> 00:05:51,510
passed between the text.
108
00:05:51,510 --> 00:05:56,510
And where we then set the onClick prop to props.onClick.
109
00:05:56,909 --> 00:06:00,133
So that can use our own button just as the built in button.
110
00:06:01,270 --> 00:06:03,640
I also want to add a class name here and set this
111
00:06:03,640 --> 00:06:05,830
to classes.btn as well.
112
00:06:05,830 --> 00:06:08,913
So that'd we still applied those CSS classes.
113
00:06:10,500 --> 00:06:13,820
With that we can go back to the event search component.
114
00:06:13,820 --> 00:06:18,210
And here we are now therefor done with this JSX code.
115
00:06:18,210 --> 00:06:20,750
Again, some styling would be nice and therefor,
116
00:06:20,750 --> 00:06:23,540
just as before, attached, you find some styles
117
00:06:23,540 --> 00:06:25,230
for this component.
118
00:06:25,230 --> 00:06:30,130
So attached you will find an events-search.module.css file
119
00:06:30,130 --> 00:06:33,990
which you should add next to the events-search JS file.
120
00:06:33,990 --> 00:06:37,497
And then here we import classes from
121
00:06:37,497 --> 00:06:41,667
./events-search.module.css
122
00:06:41,667 --> 00:06:46,630
and then add a couple of class names to this JSX code.
123
00:06:46,630 --> 00:06:48,930
To the form, for example, we add classes.form.
124
00:06:50,320 --> 00:06:54,960
To this first div we then add classes.controls.
125
00:06:54,960 --> 00:06:57,900
And those divs only exist for the styling.
126
00:06:57,900 --> 00:07:00,343
That's why I have these nested divs.
127
00:07:01,350 --> 00:07:04,890
Then here I'll have another div with a class of control.
128
00:07:04,890 --> 00:07:09,610
So the outer div has controls, the inner div has control.
129
00:07:09,610 --> 00:07:13,620
And we don't need to add anything to the label ends on,
130
00:07:13,620 --> 00:07:16,043
but this div here which holds the month,
131
00:07:16,979 --> 00:07:20,940
also receives classes.control like this.
132
00:07:20,940 --> 00:07:23,611
And, with that we're done though.
133
00:07:23,611 --> 00:07:26,450
That adds all the styling that needs to be added.
134
00:07:26,450 --> 00:07:27,630
At the moment, of course,
135
00:07:27,630 --> 00:07:29,980
this component is missing any logic,
136
00:07:29,980 --> 00:07:34,080
but it at least has the JSX code and the styling.
137
00:07:34,080 --> 00:07:37,910
So we can already include it in this index.js file
138
00:07:37,910 --> 00:07:40,490
in the events folder, in the pages folder.
139
00:07:40,490 --> 00:07:43,480
So on this AllEvents page.
140
00:07:43,480 --> 00:07:48,480
Here, we can import EventsSearch from, going up, going up,
141
00:07:48,690 --> 00:07:53,690
components, events, and then the events-search.
142
00:07:54,210 --> 00:07:56,410
And now above the event list here,
143
00:07:56,410 --> 00:07:59,410
I'll add EventsSearch like this.
144
00:07:59,410 --> 00:08:02,360
We can now also replace this div, by the way,
145
00:08:02,360 --> 00:08:06,350
with a fragment if we want to import it from react.
146
00:08:06,350 --> 00:08:08,510
That's not mandatory but I'll do it here
147
00:08:08,510 --> 00:08:11,960
because we don't really need that extra div.
148
00:08:11,960 --> 00:08:14,397
Now, if we save all files
149
00:08:14,397 --> 00:08:18,940
we should have this filter area, or this search area
150
00:08:18,940 --> 00:08:20,603
above our events.
151
00:08:21,460 --> 00:08:23,793
Now it's therefor time to add some logic.
11934
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.