Handle both atom and string keys for packet received_at field
When packets go through Phoenix LiveView serialization, map keys can be converted from atoms to strings. Add get_received_at/1 helper that handles both formats to prevent KeyError when accessing received_at field. This fixes the crash when the iOS app searches for callsigns and the LiveView tries to render the tracked callsign's last seen time.
This commit is contained in:
parent
974c61e549
commit
34c78fbe87
1 changed files with 8 additions and 1 deletions
|
|
@ -196,7 +196,7 @@ defmodule AprsmeWeb.MapLive.Components do
|
||||||
</form>
|
</form>
|
||||||
<%= if @tracked_callsign_latest_packet do %>
|
<%= if @tracked_callsign_latest_packet do %>
|
||||||
<div class="mt-2 text-xs text-gray-600">
|
<div class="mt-2 text-xs text-gray-600">
|
||||||
Last seen: {time_ago_in_words(@tracked_callsign_latest_packet.received_at)}
|
Last seen: {time_ago_in_words(get_received_at(@tracked_callsign_latest_packet))}
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -354,4 +354,11 @@ defmodule AprsmeWeb.MapLive.Components do
|
||||||
</style>
|
</style>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Helper function to get received_at from packet with either atom or string keys
|
||||||
|
defp get_received_at(packet) when is_map(packet) do
|
||||||
|
packet[:received_at] || packet["received_at"]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_received_at(_), do: nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue