Persist notifications across routes
Hi,
The title says it all. Currently notifications go away when the route is changed. I'd like the notifications to stay until they expire even if the user changes the route.
Is this possible?
Thanks, Theron
Not sure if I understand this correctly, but if you push a notification and go to another route, it will keep that notification the same way it does with the built-in Phoenix implementation.
@sezaru In my app when put a notification and then change routes the notification disappears before the timer is up. I'm following the instructions in the readme so not sure why this is happening. Are you saying Flashy's default behavior is to keep the flashes when the route is changed?
Ah, ok, I think I see what you mean.
Basically what you are saying is that you will send a notification to the user with a time of, let's say, 10 seconds, after that, if you click in some other page before the 10 second mark, the next page will not keep the notification open.
Yeah, unfortunately I would say that this is outside the scope of the library because it would need a more complex solution where you store the notification somewhere and show it up again in the next page.
But I don't think that is too complicated for you to implement as a custom solution in your project. For example, you can create a new custom notification type that you can persist into your DB.
You would persist the message/data you want to show in the notification and the datetime the notification should expire.
That way, you can also add a liveview on_mount hook that will fetch these persisted notifications from your DB, check if the datetime is already expired or not, and if now, send the notification again.