|
|
@@ -5,10 +5,25 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
@impl true
|
|
|
def mount(socket), do: {:ok, socket |> assign(availabilities: [])}
|
|
|
|
|
|
+ @impl true
|
|
|
+ def update(assigns, socket) do
|
|
|
+ {force_refresh, assigns} = assigns |> Map.pop(:force_refresh)
|
|
|
+
|
|
|
+ if is_nil(force_refresh) do
|
|
|
+ {:ok, socket |> assign(assigns)}
|
|
|
+ else
|
|
|
+ trigger_and_signal_query(
|
|
|
+ assigns |> Map.get(:location, socket.assigns.location),
|
|
|
+ assigns.id
|
|
|
+ )
|
|
|
+
|
|
|
+ {:ok, socket |> assign(availabilities: "...") |> assign(assigns)}
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
@impl true
|
|
|
def handle_event("trigger_query", _, socket = %{assigns: %{id: id, location: location}}) do
|
|
|
- ref = Search.async_trigger_query(location)
|
|
|
- send(self(), {:query_sent, id, ref})
|
|
|
+ trigger_and_signal_query(location, id)
|
|
|
{:noreply, socket |> assign(availabilities: "...")}
|
|
|
end
|
|
|
|
|
|
@@ -27,4 +42,9 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
</dl>
|
|
|
"""
|
|
|
end
|
|
|
+
|
|
|
+ defp trigger_and_signal_query(location, id) do
|
|
|
+ ref = Search.async_trigger_query(location)
|
|
|
+ send(self(), {:query_sent, id, ref})
|
|
|
+ end
|
|
|
end
|