|
@@ -13,6 +13,7 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
noob_mode: false,
|
|
noob_mode: false,
|
|
|
is_local?: is_local?,
|
|
is_local?: is_local?,
|
|
|
all_locations: all_locations,
|
|
all_locations: all_locations,
|
|
|
|
|
+ locations_displayed: all_locations,
|
|
|
locations_with_early_slots: MapSet.new(),
|
|
locations_with_early_slots: MapSet.new(),
|
|
|
locations_with_slots: MapSet.new(),
|
|
locations_with_slots: MapSet.new(),
|
|
|
pending: %{},
|
|
pending: %{},
|
|
@@ -35,7 +36,8 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
do:
|
|
do:
|
|
|
{:noreply,
|
|
{:noreply,
|
|
|
socket
|
|
socket
|
|
|
- |> assign(noob_mode: false, area_filters: socket.assigns.all_areas, params: params)}
|
|
|
|
|
|
|
+ |> assign(noob_mode: false, params: params)
|
|
|
|
|
+ |> update_area_filters(socket.assigns.all_areas)}
|
|
|
|
|
|
|
|
def handle_params(params, _url, socket)
|
|
def handle_params(params, _url, socket)
|
|
|
when is_map_key(params, "noob") or is_map_key(params, "geographic_areas") do
|
|
when is_map_key(params, "noob") or is_map_key(params, "geographic_areas") do
|
|
@@ -46,9 +48,9 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
socket
|
|
socket
|
|
|
|> assign(
|
|
|> assign(
|
|
|
noob_mode: params |> Map.has_key?("noob"),
|
|
noob_mode: params |> Map.has_key?("noob"),
|
|
|
- area_filters: areas |> MapSet.new() |> MapSet.intersection(all_areas),
|
|
|
|
|
params: params
|
|
params: params
|
|
|
- )}
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ |> update_area_filters(areas |> MapSet.new() |> MapSet.intersection(all_areas))}
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
@impl true
|
|
@@ -108,21 +110,18 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
|
|
|
|
|
@impl true
|
|
@impl true
|
|
|
def handle_info({:new_availabilities, id, res}, socket) do
|
|
def handle_info({:new_availabilities, id, res}, socket) do
|
|
|
- send_update(VaccinsWeb.LocationComponent, id: id, availabilities: res)
|
|
|
|
|
|
|
+ if id in (socket.assigns.locations_displayed |> Enum.map(& &1.id)),
|
|
|
|
|
+ do: send_update(VaccinsWeb.LocationComponent, id: id, availabilities: res)
|
|
|
|
|
+
|
|
|
{:noreply, socket}
|
|
{:noreply, socket}
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
- defp filter(locations, %{area_filters: filters}),
|
|
|
|
|
- do:
|
|
|
|
|
- locations
|
|
|
|
|
- |> Enum.filter(&(&1.geographic_area in filters))
|
|
|
|
|
-
|
|
|
|
|
defp locations_by_availability(%{
|
|
defp locations_by_availability(%{
|
|
|
- all_locations: all_locations,
|
|
|
|
|
|
|
+ locations_displayed: locations_displayed,
|
|
|
locations_with_slots: with_slots,
|
|
locations_with_slots: with_slots,
|
|
|
locations_with_early_slots: with_early_slots
|
|
locations_with_early_slots: with_early_slots
|
|
|
}) do
|
|
}) do
|
|
|
- all_locations
|
|
|
|
|
|
|
+ locations_displayed
|
|
|
|> Enum.sort(fn e1, e2 ->
|
|
|> Enum.sort(fn e1, e2 ->
|
|
|
e1_has_early_spot? = e1.id in with_early_slots
|
|
e1_has_early_spot? = e1.id in with_early_slots
|
|
|
e1_has_spot? = e1.id in with_slots
|
|
e1_has_spot? = e1.id in with_slots
|
|
@@ -140,7 +139,17 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
|
|
|
|
|
defp set_all_areas(socket), do: socket |> assign(all_areas: socket |> get_all_areas)
|
|
defp set_all_areas(socket), do: socket |> assign(all_areas: socket |> get_all_areas)
|
|
|
|
|
|
|
|
- defp init_area_filters(socket), do: socket |> assign(area_filters: socket.assigns.all_areas)
|
|
|
|
|
|
|
+ defp init_area_filters(socket), do: socket |> update_area_filters(socket.assigns.all_areas)
|
|
|
|
|
+
|
|
|
|
|
+ defp update_area_filters(socket, filter_value),
|
|
|
|
|
+ do:
|
|
|
|
|
+ socket
|
|
|
|
|
+ |> assign(
|
|
|
|
|
+ area_filters: filter_value,
|
|
|
|
|
+ locations_displayed:
|
|
|
|
|
+ socket.assigns.all_locations
|
|
|
|
|
+ |> Enum.filter(&(&1.geographic_area in filter_value))
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
defp get_all_areas(%{assigns: %{all_locations: all_locations}}),
|
|
defp get_all_areas(%{assigns: %{all_locations: all_locations}}),
|
|
|
do: all_locations |> Enum.map(& &1.geographic_area) |> MapSet.new()
|
|
do: all_locations |> Enum.map(& &1.geographic_area) |> MapSet.new()
|