1 00:00:00,370 --> 00:00:07,830 Well let's head over back to court context and then after increased amount we have the decrease amount. 2 00:00:08,180 --> 00:00:13,940 However I also failed to mention that not only we're looking for the idea we're gonna need the amount. 3 00:00:14,050 --> 00:00:20,610 So we're going to say I.D. and the amount and the reason for that is because if impound is going to 4 00:00:20,610 --> 00:00:28,520 be less than one or in fact equal to one then instead of just setting the amount equal to zero so decreasing 5 00:00:28,530 --> 00:00:32,410 the item I'm in fact going to remove the item totally from the card. 6 00:00:32,600 --> 00:00:36,250 That's the reason why we're going to get two things from our cart item. 7 00:00:36,300 --> 00:00:41,110 And remember both of them we had access to the I.D. as well as the amount. 8 00:00:41,130 --> 00:00:47,280 So instead of just passing in the 80 in this case we're also going to pass in the amount and the functionality 9 00:00:47,280 --> 00:00:51,660 is going to be following where again we're getting both the I.D. and amount. 10 00:00:51,660 --> 00:00:59,580 And now we want to check if the amount is equal to 1 then I would want to remove the item altogether. 11 00:00:59,580 --> 00:01:01,320 How can we remove the item. 12 00:01:01,350 --> 00:01:03,510 Well we already have the functionality correct. 13 00:01:03,600 --> 00:01:08,210 So I can just say in here and say remove item and then pass the 80. 14 00:01:08,280 --> 00:01:10,050 And also I would want to right away return. 15 00:01:10,380 --> 00:01:13,710 So that would be the case if the amount is equal to 1. 16 00:01:13,790 --> 00:01:17,910 There is no point for us to decrease even more if the amount is already 1. 17 00:01:17,910 --> 00:01:22,800 There is no point for us to decrease to zero right away and just remove the item. 18 00:01:22,800 --> 00:01:28,170 Then we also can have setup else if of course the amount is not equal to one. 19 00:01:28,350 --> 00:01:29,420 What we would want to do then. 20 00:01:29,940 --> 00:01:36,570 And in that case we're going to do exactly the same thing but instead of the last one we're going to 21 00:01:36,570 --> 00:01:38,240 have a minus one. 22 00:01:38,250 --> 00:01:39,960 So we're gonna decrease by one. 23 00:01:39,960 --> 00:01:44,850 And you're looking at near like okay if that is the same functionality we could have set up some kind 24 00:01:44,850 --> 00:01:45,870 of a helper function. 25 00:01:46,020 --> 00:01:47,030 And that is true. 26 00:01:47,100 --> 00:01:49,170 You could set up the helper function. 27 00:01:49,170 --> 00:01:54,860 My issue with that is that that helper function essentially comes out longer than just copy and pasted 28 00:01:54,890 --> 00:01:55,760 in this case. 29 00:01:55,770 --> 00:02:00,930 So even though I'm not a fan of just copying pasting some kind of functionality because inevitably it 30 00:02:00,930 --> 00:02:02,460 does lead to bugs. 31 00:02:02,460 --> 00:02:08,970 In this case setting up the toggle functionality whether we are increasing or decreasing amount just 32 00:02:08,970 --> 00:02:10,890 seemed too much of work. 33 00:02:10,890 --> 00:02:14,860 So in this case I'm just gonna grab whatever functionality what he had here. 34 00:02:15,000 --> 00:02:19,340 We're gonna set this up again instead of plus one. 35 00:02:19,440 --> 00:02:22,500 That was our functionality for increasing the item. 36 00:02:22,500 --> 00:02:28,260 I'm just gonna go with decreasing the item and then of course since we have the new card I also want 37 00:02:28,260 --> 00:02:32,340 to use a set card is gonna be equal to a new card. 38 00:02:32,790 --> 00:02:39,960 So let me make sure that I'm still within the LS largest right set card is equal to my new card. 39 00:02:40,740 --> 00:02:43,700 So we're going to update our state value of work card. 40 00:02:43,920 --> 00:02:45,210 Now who would want to test it out. 41 00:02:45,240 --> 00:02:52,370 We're gonna have to head over to a card item and instead of increase amount we're going to import decrease 42 00:02:52,380 --> 00:03:02,430 amount decrease mound and then where we have the angle down instead of console logging we're going to 43 00:03:02,430 --> 00:03:08,070 run decrease amount increased amount of we're going to pass on to things we're going to pass in the 44 00:03:08,080 --> 00:03:11,960 80 as well as the amount let's say it. 45 00:03:12,060 --> 00:03:13,470 And now let's try it out. 46 00:03:13,470 --> 00:03:21,570 So if we remove the item notice our amount goes down by 1 and then eventually once our amount is equal 47 00:03:21,570 --> 00:03:25,530 to 1 then we just remove the item from the card altogether.