|
@@ -11,7 +11,8 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
has_availabilities: false,
|
|
has_availabilities: false,
|
|
|
slots_after: [],
|
|
slots_after: [],
|
|
|
slots_before: [],
|
|
slots_before: [],
|
|
|
- loading: false
|
|
|
|
|
|
|
+ loading: false,
|
|
|
|
|
+ last_refresh_date: nil
|
|
|
)}
|
|
)}
|
|
|
|
|
|
|
|
@impl true
|
|
@impl true
|
|
@@ -27,14 +28,15 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
assigns.id
|
|
assigns.id
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- {:ok, socket |> assign(assigns) |> assign(loading: true)}
|
|
|
|
|
|
|
+ {:ok,
|
|
|
|
|
+ socket |> assign(assigns) |> assign(loading: true, last_refresh_date: get_refresh_time())}
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
@impl true
|
|
|
def handle_event("trigger_query", _, socket = %{assigns: %{id: id, location: location}}) do
|
|
def handle_event("trigger_query", _, socket = %{assigns: %{id: id, location: location}}) do
|
|
|
trigger_and_signal_query(location, id)
|
|
trigger_and_signal_query(location, id)
|
|
|
- {:noreply, socket |> assign(loading: true)}
|
|
|
|
|
|
|
+ {:noreply, socket |> assign(loading: true, last_refresh_date: get_refresh_time())}
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
@impl true
|
|
@@ -43,7 +45,7 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
<dl class="location">
|
|
<dl class="location">
|
|
|
<dt>id</dt>
|
|
<dt>id</dt>
|
|
|
<dd><%= @location.id %></dd>
|
|
<dd><%= @location.id %></dd>
|
|
|
- <dt>Status</dt>
|
|
|
|
|
|
|
+ <dt>Status (<%= if @last_refresh_date, do: @last_refresh_date |> Time.to_string() %>) </dt>
|
|
|
<dd>
|
|
<dd>
|
|
|
<%= cond do %>
|
|
<%= cond do %>
|
|
|
<%= @loading -> %>...
|
|
<%= @loading -> %>...
|
|
@@ -96,4 +98,10 @@ defmodule VaccinsWeb.LocationComponent do
|
|
|
ref = Search.async_trigger_query(location)
|
|
ref = Search.async_trigger_query(location)
|
|
|
send(self(), {:query_sent, id, ref})
|
|
send(self(), {:query_sent, id, ref})
|
|
|
end
|
|
end
|
|
|
|
|
+
|
|
|
|
|
+ defp get_refresh_time() do
|
|
|
|
|
+ with {:ok, now} <-
|
|
|
|
|
+ DateTime.utc_now() |> DateTime.shift_zone("Europe/Paris", Tzdata.TimeZoneDatabase),
|
|
|
|
|
+ do: now |> DateTime.to_time() |> Time.truncate(:second)
|
|
|
|
|
+ end
|
|
|
end
|
|
end
|