��f��C�o�?�j 1 00:00:00,640 --> 00:00:04,840 The last thing we have to do is make sure that after a user edits a blog post we allow them to navigate 2 00:00:04,840 --> 00:00:06,920 back to maybe just the previous screen. 3 00:00:07,520 --> 00:00:13,180 So to do so inside my edit screen remember we've got that navigation province still inside of here or 4 00:00:13,210 --> 00:00:14,440 navigation. 5 00:00:14,440 --> 00:00:17,130 I'm going to do a quick console log of that navigation prop again. 6 00:00:17,170 --> 00:00:21,070 I know we've done it many times but there's a another function on there that I want to show you very 7 00:00:21,070 --> 00:00:22,060 quickly. 8 00:00:22,060 --> 00:00:24,430 It's all save that and then to trigger the console log. 9 00:00:24,430 --> 00:00:28,380 We just need to pull up the edit screen so I'll go to the edit screen there we go. 10 00:00:28,400 --> 00:00:32,210 And now if we go back over to our terminal we should see that console log. 11 00:00:32,240 --> 00:00:33,920 So here's the console log right here. 12 00:00:33,950 --> 00:00:35,990 So we've gone over this console log many different times. 13 00:00:35,990 --> 00:00:41,170 This is the navigation object and every single time we've been using that navigate function there's 14 00:00:41,180 --> 00:00:45,740 another function inside of here that we're going to try to use in order to make sure that a user can 15 00:00:45,800 --> 00:00:49,130 automatically be sent back to the previous screen. 16 00:00:49,160 --> 00:00:52,850 So the key here is that we don't want to navigate to the show screen. 17 00:00:52,850 --> 00:00:54,530 We want to go back. 18 00:00:54,530 --> 00:01:00,140 So kind of like back over to the edit screen so to send a user back to the screen they were just looking 19 00:01:00,140 --> 00:01:07,490 at we can call the pop function right here the pop function essentially pops off the current view off 20 00:01:07,490 --> 00:01:10,880 of a stack of current views or all the views that the user is looking at. 21 00:01:10,880 --> 00:01:16,000 So it's kind of returning a user back to the previous screen they were looking at so to make sure we 22 00:01:16,000 --> 00:01:17,060 call that thing. 23 00:01:17,130 --> 00:01:22,000 I'm going to remove the console log inside of edit screen and then remember what we did the last time 24 00:01:22,000 --> 00:01:26,400 we had to handle navigation is a quick reminder back inside of our blog context. 25 00:01:26,470 --> 00:01:28,840 We've got the ad blog post function right here. 26 00:01:28,840 --> 00:01:34,840 Remember in order to handle navigation we had a callback argument being passed in and inside that callback 27 00:01:34,840 --> 00:01:35,530 function. 28 00:01:35,530 --> 00:01:41,050 We added in some code to navigate the user around so we can follow the same pattern with edit blog post 29 00:01:41,080 --> 00:01:48,890 as well so inside of edit screen I'll find where we call edit blog post and then as the fourth argument 30 00:01:49,190 --> 00:01:58,260 I'll pass in a callback function inside of here we will call navigation dot pop like so that I'll save 31 00:01:58,260 --> 00:01:58,890 this. 32 00:01:59,130 --> 00:02:03,240 I'll go back over to blog context here's edit blog post. 33 00:02:03,240 --> 00:02:07,210 So we now receive a fourth argument of callback. 34 00:02:07,590 --> 00:02:13,080 And so just like we were doing up here inside of ad blog post after dispatching our action we can then 35 00:02:13,080 --> 00:02:16,070 call the callback function. 36 00:02:16,080 --> 00:02:20,820 Now one thing on a mentioned here is that it's entirely possible that we might decide to call ad blog 37 00:02:20,820 --> 00:02:24,390 post or edit blog post without providing a callback. 38 00:02:24,540 --> 00:02:29,140 If that were the case then the code that we have inside both these right now would result in an error. 39 00:02:29,160 --> 00:02:33,300 So one way that we might solve the issue or make sure we don't run into an error if we don't provide 40 00:02:33,300 --> 00:02:40,740 that callback is to just wrap both these with something like If callback exists then call callback. 41 00:02:40,740 --> 00:02:45,030 So we could optionally do that inside of book add blog posts and edit blog post as well. 42 00:02:45,120 --> 00:02:54,540 So inside of edit we can also do if callback then call the callback right now there's not any scenario 43 00:02:54,540 --> 00:02:58,640 where we are not passing in a callback but it's our application starts to scale. 44 00:02:58,680 --> 00:03:04,890 We might decide to call edit blog post or add blog posts from other screens and in those scenarios maybe 45 00:03:04,890 --> 00:03:08,110 we would decide not to navigate the user somewhere else right away. 46 00:03:08,190 --> 00:03:10,860 Who knows why but it's entirely possible. 47 00:03:10,890 --> 00:03:15,300 So in both these scenarios adding in that little if Chuck is just going to save us a little bit of pain 48 00:03:15,300 --> 00:03:17,140 down the line OK. 49 00:03:17,180 --> 00:03:19,770 Let's save this file and do a quick test. 50 00:03:19,930 --> 00:03:31,090 So I'm going to once again tap on the blog post I'll edit I'll do change post and change content. 51 00:03:31,430 --> 00:03:36,270 And then when I tap on safe blog post that's going to dispatch our action to edit the post. 52 00:03:36,500 --> 00:03:41,600 We can see the new content and title on the screen and we also had some automatic navigation where we 53 00:03:41,600 --> 00:03:44,270 got sent back to the previous screen we're looking at. 54 00:03:44,270 --> 00:03:50,130 And again that's coming from calling that navigation dot pop function so looks like this is working 55 00:03:50,130 --> 00:03:51,530 out pretty well. 56 00:03:51,600 --> 00:03:51,840 All right. 57 00:03:51,840 --> 00:03:54,200 So I think our application is just about set. 58 00:03:54,270 --> 00:04:00,090 We've got the ability to delete posts we can add posts we can edit posts we can look at individual ones. 59 00:04:00,330 --> 00:04:02,030 That's pretty much everything. 60 00:04:02,040 --> 00:04:06,090 However there's still a little big feature I want to add in here. 61 00:04:06,120 --> 00:04:07,250 So let's take a quick pause. 62 00:04:07,260 --> 00:04:10,320 When come back the next video we're going to discuss a little change. 63 00:04:10,320 --> 00:04:14,570 We're going to start to make to our application so quick pause and I'll see you in just a minute.