|
|
@@ -19,6 +19,7 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
location_cs: LocationStore.LocationRaw.changeset(%{}),
|
|
|
display_cs: false
|
|
|
)
|
|
|
+ |> init_area_filters()
|
|
|
|> set_title()}
|
|
|
end
|
|
|
|
|
|
@@ -34,6 +35,13 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
def handle_params(%{"noob" => _}, _url, socket),
|
|
|
do: {:noreply, socket |> assign(noob_mode: true)}
|
|
|
|
|
|
+ def handle_params(%{"geographic_areas" => areas}, _url, socket) when is_list(areas) do
|
|
|
+ all = get_all_areas(socket)
|
|
|
+ areas |> MapSet.new() |> MapSet.intersection(all)
|
|
|
+
|
|
|
+ {:noreply, socket |> assign(area_filters: areas)}
|
|
|
+ end
|
|
|
+
|
|
|
@impl true
|
|
|
def handle_event("add_location", %{"location_raw" => params}, socket) do
|
|
|
case params |> LocationStore.add_location() do
|
|
|
@@ -85,6 +93,11 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
{:noreply, socket}
|
|
|
end
|
|
|
|
|
|
+ defp filter(locations, assigns = %{area_filters: filters}),
|
|
|
+ do:
|
|
|
+ locations
|
|
|
+ |> Enum.filter(&(&1.geographic_area in filters))
|
|
|
+
|
|
|
defp locations_by_availability(%{
|
|
|
locations: locations,
|
|
|
locations_with_slots: with_slots,
|
|
|
@@ -105,4 +118,9 @@ defmodule VaccinsWeb.IndexLive do
|
|
|
end
|
|
|
end)
|
|
|
end
|
|
|
+
|
|
|
+ defp init_area_filters(socket), do: socket |> assign(area_filters: socket |> get_all_areas)
|
|
|
+
|
|
|
+ defp get_all_areas(%{assigns: %{locations: locations}}),
|
|
|
+ do: locations |> Enum.map(& &1.geographic_area) |> MapSet.new()
|
|
|
end
|