1
00:00:01,170 --> 00:00:02,730
Let's go back over to our producer.

2
00:00:02,760 --> 00:00:06,960
We need to add in a couple of different cases to handle each of these different types.

3
00:00:08,370 --> 00:00:12,360
So back inside of my reducers cells reducer file.

4
00:00:14,570 --> 00:00:19,850
I'm going to scroll down to my producer and I'm going to add on my three different cases so we will

5
00:00:19,850 --> 00:00:23,870
do a case of action type dot that sells.

6
00:00:26,410 --> 00:00:29,020
Action type dot fetch sells complete.

7
00:00:32,330 --> 00:00:34,460
And finally, vetch sells air.

8
00:00:35,430 --> 00:00:40,560
In each of these, remember, we've said it so many times now, we are making use of IMR nonetheless

9
00:00:40,560 --> 00:00:43,410
just to make TypeScript happy, we still have to return our state object.

10
00:00:43,710 --> 00:00:47,670
So in every case, I'm going to return state after we do some direct mutation to it.

11
00:00:48,370 --> 00:00:52,380
I'll put it in those return statements right away just to make sure we don't get any typescript errors.

12
00:00:54,180 --> 00:00:57,630
Now we can go through and start to update our state in each of these different cases.

13
00:00:58,200 --> 00:01:00,120
First off, let's take care of cells.

14
00:01:00,570 --> 00:01:05,430
As I've said many times in this case, all we really want to do here is flip the loading flag over to

15
00:01:05,430 --> 00:01:05,790
true.

16
00:01:06,330 --> 00:01:11,250
One thing we might also do here is set air to no just in case there was some kind of error with our

17
00:01:11,250 --> 00:01:13,170
previous attempt to fetch a list of cells.

18
00:01:14,300 --> 00:01:19,310
So inside of cells, action type right here will do state loading to true.

19
00:01:20,380 --> 00:01:23,140
And state dot heir to know.

20
00:01:26,060 --> 00:01:30,020
Let's then take care of the other very easy one very quickly, so would fetch sells er.

21
00:01:31,140 --> 00:01:36,060
In this case, we're going to say, well, we just got some air during the loading process, so chances

22
00:01:36,060 --> 00:01:38,490
are we're not loading anymore, so let's change that to false.

23
00:01:39,360 --> 00:01:41,900
And our air will now be action payload.

24
00:01:42,360 --> 00:01:47,190
Remember, we just put together that action crater and our action, not payload property in this case

25
00:01:47,190 --> 00:01:49,340
is going to be a string describing what just went wrong.

26
00:01:51,430 --> 00:01:56,560
So then finally sells complete now, as I mentioned, this one is going to be just a little bit more

27
00:01:56,560 --> 00:01:57,220
complicated.

28
00:01:57,610 --> 00:02:05,410
We need to take our array of cell objects and use that to define both our order array and the data object

29
00:02:05,410 --> 00:02:05,970
as well.

30
00:02:09,139 --> 00:02:14,150
So for that, let's first take care of the order rate, because that one is by far the easiest, we'll

31
00:02:14,160 --> 00:02:19,910
say state court order will be action payload and right away, if we mouseover that, remember, I just

32
00:02:19,910 --> 00:02:26,300
want to give you the reminder once again, this is an array of cell objects, so we are going to map

33
00:02:26,300 --> 00:02:27,110
over that array.

34
00:02:28,750 --> 00:02:31,840
And for every cell we're going to return, it's Eid.

35
00:02:32,920 --> 00:02:36,220
And so that should give us every cell's ID in the correct order.

36
00:02:39,780 --> 00:02:43,560
Next up after that, we'll start to populate our data object as well.

37
00:02:44,070 --> 00:02:46,400
So in this case, we'll do a state dot data.

38
00:02:47,100 --> 00:02:49,500
And again, just a little bit of confusing logic here.

39
00:02:49,680 --> 00:02:52,280
We're going to use the reduce function in this case.

40
00:02:52,650 --> 00:02:57,570
You might remember that the reduced function is somewhat similar to MAP, but rather than iterating

41
00:02:57,570 --> 00:03:02,160
over every single element inside of an array and returning a new array, we're going to instead iterate

42
00:03:02,160 --> 00:03:08,130
over every element and we're going to add in some new data to some kind of new number or string or object

43
00:03:08,130 --> 00:03:09,120
or array or something like that.

44
00:03:09,310 --> 00:03:10,350
Let's just write out the code.

45
00:03:10,650 --> 00:03:13,440
So action payload we're going to reduce.

46
00:03:14,520 --> 00:03:15,660
We're going to take every cell.

47
00:03:19,740 --> 00:03:25,050
For every cell, I'm also going to first argument here should be our accumulator object, so that's

48
00:03:25,050 --> 00:03:27,200
the thing that we're kind of reducing down to.

49
00:03:28,050 --> 00:03:31,670
We're going to add in at accumulator cell ID.

50
00:03:32,160 --> 00:03:34,290
We're going to set that equal to Zel.

51
00:03:36,520 --> 00:03:42,130
And then we'll provide the initial value for our accumulator object, which will be an object.

52
00:03:43,190 --> 00:03:47,100
We're going to very quickly get a nasty air from typescript typescript is really not on board with all

53
00:03:47,100 --> 00:03:47,480
of this.

54
00:03:47,930 --> 00:03:52,820
So to fix this up, we can put in once again to so many little tricks inside this course.

55
00:03:52,820 --> 00:03:53,840
Just one more little trick.

56
00:03:53,840 --> 00:03:57,410
You're going to tell TypeScript what kind of object this is.

57
00:03:57,580 --> 00:04:03,440
I'm going to tell TypeScript that that object is the same type as Arcel state data property.

58
00:04:04,550 --> 00:04:10,250
So we're going to say, as does state at data like so.

59
00:04:12,640 --> 00:04:16,870
Now, we might get an error message here, lesson we have to do is just return the accumulator.

60
00:04:18,070 --> 00:04:19,230
And now everything is working.

61
00:04:20,860 --> 00:04:22,029
OK, so this looks pretty good.

62
00:04:22,060 --> 00:04:26,800
I know the reducer or the reduce function just a little bit nasty is going to assume you've got all

63
00:04:26,800 --> 00:04:28,660
that prior knowledge around how reduce works.

64
00:04:29,980 --> 00:04:35,270
Well, I'd say overall, everything is looking pretty good from the standpoint of fetching cells.

65
00:04:35,560 --> 00:04:39,710
Now all we have to do is repeat this entire process, but don't worry, it'll be much faster.

66
00:04:40,000 --> 00:04:43,360
We're going to repeat the entire process for saving a list of cells as well.

67
00:04:43,600 --> 00:04:45,090
So let's take care of that in just a moment.

