Преглед изворни кода

wip: Send id instead of ref

theenglishway (time) пре 4 година
родитељ
комит
d54f49253a
2 измењених фајлова са 6 додато и 0 уклоњено
  1. 1 0
      lib/vaccins/search.ex
  2. 5 0
      lib/vaccins_web/live/index.ex

+ 1 - 0
lib/vaccins/search.ex

@@ -11,6 +11,7 @@ defmodule Vaccins.Search do
     with {:ok, _} <-
            Task.start(fn ->
              send(target, {:query_result, ref, l |> Location.query_availability()})
+             send(target, {:location_availabilities, l.id, l |> Location.query_availability()})
            end),
          do: ref
   end

+ 5 - 0
lib/vaccins_web/live/index.ex

@@ -110,6 +110,11 @@ defmodule VaccinsWeb.IndexLive do
     {:noreply, socket |> assign(pending: pending |> Map.delete(ref))}
   end
 
+  def handle_info({:location_availabilities, id, res}, socket = %{assigns: %{locations: valid}}) do
+    send_update(VaccinsWeb.LocationComponent, id: id, availabilities: res)
+    {:noreply, socket}
+  end
+
   defp trigger_global_refresh(socket = %{assigns: %{locations: locations}}) do
     locations
     |> Enum.each(&send_update(VaccinsWeb.LocationComponent, id: &1.id, force_refresh: true))