Not bad, not bad.
We have increased functionality online as far as decrease.
We already have the function we already posted down and then of course, we already structured it in
the card item and technically we are calling it when we click on decreased.
The only problem is that the user we're not handling that and essentially functionality will be almost
the same.
The difference is going to be that I also would want to remove the item if I go below one.
So if I'm decreasing, I go below one, then I also would want to automatically remove that item from
the card.
So in this case, I think it's going to be faster if we copy and paste.
So I'm just going to grab it and copy and paste.
And then of course, the type that we're looking for is decrease, decrease like so.
And again, we're iterating over.
That still stays the same.
Now I'm iterating over the state and I still return that damn card, not what is going to be a difference
right now when we're decreasing.
Well, of course, the difference is going to be that if when I set up increase, I added plus one.
In this case, it is going to be minus one.
So I'll change this around where, of course, I'm decreasing.
And also, like I said.
I would want to set up the functionality where once I go below one, well then I would want to remove
that item from the card so I can nicely increase and I can actually decrease.
So that still works.
Everything is the same.
We have time cart, we're or the cautery.
Each item is cart item.
If the payload matches, then we just decrease amount by one.
And then if the idea doesn't match then we just return to cart item and cart is equal to the trump card.
Now the problem is that I don't want to go negative.
That doesn't make sense.
And the way we can fix that is changing filter method.
So I have my trump card, I'm ordering all the card array and what I can do over here is say, you know
what?
Also filter it as well.
And the way we'll set up our filter is in the following way, where I'm going to call again each item,
card item.
And I'm going to say if the card item amount is not equal to zero, then I would want to return.
So I'll say if it is not equal to zero, then please return to my trump card.
If it is zero, which of course is going to be the case once we go below one and of course removed from
the card.
And that way I can increase nicely, I can decrease nicely.
And the moment it is less than one there is now, it's not any more in card.
Now as you are looking at, you can make a strong case where here, listen, both of these should be
combined in one function because there is somewhat repetition and that is not the best setup.
And you're right.
But we will do that at the very end for two reasons.
First, because I would want to give you a challenge to do yourself.
And second, for people who are not interested in combining this into one function, because, of course,
it will require a little bit of refactoring as well.
Keep that in mind.
Once we set up one action over here, of course, we'll also have to help run our project a bit and
change the set up in the right arm as well as the context.
So for those people who are not interested, who are OK with having two functions, they can just skip
that video.
That's why it's going to be all the way at the very end and move on to our next project.
But at this point, we should have a nice functionality in our project where we can increase the amount,
decrease the amount.
And of course, once we go below zero, we remove the item from the cart or and simply remove the item
from the cart.
And of course, we clear the cart as well.