Rodeoclash

Rodeoclash

How are others handling the following:

  1. Child components generating flashes (I’ve built a macro to easily send a flash to the root LiveView for display)
  2. Business logic which triggers a flash and redirect (i.e. updating your personal details and returning to the dashboard).

I really don’t have a good solution for “2” yet. Flash messages sent to the root component are never displayed because the root component is unmounted when the redirect is triggered.

One solution that springs to mind is to have two root LiveView components. One for the “pages” and the other which is solely responsible for displaying flash messages. Flashes could then be sent via PubSub subscriptions.

How have others solved this?

Showing Posts 1 to 4

trisolaran

trisolaran

Maybe I’m misunderstanding your question, but if I do:

socket
|> put_flash(:info, "You've been redirected to the dashboard")
|> push_redirect(to: "/dashboard")

# push_navigate if you're on LV 0.18

I get redirected to the dashboard and I can see the flash message. Is this what you were looking for?

Rodeoclash

Rodeoclash OP

Hmm, the only difference with your code is I’m triggering the redirect from the child component. Maybe I need to push the flash and the redirect request to the parent component and I’ll get the flash on the destination page.

trisolaran

trisolaran

I wouldn’t even think in terms of the component pushing flash and redirect.

Generally, I don’t think a component should deal with redirecting or showing flash messages. Its concerns should be rendering and managing portions of your page. I would leave high-level tasks to the parent live view.

I would have the component send an event or a message to the parent live view, and have the parent live view react to it, in this case with a redirect and a flash message.

Rodeoclash

Rodeoclash OP

That seems reasonable, an “onBlah” style event, similar a bit to React’s pattern. Alright, thanks for letting me bounce some ideas around :grinning:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
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
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews