1 00:00:00,300 --> 00:00:01,380 Not bad, not bad. 2 00:00:01,410 --> 00:00:04,760 We have increased functionality online as far as decrease. 3 00:00:04,770 --> 00:00:10,860 We already have the function we already posted down and then of course, we already structured it in 4 00:00:10,860 --> 00:00:16,280 the card item and technically we are calling it when we click on decreased. 5 00:00:16,650 --> 00:00:24,060 The only problem is that the user we're not handling that and essentially functionality will be almost 6 00:00:24,060 --> 00:00:24,940 the same. 7 00:00:24,960 --> 00:00:31,830 The difference is going to be that I also would want to remove the item if I go below one. 8 00:00:32,170 --> 00:00:40,410 So if I'm decreasing, I go below one, then I also would want to automatically remove that item from 9 00:00:40,410 --> 00:00:40,800 the card. 10 00:00:41,190 --> 00:00:46,170 So in this case, I think it's going to be faster if we copy and paste. 11 00:00:46,470 --> 00:00:49,230 So I'm just going to grab it and copy and paste. 12 00:00:49,440 --> 00:00:56,010 And then of course, the type that we're looking for is decrease, decrease like so. 13 00:00:56,460 --> 00:00:58,920 And again, we're iterating over. 14 00:00:59,040 --> 00:01:00,910 That still stays the same. 15 00:01:01,000 --> 00:01:08,100 Now I'm iterating over the state and I still return that damn card, not what is going to be a difference 16 00:01:08,100 --> 00:01:09,870 right now when we're decreasing. 17 00:01:10,320 --> 00:01:17,970 Well, of course, the difference is going to be that if when I set up increase, I added plus one. 18 00:01:18,180 --> 00:01:20,100 In this case, it is going to be minus one. 19 00:01:20,460 --> 00:01:23,870 So I'll change this around where, of course, I'm decreasing. 20 00:01:24,120 --> 00:01:25,170 And also, like I said. 21 00:01:26,100 --> 00:01:32,670 I would want to set up the functionality where once I go below one, well then I would want to remove 22 00:01:32,670 --> 00:01:37,680 that item from the card so I can nicely increase and I can actually decrease. 23 00:01:38,070 --> 00:01:39,350 So that still works. 24 00:01:39,600 --> 00:01:40,620 Everything is the same. 25 00:01:40,870 --> 00:01:43,920 We have time cart, we're or the cautery. 26 00:01:44,250 --> 00:01:45,480 Each item is cart item. 27 00:01:45,780 --> 00:01:49,350 If the payload matches, then we just decrease amount by one. 28 00:01:49,710 --> 00:01:55,860 And then if the idea doesn't match then we just return to cart item and cart is equal to the trump card. 29 00:01:56,220 --> 00:01:58,650 Now the problem is that I don't want to go negative. 30 00:01:59,040 --> 00:02:00,210 That doesn't make sense. 31 00:02:00,630 --> 00:02:05,370 And the way we can fix that is changing filter method. 32 00:02:05,670 --> 00:02:12,030 So I have my trump card, I'm ordering all the card array and what I can do over here is say, you know 33 00:02:12,030 --> 00:02:12,240 what? 34 00:02:12,390 --> 00:02:13,920 Also filter it as well. 35 00:02:14,250 --> 00:02:19,620 And the way we'll set up our filter is in the following way, where I'm going to call again each item, 36 00:02:19,620 --> 00:02:20,190 card item. 37 00:02:20,430 --> 00:02:28,760 And I'm going to say if the card item amount is not equal to zero, then I would want to return. 38 00:02:29,250 --> 00:02:34,320 So I'll say if it is not equal to zero, then please return to my trump card. 39 00:02:34,620 --> 00:02:41,070 If it is zero, which of course is going to be the case once we go below one and of course removed from 40 00:02:41,070 --> 00:02:41,390 the card. 41 00:02:41,700 --> 00:02:44,880 And that way I can increase nicely, I can decrease nicely. 42 00:02:45,070 --> 00:02:50,530 And the moment it is less than one there is now, it's not any more in card. 43 00:02:50,970 --> 00:02:57,300 Now as you are looking at, you can make a strong case where here, listen, both of these should be 44 00:02:57,300 --> 00:03:04,130 combined in one function because there is somewhat repetition and that is not the best setup. 45 00:03:04,470 --> 00:03:05,340 And you're right. 46 00:03:05,490 --> 00:03:08,970 But we will do that at the very end for two reasons. 47 00:03:09,330 --> 00:03:12,060 First, because I would want to give you a challenge to do yourself. 48 00:03:12,480 --> 00:03:17,670 And second, for people who are not interested in combining this into one function, because, of course, 49 00:03:17,970 --> 00:03:20,760 it will require a little bit of refactoring as well. 50 00:03:21,120 --> 00:03:21,960 Keep that in mind. 51 00:03:22,170 --> 00:03:29,040 Once we set up one action over here, of course, we'll also have to help run our project a bit and 52 00:03:29,040 --> 00:03:33,070 change the set up in the right arm as well as the context. 53 00:03:33,360 --> 00:03:38,130 So for those people who are not interested, who are OK with having two functions, they can just skip 54 00:03:38,130 --> 00:03:38,640 that video. 55 00:03:38,800 --> 00:03:43,370 That's why it's going to be all the way at the very end and move on to our next project. 56 00:03:43,380 --> 00:03:49,770 But at this point, we should have a nice functionality in our project where we can increase the amount, 57 00:03:50,130 --> 00:03:51,000 decrease the amount. 58 00:03:51,150 --> 00:03:57,240 And of course, once we go below zero, we remove the item from the cart or and simply remove the item 59 00:03:57,240 --> 00:03:57,870 from the cart. 60 00:03:58,080 --> 00:04:00,570 And of course, we clear the cart as well.