All right without further ado let's start to implement this architecture.
The first thing I want to do is add in a new context called location.
And we're going to use this thing to maintain a couple of different pieces of state.
So back inside my code editor I'll find a context directory inside there I'll create a new file called
location context dot J.S. then at the very top are going to import create data context from create data
context I'll then make a location reducer as usual this thing will be called with a state object in
some action and right now I'll just set up my switch statements I'll say switch over action type by
default just return our state's then after that I'm going to start to kind of scaffold out a couple
of the different action functions that I think we're going to need.
So first off I think that we need the ability to toggle whether or not we are recording.
Remember recording means that we want to take the user's location updates and store them somehow.
So I want to create some action functions to update that recording flag.
I'll create one called like start recording and I'm gonna use that Shorten syntax here like so.
So remember you we'll type of there.
That's better.
So remember this is going to be one function that gets called with dispatch that returns a another function
will then create another called like stop recording.
Next up I think we need the ability to maybe also how about update or like add in a new location.
So I'll add in a function called something like add location.
So essentially we might want to call add location right here any time we get a location update out of
our use location hook so for ADD location I'll do dispatch like so.
And I think that should at least get us started.
For right now there will be eventually some other action functions we put inside of here but they're
not going to quite make sense just yet.
So we'll come back and add those in in just a little bit.
So then at the very bottom the file will do our export const context and provider and that's all going
to come from create data context and as usual for the first argument we're going to put in our reducer
which is the location reducer well then put inside of an object are different action functions.
So put an object in would start recording stop recording and add location.
And then finally I'm going to provide some initial state object here as well.
So as we just discussed I think that our initial state object should have like a recording flag some
locations array and whatever the current location is as well so my initial state objects will have recording
by default we're gonna say false.
No we are not recording any new track we're gonna have an empty array of locations that the users pass
through and we'll have a current location that's going to start off as not to say we don't yet have
any location whatsoever okay.
So that's a good start for our location context.
Now let's make sure that we wire up this provider inside of our app dot J.S. file.
So inside of app dot J.S. at the very top we'll make sure that I import provider as location provider
from we're gonna walk into our there from not form gonna walk into our s our city directory context
location context and then we can place that location provider down inside of the component that we create
inside of here.
So I'm going to wrap my auth provider with location provider like so
okay.
That's step one.
So I can say this I can make sure that my application doesn't crash or anything like that.
Yeah looks good.
So now we've got some new provider that's going to be in charge of taking all these different location
updates and doing something with them.
So let's now take another quick pause.
The next video we're going to wire up this context thing right here inside of our track create screen
we'll make sure that anytime we get a location update we somehow store that inside of our location context
so quick pause I'll see you in just a minute.