JoaoSetas

JoaoSetas

Hi,

I recently encounter a problem when trying to push_event("page-loading-start", %{}) in my liveview.
I forced page-loading-start after handling a event in my liveview that calls Task.Supervisor.async, after the task ends it calls another event in my liveview to update the content of the page and to stop the page loading with push_event("page-loading-stop", %{}).
The problem is that the in the first event of the liveview i update content in the and i think phoenix is sending a page-loading-stop that stops my call to page-loading-start.

I made a change in the App.js so that it has a count of how many page-loading-start calls it has and only calls topbar.hide() when then count is 0.

Here is an example representing my code:

def handle_event("test", %{}, socket) do
  target = self()
  Task.async(fn ->
    :timer.sleep(1000)
    send(target, :render_response)
  end)

  {:noreply,
   assign(socket,
     text: "loading..."
   )
   |> push_event("page-loading-start", %{})}
end

def handle_info(:render_response_chunk, socket) do
  {:noreply,
   assign(socket,
     text: "finished"
   )
   |> push_event("page-loading-start", %{})}
end

My implementation:

window.phxPageLoadingCount = 0
window.addEventListener("phx:page-loading-start", _info => window.phxPageLoadingCount++ && topbar.show(300))
window.addEventListener("phx:page-loading-stop", _info => window.phxPageLoadingCount && !--window.phxPageLoadingCount && topbar.hide())

I don’t know the impact this can have… But i think this could be a nice logic to have in the topbar, especially when calling the page loading events manually.

If this suggestion is accepted i can implement it and create the Pull Request :slight_smile:

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
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
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
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews