this post was submitted on 06 Aug 2023
5 points (100.0% liked)

Lemmy App Development

711 readers
1 users here now

A place for Lemmy builders to chat about building apps, clients, tools and bots for the Lemmy platform.

On-Topic:

Off-Topic:

founded 1 year ago
MODERATORS
 

I'm creating an AGPL-licensed Lemmy web UI.

While working on the comment section I wondered: what's the best way to retrieve the total amount of direct descendants of a comment? I'm not talking about child_count as this appears to count descendants at any depth.

My use case is displaying a 'Load X more' button that for a given comment loads any direct descendants that are not yet being displayed.

you are viewing a single comment's thread
view the rest of the comments
[–] silas 2 points 1 year ago

Ah, I wasn’t fully understanding, I see what you’re saying now. There’s no way to know the number of comments on a single level/depth as of now without some extra fetching. I think your best bet at this point would be preloading the next page of comments on the top level, and if no comments are return you then know not to show the “load more” button.

Then, each time the next page of top-level comments is fetched, you can also fetch the children of each comment. This will prevent unwanted layout shift and ensure all children are fetched. If you don’t do this, I’ve noticed sometimes child comments go missing when I try to fetch multiple levels of comments in one request from a larger comment tree (100+ comments)