I’m creating a sort of bookmark manager with liveview, where bookmarks are organized in collections, and each collection can have a subcollection. As such, I am rendering both bookmarks and collections in the same grid, using temporary assigns. Subcollections are rendered as widget liveviews, in order to encapsulate subscription and update logic.
Creating and updating new widgets works great by using
update(socket, :widgets, fn widgets -> [widget | widgets] end), but I’m having trouble with removing collection widgets. My initial approach was to conditionally render based on the meta state of the ecto struct, i.e.
bookmark.__meta__.state == :deleted. However, I don’t necessarily want to delete a subcollection, but merely reassign to a different parent collection. I think of this as attaching/detaching a subcollection. I tried using a phx-hook where I simply
element.remove a given widget id, but it causes some strange side-effects if a widget is re-added.
Does anyone have an idea of how I can achieve the dynamic attach/detach functionality I’m looking for? Is it perhaps a bad fit for temporary assigns?