Now that we've got our forum together and a button inside of here we need to make sure that our context
has the ability to accept a brand new title in content and create a blog post out of it so I got to
find my context directory and open up the blog context dot J J.S. file inside of here.
We've already got an action function right here called add a blog post.
Right now remember we are automatically generating a title whenever we call this thing.
However because we are essentially trying to create a blog post anyways I think we should just reuse
this function right here and have it accept the title content of some new blog post that we want to
create.
So we're just going to reuse the same function.
Remember the inner function side of here is what we actually end up calling from inside of our component.
So if you want to we can accept some arguments that will come from our component and then pass those
through to the dispatch function.
So I'm going to accept an argument of title and content we're going to eventually get from our create
screen component or then add those both in to a payload property.
So on this object I'll put in payload and I want to add in both title and content so I'll have payload
this time around be set to an object of its own that has a title of title and a content of content.
Now once again we're in a scenario where we have identical key and values so we can condense that down
to just title and content like so.
All right.
So now when we see inside a very Newser an action of type add blog post the action is going to have
a payload and we want to use that payload to set the title and the content.
So inside of case add blog post right here.
We will leave in the current ideal logic but we're going to replace the title.
The title will now instead come from action payload.
Title and we'll have a content property as well which will come from action payload dot content.
Now whenever we create a new blog post we're gonna have an I.D. title and content okay.
So that's pretty much all we have to change inside of here.
So now we can go back to our create screen inside of create screen we can get access to our context
once again remember we've already got the import for context right there and there's our use context
look right there.
So inside of one component I will call use context I'll pass in that context object and then we're going
to get back our whole big state object and all those different action functions.
In this case we don't care about the state object we don't care about the delete action function.
We only care about ad blog post so I'm going to d structure out ad blog post like so then we can make
sure that we call this with our title in content.
Whenever user taps on the button that we placed in the last video here's our button element right here.
I need to expand it.
New line it just to give myself a little bit of space and I'll put in on press on their
and inside of that arrow function we can call add a blog post and pass in our title and content.
Add blog post and pass it title and content like so OK.
So that should definitely at least create the new blog post.
We are still missing one part of this equation.
Whenever we add a new blog post we probably want to navigate our user back to the big list of blog posts.
So we don't really have anything inside of here to handle that just yet but we can at least attempt
to add in a new blog post and then manually navigate back over to the index list.
Let's try that for right now.
Just make sure that the code that we just added in actually works.
So going to save all the files that we just changed I'll then go back over I'm going to tap on that
plus button on the top right I'll enter a title of a new post and some content I'll then add the blog
post.
So that should update our listing and we can now navigate manually back over to our list of blogs by
hitting that back button right there.
And sure enough I do see a new post appear with my randomly generated ideas.
All right so definitely looks like that works.
I'll do another quick test on Android as well.
Over here I'll put in new post at the post.
Go back and see new post.
Very good.
All right.
So now we've got that working.
Let's take another quick pause right here.
When we come back the next video we'll figure out some way to make sure that we automatically navigate
back to our main index screen.
Anytime we call add blog post so quick pause and I'll see you in just a minute.