Add full region name to badge title

This commit is contained in:
Lee Jarvis 2022-02-03 12:11:56 +00:00
parent 554c97fde4
commit 534d4b5442

View file

@ -68,6 +68,30 @@ end
defmodule LiveBeatsWeb.Presence.BadgeComponent do defmodule LiveBeatsWeb.Presence.BadgeComponent do
use LiveBeatsWeb, :live_component use LiveBeatsWeb, :live_component
# https://fly.io/docs/reference/regions/
@region_names %{
"ams" => "Amsterdam, Netherlands",
"atl" => "Atlanta, Georgia (US)",
"cdg" => "Paris, France",
"dfw" => "Dallas, Texas (US)",
"ewr" => "Parsippany, NJ (US)",
"fra" => "Frankfurt, Germany",
"gru" => "Sao Paulo, Brazil",
"hkg" => "Hong Kong",
"iad" => "Ashburn, Virginia (US)",
"lax" => "Los Angeles, California (US)",
"lhr" => "London, United Kingdom",
"maa" => "Chennai (Madras), India",
"nrt" => "Tokyo, Japan",
"ord" => "Chicago, Illinois (US)",
"scl" => "Santiago, Chile",
"sea" => "Seattle, Washington (US)",
"sin" => "Singapore",
"sjc" => "Sunnyvale, California (US)",
"syd" => "Sydney, Australia",
"yyz" => "Toronto, Canada"
}
def render(assigns) do def render(assigns) do
~H""" ~H"""
<li id={"presence-#{@id}"} class="relative col-span-1 flex shadow-sm rounded-md overflow-hidden"> <li id={"presence-#{@id}"} class="relative col-span-1 flex shadow-sm rounded-md overflow-hidden">
@ -78,7 +102,7 @@ defmodule LiveBeatsWeb.Presence.BadgeComponent do
<%= @presence.username %> <%= @presence.username %>
<%= if @ping do %> <%= if @ping do %>
<p class="text-gray-400 text-xs">ping: <%= @ping %>ms</p> <p class="text-gray-400 text-xs">ping: <%= @ping %>ms</p>
<%= if @region do %><img class="inline w-7 h-7 absolute right-3 top-3" src={"https://fly.io/ui/images/#{@region}.svg"} /><% end %> <%= if @region do %><img class="inline w-7 h-7 absolute right-3 top-3" src={"https://fly.io/ui/images/#{@region}.svg"} title={region_name(@region)} /><% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -115,4 +139,6 @@ defmodule LiveBeatsWeb.Presence.BadgeComponent do
end end
defp now_ms, do: System.system_time(:millisecond) defp now_ms, do: System.system_time(:millisecond)
defp region_name(region), do: Map.get(@region_names, region)
end end