Best way to trigger new data in repeating group?

On page load, I am having a state be set for 50 of the most recent chats sent in a channel.

When users then send a new chat, that new entry is added to the state. Obviously only on THEIR side, not for other users.

I am doing it this way because having the full repeating group data is too much to display, and the height of messages is variable, which causes the chat to jump on mobile (ie. if I were to keep it fixed at 50 messages, one drops off the top when a new one is added to the bottom). This is why I am NOT setting it up like a regular repeating group.

I’ve been experimenting with a handful of different “Do every time when ______” functions in the workflows, ie. the count > the count of messages, or the repeating group doesn’t contain the last message sent… But just never finding anything that is super predictable and works.

Open to suggestions for the best way to recognize new data that is NOT displayed in a repeating group’s state of data!

Can you set the data source for the RG as Do a search for chats: items until 50? I think that should remove the need for your page load setting of the state and also update the RG in real-time as new chats are added

This is what I am doing to set the initial state, but the problem then is when a NEW chat is sent, if the original chat in index #1 is a large paragraph or an image, the chat JUMPS to accommodate a smaller item now in index #50… Because index #2 now becomes index #1.

So instead, I’m trying to have it add item #51, Item #52, etc etc…

I’m just not sure you need to set the state? Have you tried copying the search that is setting the state as the data source of the repeating group?

As you’ve discovered, you’ll need to figure out a way to update the state when a new chat comes in. If the data source of your RG is what I mentioned above I think you should be good! But I also may not be fully understanding your issue…

1 Like

Trying something based on your last comment… You’re getting some ideas going (thank you for the quick replies!). Let me see if that solves my issue.

1 Like

Cool! Curious to hear how it turns out for you

Yep—that did the trick! This was the final option that helped me load a variable number of items AFTER the initial 50.
Screenshot 2024-04-10 at 2.13.12 PM

A separate question for you, if you have any suggestions! On mobile specifically, it never scrolls correctly to the end of the list. It always cuts off at the top section of the chat. See below. Anything I can do to help make sure on MOBILE it is going to the end of that final message?

Assuming you’ve played around with offset?

I have, even to an extreme (ie. 2000 pixels).

I’d set a condition on mobile to make that rich text element shorter in height.

Or you can add a tiny group (visibly hidden [is that a thing?], but still rendered on the page) that is placed below your chat RG. It can be shown conditionally when the page width is < 500px. Set the top margin to 50px. And scroll to that group. That should allow some space above your rich text editor element.

1 Like