quentin-bettoum

quentin-bettoum

Hello,

I am building a webapp using Phoenix/LiveView where I have a list of items that I want to keep synchronized for all the users viewing it, and I also want to prevent concurrent editing.
I managed to do this by using a mix of Presence and Endpoint.broadcast.

The new LiveView streams are very useful to avoid unecessary queries, but I have one problem with it.
I want to disable the actions of each item that is already being edited and re-enable them when the user is done.
The problem I have with streams is, it seems that there is no way to refresh the actions column without using stream_insert, even when the item didn’t change.
There are cases where I want to refresh this column and where I don’t necessary have an item to submit to stream_insert.
For exemple, when a user start editing, I want to disable the actions of this item in the list, so I usually use stream_insert with the retrieved item by the user when he loads the changeset.

form_component.ex

  defp save_fruit(socket, :edit, fruit_params) do
    case Fruits.update_fruit(socket.assigns.fruit, fruit_params) do
      {:ok, fruit} ->
        notify_parent({:saved, fruit})
        # in my code, this will trigger a broadcast so all users connected
        # to this liveview will get their list refreshed with an updated state of
        # the table actions for this item

But when a user closes his form without submitting it, or when he closes his browser tab, the only way I found to refresh the table actions is to fetch the item from the database (by using the id of the item I stored in the Presence metas).

I tried to change the table component by putting a phx-update="replace" on the actions <td>, but unfortunately it’s not working. I guess nesting different phx-update is not possible (the parent <tbody> is already set to "stream").

I made an example project available here so you can see how I manage to do this at the moment.

You can try it by just creating an account and by adding/editing/deleting fruits with multiple browser tabs opened. The list and its actions are kept synchronized, but I feel the way I did it is not ideal.

Any idea on how to improve this would be appreciated.

Showing Posts 1 to 1

quentin-bettoum

quentin-bettoum OP

The problem has been discussed and solved in this topic

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews