Building Table Views with Phoenix LiveView: Add a load indicator that will start on user event (click) and end when data finishes loading

Hello @pullrich,
I am following he book, which is great because is helping me building tabelar UI fast. Thank you.
The ideea to separate the individul Phoenix.LiveComponent
s (sorting, filtering, pagination) from the main LiveView by sending events is great, but it does introduce a UX problem: there is no load indictor that will cover the whole time, starting with the user event (e.g. click on the page number of the pagination form) and ending when the result (the paginated meerkat data) is sent back to the browser.
The current behavior is that the load indicator starts when the user clinks the button and stops when the push event is handled by the handle_event
callback. But in the background, the processing of actually fetching the data continues by sending an :update
event to the parent LiveView, changing the URI params with push_patch
and finally responding to the the URI params change with handle_params
. All this subsequent background processing is not covered by the load indicator, and this is normal, as this is a custom way of processing the data. So we need to manually start and stop the progress indicator ourselves.
I tried to solve this problem myself but did not succeed:
I can start the load indicator (the topbar displayed at the top of the page) by replacing:
<div phx-click="show_page"
phx-value-page={page_number}
phx-target={@myself}
class={if current_page?, do: "active"} >
with
<div phx-click={JS.push("show_page") |> JS.dispatch("phx:page-loading-start")}
phx-value-page={page_number}
phx-target={@myself}
class={if current_page?, do: "active"} >
But I cannot stop the indicator. I tried by adding this to MeowWeb.MeerkatLive.handle_params/3
:
...
|> push_event("phx:page-loading-stop", %{})
...
but it does not work. I see the event being sent to the browser through the web socket, but there is no effect, the progress indicator keeps going on.
Any ideas?
Popular Pragprog topics










Other popular topics










Latest in Pragprog
Latest (all)
Categories:
My Saved Portals
-
None saved yet
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /c-plus-plus
- /flutter
- /preact
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /vuejs
- /nim
- /emacs
- /nerves
- /elm