OK, so now what we'll do is we'll calculate the amount according to the product and cart, according
to the quantity, we'll calculate the total amount.
OK, so for that also, we need to write a case here.
So that is if action dart type type type is equal equal to get totals.
Now what are the totals?
This will be responsible for the total amount in the bag.
That totals.
And this will be.
Lack.
And we try to tell.
It provided the total here, and we provided the amount also.
And.
That will be cool to.
Did Derkach?
So reduce.
OK.
So inside this.
There will be a function.
Vital to function, and there will be some arguments which will be passed for card.
Total.
And the guard.
Item will be passed here.
And inside, this will set the price also and will set the total item total also in right contest.
Price and amount.
That will be cool like that, that we're grabbing from the guard item.
God, I don't know what is this?
Yeah.
Next, we'll set the item total go on item.
Total is equal to.
Rise.
And to.
Among simple.
This amount of the total number of the products, nothing else like this is the price.
Now, for example, we bought five or three phones, so the total amount would be three into the price
of one form simple.
Next, we'll set the car total.
Got.
Total, not total.
Plus, an equal this policies and that will be item total simple.
Next, we have the total amount.
Our total.
So our time on.
That's an equal to amount.
Simple.
Oh.
That will provide.
The total.
After this.
Total.
Zero.
And among them is also, you know, as of now, no.
After this particular and thesis here.
What we'll do is we'll see the total is equal to the past float.
As flawed and total.
Thought you fixed?
There's a JavaScript function, remember, this has nothing to do with react to to know what this line
of code means is that whenever we are adding up the amount and if we get a decimal value, the floating
point value so that Schnorr display like after the decimal, it's not display more than to two digits,
but that is what this line is doing.
Nothing great.
Nothing so complex.
OK.
Next.
We'll return.
The state.
Right on why I'm doing this type of return, but I don't put it on it.
Next, we'll return the total as well as the amount.
Bad enough, but this was in the labor is not in the parentheses because this is an object.
Not at all.
Our single variable.
OK, now we'll write the case for the loading.
Now what happens when the data is being phased from the EPA and the state is set to loading like the
loading the third to true?
So what will happen so that?
We'll see now.
There is nothing complex there, just one line of code here.
So after this?
We'll see that if.
Action Dati is equal, equal to nerding.
Loading.
Then what we need to return.
We need to return.
The state using a spirit operator and loading is that to throw?
Now.
I never this if if if a statement is executed, that means the lowering will be set to true.
OK.
That is the only job this court will do in our next will try to display the items.
So if?
Action.
The type.
Not Coma.
Not.
The action or type is equal, equal to equal, equal, equal to display items.
Display items, so now what we need to return for this simple.
We'll start downloading two falls and everything else would be just exactly the same date and the loading
and first of all, it fade.
The cart should be the action door.
Not.
Payload and the loading will be set to false.
Simple, simple.
Now.
Next will do to toggle the amount like the Shell, the show to calculate the amount.
So when this should do so, for that, we need to create another case that will be the total amount.
OK, so action start I.
Is equally critical to.
All girl.
Among.
And this will return.
First of all, we'll create a temporary car ban.
Tim Card is equal to St. Dart.
But map.
No map function expects a function inside that should be welcoming.
So inside this will create a further function and then we'll see that if the cart item, it is equal
equal to the payload I.D. So then we'll see like what we need to do if.
The guard item.
Thought I'd.
Is equally equal to the.
Action Lord, the Lord now, let me explain one thing, if you are so confused, that's why we are using
three tools here.
Remember, in JavaScript, you equal to means it will look.
It will check the value is equal or not.
Like, for example, and that is 10.
Not ten is an integer.
OK, now if there is a string and that is equal to 10, for example, I provide I provide constant constraint
and its values.
10.
OK.
OK, that's 10.
Now I create a string and I pass Ben into it.
Now are these two things equal?
What you will say to endorse script if you if you want to check this.
So if you give the equal to so, it will return true, that means they are equal.
They're equal.
But if you check them with the three equal tools for what another extra equal you sign will do is that
it will check for its data type as well.
Like the two equal tools will just check the value and the three core values will check the data type
as well.
Like, if you know, check that 10 integer 10 is equal to spring 10.
So now it will return false because the data type is not the same.
One is an integer and another one is in string.
So that is what we are doing.
Three equal to means it is checking for the value as well as the data type.
If you if we do like two equal to zero, it will just check for the value.
So this is what is the magic of JavaScript.
Next, we'll move on.
And right now, I was in the total amount and I will I was checking the action like the guard item I.D.
and action or payload I.D. And now inside this in there done something.
If these two are equal to what we'll do is we'll return.
Written and will an object, basically.
So we leave the spirit operator and that will be carved.
But I don't.
And the amount would be God tight.
Dortmund last won in both.
Next.
We'll put it on board like this first for the increasing OK.
Like if?
Well, OK, that should be another if statement here.
Like, when we are checking for this, there should be another statement that will check for the type.
OK, my bad.
I'm sorry.
We'll be right.
If action start, I is equal equal to.
Inc, what does the think this means increase, like if they use a selected to increase the number of
products for this scored will be executed?
They will write the same thing for the decreasing part also after this.
We'll add a code for.
For the increase, and that will be if.
Action Dog II is equally according to.
We just the degrees.
Actually, that will action not, but it is action dot below dot type, because this is the payload
type thing is already over.
So payload, dot type and same goes here, also below dart type.
And if that's equal to.
B.
C.
And now.
So this will provide the court, so basically I'll just copy this code because it's doing the same thing,
and I just I'll just provide the negative value for it.
For example, here it was.
Plus we had a low minus symbol.
Nothing so complex, I like to after this.
There are few more things which we need to do like by default.
We need to return the card statement and all.
So this was ending.
You're not here because in this statement, OK, for this, we knew we forgot to provide the parent
kisses.
And that will be provided here.
OK.
This is not this.
And for this, we'll provide another one after this like this one is this ending parenthesis is for
this and this would be for this would be for this.
This is for this.
And yeah.
Now, I hope that that makes sense.
I hope that makes sense.
OK, next, what we'll do is we'll return some basic general things, so we'll return.
Got it on.
Item, so this is the like default thing, OK?
And now overall, we think that this will be a filter.
OK, let me do it quick because we are giving a lot of time to this one component, so I don't want
to make it so long.
That would be I don't.
It will be.
But you don't even need to provide the columnists for the guard item guide item Dortmund should know
and be equal equal to zero.
And.
Why buy the word prep is not working?
Yeah.
All scored after the filter will return one more time.
I know you.
You must be thinking there are so many returns in this one particular campaign, but trust me, this
is the most beautiful thing of react.
And once you understand and you connect the dots, you will love it.
You will not, will will not think of creating any project without the use it or lose it, because this
is the most important thing to learn.
And after this, we'll just throw error if that is an error, we'll throw through new.
At A.
And that will be no matching action type.
Excellent.
Now this is similar to that in the statement, there is a default statement that the last which implies
that if any one of the cases is not true, like the user is entering something else, only so true that
error, which is that in the default theme through new error.
So this is this is a JavaScript thing.
Okay, let me save.
And see, it's compiling OK, there, we made a typo.
So that is on line 53, 53.
Yeah, OK, for the faults, I provide three three.
Yes, OK.
Things are good now and.
Things are working fine so far.
So we'll check this out.
We'll check the UI in the next video, we'll check how this thing looks on the UI in the browser.