Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,120 --> 00:00:03,610
So what's next?
2
00:00:03,610 --> 00:00:06,300
Of course, this is generally up to you,
3
00:00:06,300 --> 00:00:09,100
but here I want to continue with the meals
4
00:00:09,100 --> 00:00:11,550
because, of course, that is a rather important part
5
00:00:11,550 --> 00:00:13,440
of this application.
6
00:00:13,440 --> 00:00:18,440
And for that, in the meals folder, I'll add a Meals.js file
7
00:00:19,550 --> 00:00:22,060
and this will be responsible for, in the end,
8
00:00:22,060 --> 00:00:25,470
rendering that meals list, though,
9
00:00:25,470 --> 00:00:28,210
actually not just a list of meals,
10
00:00:28,210 --> 00:00:31,923
but also this little summary text above it.
11
00:00:33,010 --> 00:00:36,780
And therefore, I will actually add two other components here
12
00:00:36,780 --> 00:00:40,280
which split these responsibilities.
13
00:00:40,280 --> 00:00:44,070
I will add a MealsSummary.js file
14
00:00:44,070 --> 00:00:48,590
which will render this text above the list of meals.
15
00:00:48,590 --> 00:00:53,590
And I'll render an available meals component,
16
00:00:54,060 --> 00:00:55,860
which will then be responsible
17
00:00:55,860 --> 00:00:59,263
for bringing the actual list of meals to the screen.
18
00:01:00,670 --> 00:01:04,069
Now let's maybe start with the meals summary component.
19
00:01:04,069 --> 00:01:07,283
For that, you attached find a CSS file,
20
00:01:07,283 --> 00:01:10,053
MealsSummary.module.css,
21
00:01:10,900 --> 00:01:15,780
and in the meals summary component file, in the JS file,
22
00:01:15,780 --> 00:01:19,460
as always, we just export a component.
23
00:01:19,460 --> 00:01:21,880
Now this will be a very simple component
24
00:01:21,880 --> 00:01:25,990
because it will just contain some hard-coded JSX code.
25
00:01:25,990 --> 00:01:29,790
It doesn't even need to accept the props parameter
26
00:01:29,790 --> 00:01:33,543
because we will not be using props here at any time.
27
00:01:34,540 --> 00:01:38,600
And here, I just want to return a section, let's say,
28
00:01:38,600 --> 00:01:40,220
where we have a H2 tag
29
00:01:40,220 --> 00:01:45,220
where we say, "Delicious food, delivered to you,"
30
00:01:47,270 --> 00:01:49,310
And then a couple of paragraph texts
31
00:01:49,310 --> 00:01:51,960
with some text below it.
32
00:01:51,960 --> 00:01:54,750
Now to save you the extra typing,
33
00:01:54,750 --> 00:01:59,453
attached you find that MealsSummary.js file finished.
34
00:02:00,330 --> 00:02:03,240
And there you got these paragraphs already added
35
00:02:03,240 --> 00:02:05,540
and you also got a class name edit,
36
00:02:05,540 --> 00:02:07,809
and they are for here.
37
00:02:07,809 --> 00:02:09,020
I need to add to the import again;
38
00:02:09,020 --> 00:02:11,830
you already have that in the attached file
39
00:02:11,830 --> 00:02:16,830
where I import MealsSummary.module.css like this
40
00:02:18,240 --> 00:02:22,913
and then add this summary class here like this.
41
00:02:26,910 --> 00:02:28,130
Now again, you'll find
42
00:02:28,130 --> 00:02:31,200
this finished meal summary JS file attached
43
00:02:31,200 --> 00:02:33,113
because it is a very simple file.
44
00:02:34,770 --> 00:02:39,640
More interesting, of course, is the available meals file.
45
00:02:39,640 --> 00:02:44,480
Here we can have the available meals function.
46
00:02:44,480 --> 00:02:46,950
We also don't need props here, actually,
47
00:02:46,950 --> 00:02:49,970
because I won't receive any props here.
48
00:02:49,970 --> 00:02:52,500
Instead here, in this application,
49
00:02:52,500 --> 00:02:56,330
we will work with some dummy meals data
50
00:02:56,330 --> 00:02:59,000
which is baked into this component.
51
00:02:59,000 --> 00:03:01,250
That's of course a bit unrealistic,
52
00:03:01,250 --> 00:03:03,890
but we will later in the course learn
53
00:03:03,890 --> 00:03:06,530
how we could fetch data from a database.
54
00:03:06,530 --> 00:03:08,380
At the moment we don't know it yet,
55
00:03:08,380 --> 00:03:11,423
and therefore we will work with such dummy data.
56
00:03:12,310 --> 00:03:15,470
Speaking off that, attached you'll find
57
00:03:15,470 --> 00:03:18,900
the Dummy Meals JS file.
58
00:03:18,900 --> 00:03:21,970
And that includes a simple constant,
59
00:03:21,970 --> 00:03:24,530
which you should add in this file
60
00:03:24,530 --> 00:03:28,190
above the available meals component function,
61
00:03:28,190 --> 00:03:31,020
which is this DUMMY_MEALS constant
62
00:03:31,020 --> 00:03:33,500
which holds an array of dummy meals.
63
00:03:33,500 --> 00:03:36,530
Again, that is that dummy data we're going to work with
64
00:03:36,530 --> 00:03:38,423
in this demo application.
65
00:03:40,610 --> 00:03:44,740
Now, with that added here in the available meals component,
66
00:03:44,740 --> 00:03:48,720
we want to render this array of meals,
67
00:03:48,720 --> 00:03:50,550
which we of course could have fetched
68
00:03:50,550 --> 00:03:52,740
from some database or anything like that.
69
00:03:52,740 --> 00:03:56,063
In reality, we want our render this as JSX,
70
00:03:57,410 --> 00:04:01,240
and therefore, we will need to transform this regular array
71
00:04:01,240 --> 00:04:05,750
of JavaScript objects to an array of JSX elements.
72
00:04:05,750 --> 00:04:07,210
And that is something you of course
73
00:04:07,210 --> 00:04:08,590
learn throughout the course,
74
00:04:08,590 --> 00:04:12,310
that that is something you can do easily with React.
75
00:04:12,310 --> 00:04:14,810
So here we want to return some JSX code,
76
00:04:14,810 --> 00:04:17,610
let's say with a section inside of it.
77
00:04:17,610 --> 00:04:20,149
And then inside of this section,
78
00:04:20,149 --> 00:04:22,420
I want to have an unordered list.
79
00:04:22,420 --> 00:04:23,980
And inside of this unordered list,
80
00:04:23,980 --> 00:04:27,630
I want to have my meals list, and therefore,
81
00:04:27,630 --> 00:04:31,920
we can add curly braces and then refer to dummy meals
82
00:04:31,920 --> 00:04:35,363
and map them into an array of JSX elements.
83
00:04:36,630 --> 00:04:38,130
Now we can do this here,
84
00:04:38,130 --> 00:04:42,110
and we did is here in the JSX code in the past,
85
00:04:42,110 --> 00:04:44,590
but to keep this return statement lean,
86
00:04:44,590 --> 00:04:47,550
I will actually create a helper constant here,
87
00:04:47,550 --> 00:04:49,440
which I'll name mealsList,
88
00:04:49,440 --> 00:04:53,850
which simply stores that mapped dummy meals list here
89
00:04:53,850 --> 00:04:56,403
so that down there, I just output meals list.
90
00:04:57,370 --> 00:04:58,920
That's exactly the same
91
00:04:58,920 --> 00:05:00,800
as if I would be doing it down there.
92
00:05:00,800 --> 00:05:04,520
It just ensures that this JSX snippet is a bit leaner.
93
00:05:04,520 --> 00:05:05,640
And it's totally up to you
94
00:05:05,640 --> 00:05:08,510
if you want to do this transformation here
95
00:05:08,510 --> 00:05:11,570
and store it in a constant which you use down there,
96
00:05:11,570 --> 00:05:16,570
or if you do the transformation in line in your JSX block.
97
00:05:16,690 --> 00:05:20,940
Either way, we will simply map all these meals
98
00:05:20,940 --> 00:05:23,010
by passing a function to map,
99
00:05:23,010 --> 00:05:26,690
which is executed for every meal by JavaScript.
100
00:05:26,690 --> 00:05:30,920
And then for every meal, we want to return a JSX element
101
00:05:30,920 --> 00:05:33,170
which represents this meal item.
102
00:05:33,170 --> 00:05:36,040
And that should be some list item, of course,
103
00:05:36,040 --> 00:05:39,250
though I can already say, for the moment,
104
00:05:39,250 --> 00:05:42,600
we can simply output meal.name here like this,
105
00:05:42,600 --> 00:05:44,770
but that's just temporary.
106
00:05:44,770 --> 00:05:48,300
We will soon create a separate component for the meal item,
107
00:05:48,300 --> 00:05:50,580
but for the moment we can leave it like this
108
00:05:50,580 --> 00:05:55,570
and finish this first draft of the available meals component
109
00:05:55,570 --> 00:05:57,023
by adding some styling.
110
00:05:57,910 --> 00:05:59,790
Now for this, again, attached you'll find
111
00:05:59,790 --> 00:06:03,290
the availablemeals.module.css file
112
00:06:03,290 --> 00:06:05,573
with some predefined CSS code,
113
00:06:06,710 --> 00:06:10,730
and in the availablemeals.js file at the very top,
114
00:06:10,730 --> 00:06:13,850
you simply import classes
115
00:06:13,850 --> 00:06:17,633
from availablemeals.module.css.
116
00:06:20,540 --> 00:06:22,920
And then on this section,
117
00:06:22,920 --> 00:06:26,593
we can add a class name of classes.meals.
118
00:06:28,370 --> 00:06:31,920
And now with that, we can go back to the meals component,
119
00:06:31,920 --> 00:06:34,910
which should now group the meals summary
120
00:06:34,910 --> 00:06:37,460
and available meals together.
121
00:06:37,460 --> 00:06:40,300
So here, the meals component will, again,
122
00:06:40,300 --> 00:06:42,110
also be very simple.
123
00:06:42,110 --> 00:06:44,453
It won't need any props either.
124
00:06:45,460 --> 00:06:48,720
Here we just want to import the two other components.
125
00:06:48,720 --> 00:06:53,720
So the meals summary from meals summary, like this,
126
00:06:55,710 --> 00:07:00,710
and import available meals from available meals, like this,
127
00:07:03,450 --> 00:07:06,020
and then return both side by side.
128
00:07:06,020 --> 00:07:09,100
And since I want to return two elements side by side,
129
00:07:09,100 --> 00:07:12,160
you know that this is not possible in JSX.
130
00:07:12,160 --> 00:07:15,300
We must only have one root JSX element,
131
00:07:15,300 --> 00:07:18,550
and therefore again, I will use the fragment.
132
00:07:18,550 --> 00:07:23,550
So we should import fragment from React
133
00:07:23,920 --> 00:07:28,360
as a wrapper component around meals summary,
134
00:07:28,360 --> 00:07:32,270
as a self-closing component and available meals
135
00:07:32,270 --> 00:07:33,963
as a self-closing component.
136
00:07:36,330 --> 00:07:40,810
And now with that, we can go to the app, JS file,
137
00:07:40,810 --> 00:07:45,710
and here below the header, I will add a main HTML element,
138
00:07:45,710 --> 00:07:49,840
which is a default built-in HTML5 element.
139
00:07:49,840 --> 00:07:54,330
And inside of that main element, I will add my meals.
140
00:07:54,330 --> 00:07:59,330
So I will import meals from components/Meals/Meals,
141
00:08:00,830 --> 00:08:04,050
import into Meals JavaScript file in the meals folder
142
00:08:05,410 --> 00:08:07,010
and then simply render this here
143
00:08:07,010 --> 00:08:08,773
as a self-closing component.
144
00:08:10,230 --> 00:08:14,490
And if you save that, you should see something like this.
145
00:08:14,490 --> 00:08:16,680
Now the summary already looks good.
146
00:08:16,680 --> 00:08:18,970
Of course, the list of meals doesn't,
147
00:08:18,970 --> 00:08:22,600
but here we're also just getting started.
148
00:08:22,600 --> 00:08:27,380
Now as a next step, I want to wrap this entire list here,
149
00:08:27,380 --> 00:08:31,090
this unordered list, into a card component.
150
00:08:31,090 --> 00:08:33,960
So into a container with rounded corners
151
00:08:33,960 --> 00:08:36,240
and a white background and so on,
152
00:08:36,240 --> 00:08:38,190
and every list item itself
153
00:08:38,190 --> 00:08:40,490
should also become a separate component,
154
00:08:40,490 --> 00:08:45,050
which also outputs more data and in a nicer way.
155
00:08:45,050 --> 00:08:47,350
Now that's what we're going to do in the next lecture.
156
00:08:47,350 --> 00:08:52,350
Of course, as always, feel free to not proceed right away
157
00:08:52,490 --> 00:08:54,510
but try this on your own first.
158
00:08:54,510 --> 00:08:56,130
Even if it then looks different
159
00:08:56,130 --> 00:08:58,710
than what we're going to build in the next lecture,
160
00:08:58,710 --> 00:09:02,060
this is a great practice you can, and you maybe should,
161
00:09:02,060 --> 00:09:05,993
do before you proceed and we do it together next.
12950
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.