0:00 All right, so just like we've done for our chats, 0:02 let's go ahead and in our 0:04 source directory 0:06 on our UI, we'll go ahead and create a new hook to actually 0:09 count the number of messages we have in our database, which we know we 0:13 need to implement this infinite scrolling. 0:16 So I'm just gonna go ahead and copy the existing useCountChats and 0:20 paste it in for countMessages. And now we'll go ahead and make some 0:24 changes. So we'll change the name of the function, 0:28 and then we'll need to go ahead and change our endpoint to be 0:30 messagesCount. 0:33 Let's go ahead and change this to messagesCount now, 0:37 and, and then setMessagesCount. 0:41 The function we'll call countMessages, 0:45 and then update our call to setMessagesCount when we parse the 0:49 incoming message. 0:51 And finally, update our return types to be 0:53 messagesCount 0:55 and countMessages. So now that we have this functionality, 0:58 there's another change 0:58 we need to make. So by default, when we actually return 1:02 chats previously from our server, they're just coming back as an 1:06 integer from the database, thanks to the actual 1:09 .count call. This is just going to be coming back as a 1:13 number and then serialized as a string, and that's what the UI is gonna get 1:17 on this call. However, in the messages 1:21 service, 1:23 when we count chats here, we're actually returning 1:26 the object that contains the messages property, and 1:30 that property has the count on it. So in order to 1:34 actually parse this, we want to 1:37 destructure the messages property on the incoming 1:41 payload. So let's do that. We'll destructure the messages property, 1:44 which is 1:45 gonna be the actual count of messages, 1:48 and we'll set this equal to await res.json. 1:52 So we're actually parsing the incoming object, and 1:56 now we're pulling off the message count on it.
The rest of the transcript is for members.
Sign in