Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,309 --> 00:00:04,230
So let's now start wiring up
2
00:00:04,230 --> 00:00:05,063
our PostItem
3
00:00:05,063 --> 00:00:08,740
to the PostsGrid, and let's add some dummy data.
4
00:00:08,740 --> 00:00:11,960
To wire it up, keep in mind that in the PostsGrid
5
00:00:11,960 --> 00:00:14,290
we get posts through props,
6
00:00:14,290 --> 00:00:17,580
and that will probably be an array full of objects
7
00:00:17,580 --> 00:00:19,630
that describe a post.
8
00:00:19,630 --> 00:00:23,470
So assumption is that a individual post and that list
9
00:00:23,470 --> 00:00:26,290
has all the data PostItem needs.
10
00:00:26,290 --> 00:00:27,640
We can make that assumption
11
00:00:27,640 --> 00:00:30,050
because we are writing that code.
12
00:00:30,050 --> 00:00:31,690
So we'll just have to make sure
13
00:00:31,690 --> 00:00:33,533
that this the case later.
14
00:00:34,500 --> 00:00:38,303
Now, PostItem, this component, once a PostProp,
15
00:00:39,180 --> 00:00:41,040
hence now in PostsGrid,
16
00:00:41,040 --> 00:00:43,080
we can add that PostProp here,
17
00:00:43,080 --> 00:00:47,900
and pass the post which we get here, in this map method
18
00:00:47,900 --> 00:00:50,713
into PostItem through that PostProp.
19
00:00:51,850 --> 00:00:55,300
Now we expose that data to PostsItem.
20
00:00:55,300 --> 00:00:58,700
Now, since we map, we should also add to key prop
21
00:00:58,700 --> 00:01:01,210
that's required by reactjs
22
00:01:01,210 --> 00:01:04,780
to efficiently render an update that list,
23
00:01:04,780 --> 00:01:07,990
and we can set this to some unique identifier,
24
00:01:07,990 --> 00:01:10,770
and every post will have a slug property
25
00:01:10,770 --> 00:01:13,800
which is the unique identifier of a given post,
26
00:01:13,800 --> 00:01:16,780
and therefore that is what we can use here.
27
00:01:16,780 --> 00:01:19,630
Now we got that, now we need some dummy data.
28
00:01:19,630 --> 00:01:22,930
For this, let's first of all, go to Featured Posts
29
00:01:22,930 --> 00:01:24,500
in the homepage folder,
30
00:01:24,500 --> 00:01:29,353
because that is where we now wanna use that PostsGrid.
31
00:01:30,420 --> 00:01:33,490
So in here we want to output PostsGrid,
32
00:01:33,490 --> 00:01:34,910
and for this you should make sure
33
00:01:34,910 --> 00:01:39,540
that you add the import two PostsGrid to that component.
34
00:01:39,540 --> 00:01:43,480
And now the there we need to set the PostProp
35
00:01:43,480 --> 00:01:44,713
on PostsGrid.
36
00:01:45,610 --> 00:01:49,210
We need to set that because in the PostsGrid component,
37
00:01:49,210 --> 00:01:52,393
we are extracting that PostProp here.
38
00:01:53,760 --> 00:01:56,880
So we wanna se this, and in Featured Posts,
39
00:01:56,880 --> 00:02:01,880
I actually also expect that I get my posts data from props.
40
00:02:02,390 --> 00:02:05,720
Now that's a long chain of props, and we could,
41
00:02:05,720 --> 00:02:08,080
therefore of course also kind of consider
42
00:02:08,080 --> 00:02:10,630
using context or redux
43
00:02:10,630 --> 00:02:12,849
to avoid this prop-drilling,
44
00:02:12,849 --> 00:02:15,410
but here I'm actually fine with it
45
00:02:15,410 --> 00:02:18,350
because it is a chain that makes a lot of sense,
46
00:02:18,350 --> 00:02:20,400
and a PostsGrid for example,
47
00:02:20,400 --> 00:02:24,220
shouldn't be tied to one specific context anyways,
48
00:02:24,220 --> 00:02:28,170
because we will reuse that component in different places,
49
00:02:28,170 --> 00:02:30,940
so that should definitely receive its data
50
00:02:30,940 --> 00:02:33,330
through props instead of context,
51
00:02:33,330 --> 00:02:35,880
and hence I'll leave it like this.
52
00:02:35,880 --> 00:02:37,650
Therefore, in Featured Post,
53
00:02:37,650 --> 00:02:41,210
I'll sets the PostProp on PostsGrid
54
00:02:41,210 --> 00:02:43,610
to prop dot posts.
55
00:02:43,610 --> 00:02:46,150
And yeah, that's a lot of posts,
56
00:02:46,150 --> 00:02:49,053
but that is what this application is about in the end.
57
00:02:50,110 --> 00:02:53,652
So now Featured Posts also has a PostProp
58
00:02:53,652 --> 00:02:55,880
that needs to be populated.
59
00:02:55,880 --> 00:02:58,710
And let's therefore now finally go to the place
60
00:02:58,710 --> 00:03:03,240
where the prop chain will end, and that is index.js file
61
00:03:03,240 --> 00:03:05,090
in the pages folder.
62
00:03:05,090 --> 00:03:09,621
Here below Hero, I wanna output my Featured Posts,
63
00:03:09,621 --> 00:03:11,700
and therefore you need to make sure
64
00:03:11,700 --> 00:03:14,156
that you do add that import
65
00:03:14,156 --> 00:03:17,350
to import the Featured Posts component.
66
00:03:17,350 --> 00:03:20,053
And here we now set our PostProp.
67
00:03:21,200 --> 00:03:22,650
Now later,
68
00:03:22,650 --> 00:03:26,334
we will get posts with get static props,
69
00:03:26,334 --> 00:03:30,320
when we have actual post which we load.
70
00:03:30,320 --> 00:03:32,030
For them moment we don't have that,
71
00:03:32,030 --> 00:03:34,520
for the moment to just see something,
72
00:03:34,520 --> 00:03:35,710
I'll add
73
00:03:35,710 --> 00:03:36,810
DUMMY
74
00:03:36,810 --> 00:03:39,210
POSTS array here,
75
00:03:39,210 --> 00:03:42,400
which I'll set as a value for the PostProp,
76
00:03:42,400 --> 00:03:45,280
and we'll then replace that later.
77
00:03:45,280 --> 00:03:47,140
Now, DUMMY POSTS will be an array
78
00:03:47,140 --> 00:03:52,140
full of DUMMY POSTS data, so full of DUMMY POSTS objects.
79
00:03:52,820 --> 00:03:55,280
And now every post object here,
80
00:03:55,280 --> 00:03:58,290
showed in the end half these properties
81
00:03:58,290 --> 00:04:01,360
because that's what we rely on later.
82
00:04:01,360 --> 00:04:05,563
We wanna have a title image, excerpt, date and slug,
83
00:04:07,020 --> 00:04:09,490
hence here in index JS we wanna add to that.
84
00:04:09,490 --> 00:04:14,073
We wanna add a slug, title, an image, an expert,
85
00:04:14,920 --> 00:04:17,120
and our date.
86
00:04:17,120 --> 00:04:20,040
So all those properties
87
00:04:20,040 --> 00:04:21,810
we are relying on
88
00:04:21,810 --> 00:04:23,183
here in PostItem,
89
00:04:24,040 --> 00:04:27,463
five prop there, five properties here.
90
00:04:28,320 --> 00:04:29,630
Now, since it's dummy data,
91
00:04:29,630 --> 00:04:32,920
we can come up with any slug and any values
92
00:04:32,920 --> 00:04:34,810
in general we want.
93
00:04:34,810 --> 00:04:37,380
The slug should be a text with the words
94
00:04:37,380 --> 00:04:40,870
separated by dashes and no special characters.
95
00:04:40,870 --> 00:04:43,350
So here I'll have like a slug of
96
00:04:43,350 --> 00:04:44,720
getting-started
97
00:04:46,040 --> 00:04:47,253
with nextjs,
98
00:04:48,250 --> 00:04:50,040
and then I'll add a title off,
99
00:04:50,040 --> 00:04:52,090
Getting Started
100
00:04:52,090 --> 00:04:54,000
with NextJS,
101
00:04:54,000 --> 00:04:56,930
so that could be a block post title,
102
00:04:56,930 --> 00:04:58,960
then a image,
103
00:04:58,960 --> 00:05:00,160
which I'll name,
104
00:05:00,160 --> 00:05:04,440
getting-started-nextjs, just like this,
105
00:05:04,440 --> 00:05:06,430
and then(indistinct) the dot png.
106
00:05:06,430 --> 00:05:09,240
I will soon provide this file to you,
107
00:05:09,240 --> 00:05:11,360
so it would be half this image.
108
00:05:11,360 --> 00:05:15,250
Then add an excerpt, where I say something like,
109
00:05:15,250 --> 00:05:17,450
NextJS is
110
00:05:17,450 --> 00:05:22,050
the React framework for production,
111
00:05:22,050 --> 00:05:27,030
it makes building fullstack React apps and sites
112
00:05:27,030 --> 00:05:27,863
a
113
00:05:27,863 --> 00:05:28,696
breeze
114
00:05:28,696 --> 00:05:31,778
and ships with built-in
115
00:05:31,778 --> 00:05:33,663
server-side rendering.
116
00:05:34,580 --> 00:05:36,520
Now you can come up with any texts you want,
117
00:05:36,520 --> 00:05:38,490
it just shouldn't be too long
118
00:05:38,490 --> 00:05:41,543
because it's just a short review text in the end.
119
00:05:42,580 --> 00:05:44,050
And then I'll add a date,
120
00:05:44,050 --> 00:05:46,370
which should be in the format of
121
00:05:46,370 --> 00:05:47,760
year dash,
122
00:05:47,760 --> 00:05:50,260
month dash day.
123
00:05:50,260 --> 00:05:54,360
That will be a date which then later can be parsed and used
124
00:05:54,360 --> 00:05:56,603
by the date constructor.
125
00:05:58,560 --> 00:06:00,060
So that's some dummy data,
126
00:06:00,060 --> 00:06:02,650
and I'll add more than one posts here.
127
00:06:02,650 --> 00:06:05,090
I'll repeat this four times,
128
00:06:05,090 --> 00:06:08,000
and I'll just add it to the slug slightly,
129
00:06:08,000 --> 00:06:12,580
so getting started with nextjs2, and three, and four,
130
00:06:12,580 --> 00:06:14,330
so that this is unique,
131
00:06:14,330 --> 00:06:17,612
and all the other data is duplicated for the moment
132
00:06:17,612 --> 00:06:20,040
just because I don't wanna waste time
133
00:06:20,040 --> 00:06:21,610
setting up dummy data here,
134
00:06:21,610 --> 00:06:25,900
we'll just need this to see of our grid works correctly.
135
00:06:25,900 --> 00:06:27,210
So that is what it is,
136
00:06:27,210 --> 00:06:29,170
that is the DUMMY POSTS I wanna work with,
137
00:06:29,170 --> 00:06:32,893
and that's the DUMMY POSTS parsed to Featured Posts.
138
00:06:33,860 --> 00:06:37,080
Now, in order to see anything on the screen
139
00:06:37,080 --> 00:06:41,150
we now need that image, which we are relying on.
140
00:06:41,150 --> 00:06:44,030
And I do provide a dummy image for you,
141
00:06:44,030 --> 00:06:47,300
you can use that image, which you find attached,
142
00:06:47,300 --> 00:06:51,260
the getting-started nextjs png file.
143
00:06:51,260 --> 00:06:52,780
You can download that
144
00:06:52,780 --> 00:06:56,900
and add it in your public images posts folder,
145
00:06:56,900 --> 00:07:01,430
there at this getting-started nextjs png file,
146
00:07:01,430 --> 00:07:04,890
which has a little dummy file I created for you,
147
00:07:04,890 --> 00:07:07,660
of course, you can also add your own files.
148
00:07:07,660 --> 00:07:10,370
And now double check that the value
149
00:07:10,370 --> 00:07:12,390
you set up for the image property here
150
00:07:12,390 --> 00:07:14,500
in the DUMMY POSTS data,
151
00:07:14,500 --> 00:07:17,360
is equal to that image file name you just added,
152
00:07:17,360 --> 00:07:19,203
that you have no typo here.
153
00:07:20,410 --> 00:07:23,450
With that, we should have everything we need.
154
00:07:23,450 --> 00:07:26,440
If we now save that I get an error,
155
00:07:26,440 --> 00:07:27,680
if I reload,
156
00:07:27,680 --> 00:07:32,160
because a forgot to set the href property, makes sense.
157
00:07:32,160 --> 00:07:35,220
In a PostItem, I'm wrapping the entire post
158
00:07:35,220 --> 00:07:38,990
in the end with a link, but I'm not linking anywhere.
159
00:07:38,990 --> 00:07:41,123
I forgot to set my href.
160
00:07:41,970 --> 00:07:45,220
And of course we wanna set the href here.
161
00:07:45,220 --> 00:07:46,570
Now, what should be the link,
162
00:07:46,570 --> 00:07:49,593
or the path this link leads to though?
163
00:07:50,570 --> 00:07:51,570
It showed in the end
164
00:07:51,570 --> 00:07:55,723
be the individual page board this selected post.
165
00:07:56,620 --> 00:07:59,960
So we wanna load this slug page here at the end
166
00:07:59,960 --> 00:08:02,363
for that concrete post slug.
167
00:08:03,320 --> 00:08:07,320
Hence here, we wanna derive that path dynamically,
168
00:08:07,320 --> 00:08:10,130
and I'll do that by adding a separate constant,
169
00:08:10,130 --> 00:08:11,440
linkPath,
170
00:08:11,440 --> 00:08:14,770
which again is a template literal
171
00:08:14,770 --> 00:08:17,510
where we start with, slash posts
172
00:08:17,510 --> 00:08:20,810
because that slug file is in the posts folder,
173
00:08:20,810 --> 00:08:22,740
in the pages folder,
174
00:08:22,740 --> 00:08:24,390
and then slash,
175
00:08:24,390 --> 00:08:26,670
and then some dynamic value.
176
00:08:26,670 --> 00:08:28,600
Here we wanna use the slug then
177
00:08:28,600 --> 00:08:30,880
because that's luck, that unique,
178
00:08:30,880 --> 00:08:33,909
human and search engine friendly text
179
00:08:33,909 --> 00:08:37,409
that should be part of the URL.
180
00:08:37,409 --> 00:08:41,280
And then it's this linkPath which we use here.
181
00:08:41,280 --> 00:08:43,090
So that is something we have to add.
182
00:08:43,090 --> 00:08:47,810
And once we do add this, we do render Featured Posts.
183
00:08:47,810 --> 00:08:51,920
Now the cards are showing up, the images not though.
184
00:08:51,920 --> 00:08:53,860
And that makes sense,
185
00:08:53,860 --> 00:08:57,540
If we take another look at PostItem and the imagePath
186
00:08:57,540 --> 00:08:59,600
we're constructing here.
187
00:08:59,600 --> 00:09:03,810
I point at images posts and then the slug of the posts
188
00:09:03,810 --> 00:09:07,483
as an extra sub folder, and then the image file name.
189
00:09:08,380 --> 00:09:12,220
Now I have the image directly in the post folder,
190
00:09:12,220 --> 00:09:15,620
so that extra slug folder in between is missing.
191
00:09:15,620 --> 00:09:17,010
We should add it.
192
00:09:17,010 --> 00:09:20,118
We should add it, we go back to indexjs,
193
00:09:20,118 --> 00:09:22,670
and then add our slugs here,
194
00:09:22,670 --> 00:09:27,460
which we have in the dummy data as sub folders in posts.
195
00:09:27,460 --> 00:09:31,010
So I'll add a sub folder with a slug of
196
00:09:31,010 --> 00:09:33,660
getting-started-with-nextjs,
197
00:09:33,660 --> 00:09:35,763
and I'll drag the image in there.
198
00:09:38,749 --> 00:09:42,100
And I'll repeat that for my other DUMMY POSTS,
199
00:09:42,100 --> 00:09:43,700
of course it's always the same image
200
00:09:43,700 --> 00:09:45,960
but still to be able to render this,
201
00:09:45,960 --> 00:09:49,853
I'll add more sub folders in the posts folder.
202
00:09:52,250 --> 00:09:54,450
So not inside of the other slug folder
203
00:09:54,450 --> 00:09:58,770
but in the posts folder, there, I will add more sub folders
204
00:10:00,370 --> 00:10:04,400
with those different slug names as a folder names,
205
00:10:04,400 --> 00:10:07,480
because data's required to find the image correctly.
206
00:10:07,480 --> 00:10:10,500
And then we can drag and drop the image
207
00:10:10,500 --> 00:10:14,240
by copying it into those other select sub folders.
208
00:10:14,240 --> 00:10:16,750
So then we have to same image, four times
209
00:10:16,750 --> 00:10:20,583
in those different sub folders for those different slugs.
210
00:10:21,940 --> 00:10:24,490
Now the image should be fetched correctly.
211
00:10:24,490 --> 00:10:29,427
If we save this again and load low closed (indistinct),
212
00:10:29,427 --> 00:10:30,260
we see it.
213
00:10:31,190 --> 00:10:35,520
Now what we also see, is that here on this big screen,
214
00:10:35,520 --> 00:10:37,290
it's a little bit too small.
215
00:10:37,290 --> 00:10:40,600
If I open up the dev tools and I resized this,
216
00:10:40,600 --> 00:10:45,600
you see it doesn't really fit my card that nicely,
217
00:10:45,710 --> 00:10:47,930
it doesn't really fit in there,
218
00:10:47,930 --> 00:10:50,053
and that's not the behavior I want.
219
00:10:50,920 --> 00:10:53,920
To fix this, we can go back to the PostItem
220
00:10:53,920 --> 00:10:55,580
where we rendered that image,
221
00:10:55,580 --> 00:10:58,023
and add the special layout prop.
222
00:10:58,860 --> 00:11:01,360
Now I mentioned that we have a couple of values
223
00:11:01,360 --> 00:11:04,610
we can set there, and the default is intrinsic,
224
00:11:04,610 --> 00:11:06,803
which means, the width and height we specify here,
225
00:11:06,803 --> 00:11:09,650
this is the width and height which is being used.
226
00:11:09,650 --> 00:11:12,900
Now we wanna set this to responsive instead.
227
00:11:12,900 --> 00:11:13,820
By setting this,
228
00:11:13,820 --> 00:11:17,391
it will fill out the entire surrounding container,
229
00:11:17,391 --> 00:11:19,320
this div in this case,
230
00:11:19,320 --> 00:11:21,370
which has certain CSS styles
231
00:11:21,370 --> 00:11:23,420
that control its width and height,
232
00:11:23,420 --> 00:11:26,390
and then it will shrink and grow together
233
00:11:26,390 --> 00:11:28,290
with that container.
234
00:11:28,290 --> 00:11:30,100
So if you set layout to responsive
235
00:11:30,100 --> 00:11:31,710
now that looks much better.
236
00:11:31,710 --> 00:11:34,110
Now we take the full available space
237
00:11:34,110 --> 00:11:36,163
as we moved this around.
238
00:11:37,000 --> 00:11:38,750
Now, of course, it's up to you
239
00:11:38,750 --> 00:11:40,730
how exactly that should be styled.
240
00:11:40,730 --> 00:11:43,310
I just have some basic starting styles here.
241
00:11:43,310 --> 00:11:46,800
You can, of course, fine tuned it to change the size,
242
00:11:46,800 --> 00:11:50,200
and fine tuned it to your exact requirements.
243
00:11:50,200 --> 00:11:52,210
I have some basic style here though,
244
00:11:52,210 --> 00:11:55,140
and as you see that doesn't look too bad.
245
00:11:55,140 --> 00:11:57,830
It is growing and shrinking,
246
00:11:57,830 --> 00:12:01,453
and we take advantage of this automatically optimized image.
247
00:12:02,800 --> 00:12:06,670
So with that we have our Featured Posts being rendered here,
248
00:12:06,670 --> 00:12:10,680
and therefore the starting page of our blog is finished,
249
00:12:10,680 --> 00:12:14,060
with that's dummy data, but better than nothing.
250
00:12:14,060 --> 00:12:18,130
Now we can move on to the other pages and work on those.
251
00:12:18,130 --> 00:12:20,810
And I will move on to the posts page now,
252
00:12:20,810 --> 00:12:23,373
where I wanna render all my posts.
19166
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.