|
@@ -12,6 +12,8 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
socket
|
|
socket
|
|
|
|> assign(
|
|
|> assign(
|
|
|
locations: locations,
|
|
locations: locations,
|
|
|
|
|
+ locations_with_early_slots: MapSet.new(),
|
|
|
|
|
+ locations_with_slots: MapSet.new(),
|
|
|
pending: %{},
|
|
pending: %{},
|
|
|
location_cs: LocationStore.LocationRaw.changeset(%{}),
|
|
location_cs: LocationStore.LocationRaw.changeset(%{}),
|
|
|
display_cs: false
|
|
display_cs: false
|
|
@@ -47,6 +49,21 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
|> trigger_global_refresh
|
|
|> trigger_global_refresh
|
|
|
|> trigger_periodic_refresh}
|
|
|> trigger_periodic_refresh}
|
|
|
|
|
|
|
|
|
|
+ def handle_info({:location_has_slots, id, true}, socket) do
|
|
|
|
|
+ {:noreply, socket |> update(:locations_with_early_slots, &(&1 |> MapSet.put(id)))}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ def handle_info({:location_has_slots, id, false}, socket) do
|
|
|
|
|
+ {:noreply, socket |> update(:locations_with_slots, &(&1 |> MapSet.put(id)))}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
|
|
+ def handle_info({:location_no_more_slots, id}, socket) do
|
|
|
|
|
+ {:noreply,
|
|
|
|
|
+ socket
|
|
|
|
|
+ |> update(:locations_with_slots, &(&1 |> MapSet.delete(id)))
|
|
|
|
|
+ |> update(:locations_with_early_slots, &(&1 |> MapSet.delete(id)))}
|
|
|
|
|
+ end
|
|
|
|
|
+
|
|
|
@impl true
|
|
@impl true
|
|
|
def handle_info(
|
|
def handle_info(
|
|
|
{:query_result, ref, res},
|
|
{:query_result, ref, res},
|
|
@@ -68,4 +85,26 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
Process.send_after(self(), :periodic_refresh, @refresh_period_ms)
|
|
Process.send_after(self(), :periodic_refresh, @refresh_period_ms)
|
|
|
socket
|
|
socket
|
|
|
end
|
|
end
|
|
|
|
|
+
|
|
|
|
|
+ defp locations_by_availability(
|
|
|
|
|
+ assigns = %{
|
|
|
|
|
+ locations: locations,
|
|
|
|
|
+ locations_with_slots: with_slots,
|
|
|
|
|
+ locations_with_early_slots: with_early_slots
|
|
|
|
|
+ }
|
|
|
|
|
+ ) do
|
|
|
|
|
+ locations
|
|
|
|
|
+ |> Enum.sort(fn e1, e2 ->
|
|
|
|
|
+ e1_has_early_spot? = e1 in with_early_slots
|
|
|
|
|
+ e1_has_spot? = e1 in with_slots
|
|
|
|
|
+ e2_has_early_spot? = e2 in with_early_slots
|
|
|
|
|
+ e2_has_spot? = e2 in with_slots
|
|
|
|
|
+
|
|
|
|
|
+ cond do
|
|
|
|
|
+ e1_has_early_spot? and not e2_has_early_spot? -> true
|
|
|
|
|
+ e1_has_spot? and not e2_has_early_spot? and not e2_has_spot? -> true
|
|
|
|
|
+ true -> false
|
|
|
|
|
+ end
|
|
|
|
|
+ end)
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|