1
00:00:02,000 --> 00:00:03,000
So let's do that cleanup work.

2
00:00:03,000 --> 00:00:06,000
And I first of all wanna make sure

3
00:00:06,000 --> 00:00:11,000
that this app component is a separate route in the end.

4
00:00:11,000 --> 00:00:14,000
And for that as a first step, I'll actually move app

5
00:00:14,000 --> 00:00:17,000
into the routes folder because this is loaded as a route.

6
00:00:17,000 --> 00:00:19,000
And I wanna, as mentioned before,

7
00:00:19,000 --> 00:00:21,000
organize my components such that the route components are

8
00:00:21,000 --> 00:00:24,000
in the routes folder and other components which are used

9
00:00:24,000 --> 00:00:28,000
as part of other components are in the components folder.

10
00:00:29,000 --> 00:00:31,000
And I'll rename this app component here

11
00:00:31,000 --> 00:00:34,000
to posts because ultimately this should be responsible

12
00:00:34,000 --> 00:00:38,000
for rendering my posts list here.

13
00:00:38,000 --> 00:00:42,000
Now in this post JSX file, which was the app component,

14
00:00:42,000 --> 00:00:43,000
I'll remove the main header

15
00:00:43,000 --> 00:00:45,000
and I'll rename this function here,

16
00:00:45,000 --> 00:00:49,000
this component function to posts, also in the export.

17
00:00:50,000 --> 00:00:53,000
And we can get rid of that main header import here as well.

18
00:00:53,000 --> 00:00:56,000
Now we can also get rid of the show modal handler

19
00:00:56,000 --> 00:01:00,000
because that was previously used by the main header.

20
00:01:00,000 --> 00:01:02,000
And we can actually also already get rid

21
00:01:02,000 --> 00:01:05,000
of hide modal handler here,

22
00:01:05,000 --> 00:01:09,000
and get rid of these parts here and of this state

23
00:01:09,000 --> 00:01:11,000
because we'll have to change the entire logic

24
00:01:11,000 --> 00:01:15,000
of our posts list component and how it works soon.

25
00:01:16,000 --> 00:01:18,000
So for the moment, if I save it like this,

26
00:01:19,000 --> 00:01:23,000
if I reload we show that list of posts

27
00:01:23,000 --> 00:01:25,000
and we don't have to duplicate header anymore.

28
00:01:25,000 --> 00:01:27,000
But of course this button here still won't work.

29
00:01:27,000 --> 00:01:29,000
I'll get back to this soon.

30
00:01:29,000 --> 00:01:31,000
What I wanna do first though

31
00:01:31,000 --> 00:01:34,000
is I also wanna refactor the new post component,

32
00:01:34,000 --> 00:01:37,000
and also move that along with its styles file

33
00:01:37,000 --> 00:01:38,000
into the routes folder

34
00:01:38,000 --> 00:01:41,000
because this is also loaded as a route.

35
00:01:43,000 --> 00:01:46,000
So here we have this new post component here,

36
00:01:46,000 --> 00:01:48,000
and with it being moved here,

37
00:01:48,000 --> 00:01:49,000
this button still doesn't work.

38
00:01:49,000 --> 00:01:54,000
But if for the moment I manually enter slash create post

39
00:01:54,000 --> 00:01:56,000
in the URL, this gets loaded.

40
00:01:56,000 --> 00:02:01,000
However, not as a modal overlay above my post list.

41
00:02:02,000 --> 00:02:03,000
This does not work.

42
00:02:04,000 --> 00:02:07,000
As you can see, I have my post list here,

43
00:02:07,000 --> 00:02:10,000
but the new post page was not loaded as an overlay.

44
00:02:10,000 --> 00:02:12,000
And that's therefore some more refactoring

45
00:02:12,000 --> 00:02:14,000
which we have to perform.

46
00:02:14,000 --> 00:02:18,000
This new post component should still be loaded as a modal

47
00:02:18,000 --> 00:02:20,000
and therefore inside of the new post component

48
00:02:20,000 --> 00:02:23,000
I'll use this modal component.

49
00:02:23,000 --> 00:02:25,000
Previously I used it here in post list,

50
00:02:25,000 --> 00:02:27,000
but there I'll soon get rid of it.

51
00:02:27,000 --> 00:02:29,000
So instead, inside the new post component,

52
00:02:29,000 --> 00:02:31,000
I want to use this modal component

53
00:02:31,000 --> 00:02:33,000
as a wrapper around this form.

54
00:02:35,000 --> 00:02:39,000
And for that you have to import this modal component

55
00:02:39,000 --> 00:02:43,000
from going up one level, components modal like this,

56
00:02:44,000 --> 00:02:47,000
so that this still gets rendered as a modal.

