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.

  • silas
    link
    fedilink
    English
    arrow-up
    2
    ·
    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)