Infinite scroll of card with reactions and comments

Hi,

I have the usual app of post with reactions and comments.
I have succeed to make an infinite scroll with adding deleting posts and use pubsub to broadcast modification (new reaction, comments,…). So, it works well when everything is managed by the liveview.

My issue is that a post can be in a lot of different liveview. So I have a lot of duplication.

I thought using a live component was the right move but it’s not that easy as it can’t directly receive a message.

Do you any tips on how to avoid the duplication ?

Will on_mount/attach_hook help?

https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.html#attach_hook/4

Hi,

Thanks for your help

Seems to be the right way to do it.
But, I can’t attach a hook to a handle_info triggered by a pubsub broadcast

Really strange, maybe a bug in my code.

Could you clarify what you mean by this? Do you have multiple LiveViews on the same page, and each of them is displaying posts? What is the difference between the LiveViews?

Sure,

I’ve created several distinct liveview to list the cards

  • created by a user (in the user profil)
  • for a topic (in the topic details show page)
  • in a search page

Maybe it’s ok to duplicate the code in each liveview or maybe i should create a liveview for the infinite scroll and render it inside another liveview or the on_mount/attach_hook is the right move.

I don’t really know :sweat_smile:

Thanks for your help