Browse Source

Refresh slots on load

theenglishway (time) 4 years ago
parent
commit
c72d40639a
1 changed files with 11 additions and 6 deletions
  1. 11 6
      lib/vaccins_web/live/index.ex

+ 11 - 6
lib/vaccins_web/live/index.ex

@@ -13,7 +13,8 @@ defmodule VaccinsWeb.IndexLive do
        pending: %{},
        availabilities: locations |> Map.new(&{&1.id, []}),
        location_cs: LocationStore.LocationRaw.changeset(%{})
-     )}
+     )
+     |> trigger_global_refresh}
   end
 
   @impl true
@@ -25,11 +26,8 @@ defmodule VaccinsWeb.IndexLive do
   end
 
   @impl true
-  def handle_event("trigger_all", _, socket = %{assigns: %{locations: locations}}) do
-    locations
-    |> Enum.each(&send_update(VaccinsWeb.LocationComponent, id: &1.id, force_refresh: true))
-
-    {:noreply, socket}
+  def handle_event("trigger_all", _, socket) do
+    {:noreply, socket |> trigger_global_refresh}
   end
 
   @impl true
@@ -46,4 +44,11 @@ defmodule VaccinsWeb.IndexLive do
     send_update(VaccinsWeb.LocationComponent, id: id, availabilities: res)
     {:noreply, socket |> assign(pending: pending |> Map.delete(ref))}
   end
+
+  defp trigger_global_refresh(socket = %{assigns: %{locations: locations}}) do
+    locations
+    |> Enum.each(&send_update(VaccinsWeb.LocationComponent, id: &1.id, force_refresh: true))
+
+    socket
+  end
 end