Selaa lähdekoodia

Set title according to current status

theenglishway (time) 4 vuotta sitten
vanhempi
commit
7090e738dd
2 muutettua tiedostoa jossa 13 lisäystä ja 4 poistoa
  1. 12 3
      lib/vaccins_web/live/index.ex
  2. 1 1
      lib/vaccins_web/templates/layout/root.html.leex

+ 12 - 3
lib/vaccins_web/live/index.ex

@@ -19,10 +19,17 @@ defmodule VaccinsWeb.IndexLive do
        location_cs: LocationStore.LocationRaw.changeset(%{}),
        display_cs: false
      )
+     |> set_title()
      |> trigger_global_refresh
      |> trigger_periodic_refresh}
   end
 
+  defp set_title(socket = %{assigns: %{locations_with_early_slots: early}}) do
+    if early |> Enum.empty?(),
+      do: socket |> assign(page_title: "Disponibilités vaccins"),
+      else: socket |> assign(page_title: "(!!) Disponibilités vaccins")
+  end
+
   @impl true
   def handle_params(%{}, _url, socket), do: {:noreply, socket}
 
@@ -62,18 +69,20 @@ defmodule VaccinsWeb.IndexLive do
     do: {:noreply, socket |> trigger_periodic_refresh}
 
   def handle_info({:location_has_slots, id, true}, socket) do
-    {:noreply, socket |> update(:locations_with_early_slots, &(&1 |> MapSet.put(id)))}
+    {:noreply,
+     socket |> update(:locations_with_early_slots, &(&1 |> MapSet.put(id))) |> set_title}
   end
 
   def handle_info({:location_has_slots, id, false}, socket) do
-    {:noreply, socket |> update(:locations_with_slots, &(&1 |> MapSet.put(id)))}
+    {:noreply, socket |> update(:locations_with_slots, &(&1 |> MapSet.put(id))) |> set_title}
   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)))}
+     |> update(:locations_with_early_slots, &(&1 |> MapSet.delete(id)))
+     |> set_title}
   end
 
   def handle_info({:location_deleted, _}, socket),

+ 1 - 1
lib/vaccins_web/templates/layout/root.html.leex

@@ -5,7 +5,7 @@
     <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
     <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
     <%= csrf_meta_tag() %>
-    <%= live_title_tag assigns[:page_title] || "Vaccins", suffix: " · Phoenix Framework" %>
+    <%= live_title_tag assigns[:page_title] || "Vaccins" %>
     <link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
     <script defer phx-track-static type="text/javascript" src="<%= Routes.static_path(@conn, "/js/app.js") %>"></script>
   </head>