57
00:02:48,000 --> 00:02:50,000
And in the posts list component,

58
00:02:50,000 --> 00:02:52,000
I want to clean up this component.

59
00:02:52,000 --> 00:02:55,000
This should no longer be responsible for also adding new

60
00:02:55,000 --> 00:02:58,000
posts, instead that will soon be taken care of inside

61
00:02:58,000 --> 00:03:00,000
of the new post component.

62
00:03:00,000 --> 00:03:03,000
So in the post list component, we can get rid that code

63
00:03:03,000 --> 00:03:05,000
where we render the new post component in the modal.

64
00:03:07,000 --> 00:03:10,000
We can therefore get rid of this isPosting,

65
00:03:10,000 --> 00:03:13,000
and also of the onStopPosting props.

66
00:03:13,000 --> 00:03:16,000
Get rid of these two imports, which we don't need anymore.

67
00:03:17,000 --> 00:03:22,000
And also theoretically here of that adPostHandler function.

68
00:03:22,000 --> 00:03:23,000
But I'll keep it for the moment

69
00:03:23,000 --> 00:03:26,000
because I will soon need that code again.

70
00:03:27,000 --> 00:03:30,000
But with that, if we save this, if I now go to

71
00:03:30,000 --> 00:03:35,000
create dash post, it now opens as an overlay.

72
00:03:36,000 --> 00:03:40,000
However not as an overlay above my post list.

73
00:03:40,000 --> 00:03:42,000
To make that work

74
00:03:42,000 --> 00:03:44,000
we actually have to turn this post component

75
00:03:44,000 --> 00:03:46,000
into a layout component itself,

76
00:03:46,000 --> 00:03:49,000
because whilst it does not provide some sidebar

77
00:03:49,000 --> 00:03:50,000
or main navigation

78
00:03:50,000 --> 00:03:54,000
it still should provide an element that's also available

79
00:03:54,000 --> 00:03:55,000
in the new post component.

80
00:03:55,000 --> 00:03:57,000
And that would be the list of posts.

81
00:03:58,000 --> 00:04:00,000
So I'll actually add a children prop here

82
00:04:00,000 --> 00:04:04,000
to the app component, which was actually renamed to posts.

83
00:04:04,000 --> 00:04:06,000
So I'll rename it here as well

84
00:04:06,000 --> 00:04:08,000
in the import and when I use it.

85
00:04:09,000 --> 00:04:12,000
And then here in this array of child components

86
00:04:12,000 --> 00:04:16,000
I wanna render create post as a child component.

87
00:04:16,000 --> 00:04:19,000
So this new post component is now a child route

88
00:04:19,000 --> 00:04:21,000
of the posts route.

89
00:04:22,000 --> 00:04:26,000
So we have some nested layouts here, but due to this setup

90
00:04:26,000 --> 00:04:29,000
we'll be able to render this new post modal

91
00:04:29,000 --> 00:04:32,000
as an overlay to this list of posts.

92
00:04:32,000 --> 00:04:34,000
For that, we just have to make sure

93
00:04:34,000 --> 00:04:36,000
that we also add an outlet here.

94
00:04:36,000 --> 00:04:40,000
And this can again be done by importing outlet

95
00:04:40,000 --> 00:04:44,000
from react-router-dom, just as we did it before.

96
00:04:44,000 --> 00:04:47,000
And then we could add it here above this main section.

97
00:04:49,000 --> 00:04:52,000
So now posts is technically also a layout route

98
00:04:52,000 --> 00:04:53,000
you could say.

99
00:04:53,000 --> 00:04:55,000
And we got these nested routes here to

100
00:04:55,000 --> 00:05:00,000
achieve this look where if I now open create post

101
00:05:00,000 --> 00:05:04,000
this is open as an overlay above my list of posts.

102
00:05:05,000 --> 00:05:08,000
At the moment, that list of posts gets reloaded

103
00:05:08,000 --> 00:05:10,000
because I manually entered the URL

104
00:05:10,000 --> 00:05:13,000
and they have reloaded this page

105
00:05:13,000 --> 00:05:17,000
as a brand new page just as if I clicked the reload button.

106
00:05:17,000 --> 00:05:18,000
But you see it now is rendered

107
00:05:18,000 --> 00:05:21,000
with exactly the look I want to have,

108
00:05:21,000 --> 00:05:23,000
which is that we have this as an overlay.

109
00:05:24,000 --> 00:05:26,000
Though at the moment closing this

110
00:05:26,000 --> 00:05:28,000
of course does not really work

111
00:05:28,000 --> 00:05:31,000
and we also can't open it by clicking new post.

112
00:05:31,000 --> 00:05:33,000
So that's something we should also change.

