瀏覽代碼

Add last_early_slot_seen

theenglishway (time) 4 年之前
父節點
當前提交
ea4fd90e0d
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      lib/vaccins_web/live/location_component.ex

+ 5 - 3
lib/vaccins_web/live/location_component.ex

@@ -11,7 +11,8 @@ defmodule VaccinsWeb.LocationComponent do
          slots_after: [],
          slots_before: [],
          loading: false,
-         last_refresh_date: nil
+         last_refresh_date: nil,
+         last_early_slot_seen: nil
        )}
 
   @impl true
@@ -53,7 +54,7 @@ defmodule VaccinsWeb.LocationComponent do
         <dd>
           <%= cond do %>
             <%= @loading -> %>...
-            <%= not has_slots?(assigns) -> %>Pas de créneau
+            <%= not has_slots?(assigns) -> %>Pas de créneau <%= if @last_early_slot_seen do %>(<%= @last_early_slot_seen |> DateTime.to_time() |> Time.truncate(:second) |> Time.to_string %>)<% end %>
             <%= has_early_slots?(assigns) -> %><span class="alert-danger">Des dispos sous 24h !</span>
             <%= has_slots?(assigns) -> %>Des dispos !
           <% end %>
@@ -101,6 +102,7 @@ defmodule VaccinsWeb.LocationComponent do
          assigns
          |> Map.put(:slots_after, after_slots |> Enum.take(5))
          |> Map.put(:slots_before, before_slots)
+         |> Map.put(:last_early_slot_seen, DateTime.utc_now)
 
   defp integrate_availabilities(assigns), do: assigns
 
@@ -121,7 +123,7 @@ defmodule VaccinsWeb.LocationComponent do
          do: now |> DateTime.to_time() |> Time.truncate(:second)
   end
 
-  defp signal_availabilities(socket = %{assigns: %{loading: false, slots_after: slots_after}}) do
+  defp signal_availabilities(socket = %{assigns: %{loading: false}}) do
     cond do
       socket.assigns |> has_slots? ->
         send(self(), {:location_has_slots, socket.assigns.id, socket.assigns |> has_early_slots?})