kurmetaubanov

kurmetaubanov

Hey everyone! :waving_hand:

I just published my first hex package that solves a common UX issue in Phoenix LiveView applications, and I’d love to share it with the community!

The Problem

Flash messages in Phoenix LiveView applications often stick around until the user navigates away or manually dismisses them. This can lead to cluttered UIs and poor user experience, especially for success messages like “Data saved!” that should naturally disappear after being read.

The Solution

PhoenixLiveViewFlashTimer automatically clears flash messages after a configurable timeout (default: 5 seconds). It handles both:

  • Controller-set flash messages (after form submissions, redirects, etc.)
  • LiveView put_flash calls

Quick Start

Add to your dependencies:

{:phoenix_liveview_flash_timer, "~> 0.1.0"}

For LiveView flash messages only:

def live_view do
  quote do
    use Phoenix.LiveView
    use PhoenixLiveViewFlashTimer
    
    # ... rest of your code
  end
end

For both controller AND LiveView flash messages:

def live_view do
  quote do
    use Phoenix.LiveView
    use PhoenixLiveViewFlashTimer
    on_mount PhoenixLiveViewFlashTimer  # Add this for controller flash support
    
    # ... rest of your code
  end
end

That’s it! Flash messages will now auto-disappear after 5 seconds.
Configuration

# config/config.exs
config :phoenix_liveview_flash_timer,
  default_timeout: 3000  # Custom timeout in milliseconds
Examples
elixir# In a LiveView - automatically cleared after 5 seconds
socket = put_flash(socket, :info, "Data saved successfully!")

# In a LiveView - custom timeout
socket = put_flash(socket, :error, "Something went wrong", 10000)

# In a controller - cleared when LiveView mounts (requires on_mount)
conn
|> put_flash(:info, "Account created successfully!")
|> redirect(to: ~p"/dashboard")

Features

:white_check_mark: Zero configuration required
:white_check_mark: Works with existing Phoenix LiveView apps
:white_check_mark: Configurable timeout per message or globally
:white_check_mark: Handles both controller and LiveView flash messages
:white_check_mark: Uses on_mount hook for universal coverage
:white_check_mark: Simple drop-in solution

Technical Details
The package uses Phoenix LiveView’s on_mount hook to automatically start timers for controller flash messages, and overrides put_flash to set timers for LiveView flash messages. It’s implemented as a simple macro that you can drop into any existing LiveView application without changing your existing code.
This was born out of a real need - I kept manually implementing flash message clearing in every LiveView project, so I decided to package it up and share it with the community!

I’m excited to hear your thoughts and feedback! This is my first hex package, so any suggestions are very welcome.
Thanks! :rocket:

Links

Hex: phoenix_liveview_flash_timer | Hex
Docs: phoenix_liveview_flash_timer v0.1.0 — Documentation

https://github.com/kurmetaubanov/phoenix_liveview_flash_timer

Showing Posts 1 to 6

kurmetaubanov

kurmetaubanov OP

what doesn’t look right??

LostKobrakai

LostKobrakai

There’s no code in the module I linked to.

kurmetaubanov

kurmetaubanov OP

oh i just updated it, please run mix deps.get again
somehow code didn’t paste with the docs. sorry for it, it’s my first package

regex.sh

regex.sh

I wrote a blog about it some time ago, it maybe can help :slight_smile:

kurmetaubanov

kurmetaubanov OP

nice) a JS solution! thanks) countdown is also cool

could be implemented in maybe next version

anyway i want to share this with those who prefers “pure” Elixir solution like myself

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
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
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
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
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews