improve formatting

This commit is contained in:
shibao 2023-01-26 00:39:16 -05:00
parent 8ea2b06487
commit 0ad1ee47de
21 changed files with 244 additions and 134 deletions

View File

@ -55,13 +55,13 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<span class="rounded-lg title text-lg">
<%= gettext("Purchased on:") %>
<%= @ammo_group.purchased_on |> display_date() %>
<.date date={@ammo_group.purchased_on} />
</span>
<%= if @ammo_group |> Ammo.get_last_used_shot_group() do %>
<span class="rounded-lg title text-lg">
<%= gettext("Last used on:") %>
<%= @ammo_group |> Ammo.get_last_used_shot_group() |> Map.get(:date) |> display_date() %>
<.date date={@ammo_group |> Ammo.get_last_used_shot_group() |> Map.get(:date)} />
</span>
<% end %>

View File

@ -157,7 +157,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
{purchased_on,
~H"""
<%= @purchased_on |> display_date() %>
<.date date={@purchased_on} />
"""}
end
@ -173,7 +173,7 @@ defmodule CanneryWeb.Components.AmmoGroupTableComponent do
{last_shot_group_date,
~H"""
<%= if @last_shot_group_date do %>
<%= @last_shot_group_date |> display_date() %>
<.date date={@last_shot_group_date} />
<% else %>
<%= gettext("Never used") %>
<% end %>

View File

@ -27,8 +27,14 @@ defmodule CanneryWeb.Components.InviteCard do
<%= if @invite.disabled_at |> is_nil() do %>
<h2 class="title text-md">
<%= gettext("Uses Left:") %>
<%= @invite.uses_left || "Unlimited" %>
<%= if @invite.uses_left do %>
<%= gettext(
"Uses Left: %{uses_left}",
uses_left: @invite.uses_left
) %>
<% else %>
<%= gettext("Uses Left: Unlimited") %>
<% end %>
</h2>
<% else %>
<h2 class="title text-md">

View File

@ -103,7 +103,11 @@ defmodule CanneryWeb.Components.ShotGroupTableComponent do
{ammo_type_name, name_block}
end
defp get_row_value(:date, %{date: date}, _extra_data), do: date |> display_date()
defp get_row_value(:date, assigns = %{date: _date}, _extra_data) do
~H"""
<.date date={@date} />
"""
end
defp get_row_value(:actions, shot_group, %{actions: actions}) do
assigns = %{actions: actions, shot_group: shot_group}

View File

@ -23,16 +23,23 @@ defmodule CanneryWeb.Components.UserCard do
<h3 class="px-4 py-2 rounded-lg title text-lg">
<p>
<%= if @user.confirmed_at |> is_nil() do %>
Email unconfirmed
<%= if @user.confirmed_at do %>
<%= gettext(
"User was confirmed at%{confirmed_datetime}",
confirmed_datetime: ""
) %>
<.datetime datetime={@user.confirmed_at} />
<% else %>
User was confirmed at <%= @user.confirmed_at |> display_datetime() %>
<%= gettext("Email unconfirmed") %>
<% end %>
</p>
<p>
<%= gettext("User registered on") %>
<%= @user.inserted_at |> display_datetime() %>
<%= gettext(
"User registered on%{registered_datetime}",
registered_datetime: ""
) %>
<.datetime datetime={@user.inserted_at} />
</p>
</h3>

View File

@ -116,7 +116,12 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
value =
case key do
:date ->
{date, date |> display_date()}
assigns = %{date: date}
{date,
~H"""
<.date date={@date} />
"""}
:actions ->
~H"""

View File

@ -28,7 +28,7 @@
<span class="rounded-lg title text-lg">
<%= gettext("Purchased on:") %>
<%= @ammo_group.purchased_on |> display_date() %>
<.date date={@ammo_group.purchased_on} />
</span>
<%= if @ammo_group.price_paid do %>

View File

@ -124,7 +124,7 @@
</h3>
<span class="text-primary-600">
<%= @ammo_type.inserted_at |> display_datetime() %>
<.datetime datetime={@ammo_type.inserted_at} />
</span>
<%= if @avg_cost_per_round do %>

View File

@ -5,64 +5,62 @@ defmodule CanneryWeb.ViewHelpers do
:view`
"""
import Phoenix.Component
@id_length 16
use Phoenix.Component
@doc """
Returns a <time> element that renders the naivedatetime in the user's local
timezone with Alpine.js
Phoenix.Component for a <time> element that renders the naivedatetime in the
user's local timezone with Alpine.js
"""
@spec display_datetime(NaiveDateTime.t() | nil) :: Phoenix.LiveView.Rendered.t()
def display_datetime(nil), do: ""
def display_datetime(datetime) do
assigns = %{
id: :crypto.strong_rand_bytes(@id_length) |> Base.url_encode64(),
datetime: datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
}
attr :datetime, :any, required: true, doc: "A `DateTime` struct or nil"
def datetime(assigns) do
~H"""
<time
id={@id}
datetime={@datetime}
x-data={"{
date:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{@datetime}\"))
}"}
x-text="date"
>
<%= @datetime %>
</time>
<%= if @datetime do %>
<time
datetime={cast_datetime(@datetime)}
x-data={"{
datetime:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{cast_datetime(@datetime)}\"))
}"}
x-text="datetime"
>
<%= cast_datetime(@datetime) %>
</time>
<% end %>
"""
end
@spec cast_datetime(NaiveDateTime.t() | nil) :: String.t()
defp cast_datetime(%NaiveDateTime{} = datetime) do
datetime |> DateTime.from_naive!("Etc/UTC") |> DateTime.to_iso8601(:extended)
end
defp cast_datetime(_datetime), do: ""
@doc """
Returns a <date> element that renders the Date in the user's local
timezone with Alpine.js
Phoenix.Component for a <date> element that renders the Date in the user's
local timezone with Alpine.js
"""
@spec display_date(Date.t() | nil) :: Phoenix.LiveView.Rendered.t()
def display_date(nil), do: ""
def display_date(date) do
assigns = %{
id: :crypto.strong_rand_bytes(@id_length) |> Base.url_encode64(),
date: date |> Date.to_iso8601(:extended)
}
attr :date, :any, required: true, doc: "A `Date` struct or nil"
def date(assigns) do
~H"""
<time
id={@id}
datetime={@date}
x-data={"{
date:
Intl.DateTimeFormat([], {timeZone: 'Etc/UTC', dateStyle: 'short'}).format(new Date(\"#{@date}\"))
}"}
x-text="date"
>
<%= @date %>
</time>
<%= if @date do %>
<time
datetime={@date |> Date.to_iso8601(:extended)}
x-data={"{
date:
Intl.DateTimeFormat([], {timeZone: 'Etc/UTC', dateStyle: 'short'})
.format(new Date(\"#{@date |> Date.to_iso8601(:extended)}\"))
}"}
x-text="date"
>
<%= @date |> Date.to_iso8601(:extended) %>
</time>
<% end %>
"""
end
@ -70,9 +68,9 @@ defmodule CanneryWeb.ViewHelpers do
Displays emoji as text emoji if SHIBAO_MODE is set to true :)
"""
@spec display_emoji(String.t()) :: String.t()
def display_emoji("😔"),
do:
if(Application.get_env(:cannery, CanneryWeb.ViewHelpers)[:shibao_mode], do: "q_q", else: "😔")
def display_emoji("😔") do
if Application.get_env(:cannery, CanneryWeb.ViewHelpers)[:shibao_mode], do: "q_q", else: "😔"
end
def display_emoji(other_emoji), do: other_emoji

View File

@ -194,7 +194,7 @@ msgstr "Brandmunition"
msgid "Instance Information"
msgstr "Instanzinformationen"
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr "Einladung deaktiviert"
@ -441,11 +441,6 @@ msgstr "Art:"
msgid "Users"
msgstr "Benutzer"
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr "Verbleibende Nutzung:"
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -734,11 +729,6 @@ msgstr "Kopien"
msgid "Added on:"
msgstr "Hinzugefügt am:"
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr "Benutzer registriert am"
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1152,3 +1142,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Cannery"
msgstr ""
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format, fuzzy
msgid "User registered on%{registered_datetime}"
msgstr "Benutzer registriert am"
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: %{uses_left}"
msgstr "Verbleibende Nutzung:"
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: Unlimited"
msgstr "Verbleibende Nutzung:"

View File

@ -208,7 +208,7 @@ msgstr "Schüsse erfolgreich dokumentiert"
msgid "Are you sure you want to unstage this ammo?"
msgstr "Sind sie sicher, dass Sie diese Munition demarkieren möchten?"
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"

View File

@ -179,7 +179,7 @@ msgstr ""
msgid "Instance Information"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr ""
@ -424,11 +424,6 @@ msgstr ""
msgid "Users"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr ""
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -717,11 +712,6 @@ msgstr ""
msgid "Added on:"
msgstr ""
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr ""
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1135,3 +1125,28 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Cannery"
msgstr ""
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format
msgid "User registered on%{registered_datetime}"
msgstr ""
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format
msgid "Uses Left: %{uses_left}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format
msgid "Uses Left: Unlimited"
msgstr ""

View File

@ -179,7 +179,7 @@ msgstr ""
msgid "Instance Information"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr ""
@ -424,11 +424,6 @@ msgstr ""
msgid "Users"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr ""
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -717,11 +712,6 @@ msgstr ""
msgid "Added on:"
msgstr ""
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr ""
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1135,3 +1125,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Cannery"
msgstr ""
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format, fuzzy
msgid "User registered on%{registered_datetime}"
msgstr ""
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: %{uses_left}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: Unlimited"
msgstr ""

View File

@ -187,7 +187,7 @@ msgstr ""
msgid "Are you sure you want to unstage this ammo?"
msgstr ""
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"

View File

@ -194,7 +194,7 @@ msgstr "Incendiaria"
msgid "Instance Information"
msgstr "Información de Instancia"
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr "Invitación Desactivada"
@ -442,11 +442,6 @@ msgstr "Tipo:"
msgid "Users"
msgstr "Usuarios"
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr "Usos Restantes:"
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -735,11 +730,6 @@ msgstr "Copias"
msgid "Added on:"
msgstr "Añadido en:"
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr "Usuario registrado en"
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1154,3 +1144,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Cannery"
msgstr "Logo de cannery"
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format, fuzzy
msgid "User registered on%{registered_datetime}"
msgstr "Usuario registrado en"
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: %{uses_left}"
msgstr "Usos Restantes:"
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: Unlimited"
msgstr "Usos Restantes:"

View File

@ -207,7 +207,7 @@ msgstr "Tiros registrados exitosamente"
msgid "Are you sure you want to unstage this ammo?"
msgstr "Está seguro que desea desmontar esta munición?"
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"

View File

@ -194,7 +194,7 @@ msgstr "Incendiaire"
msgid "Instance Information"
msgstr "Information de linstance"
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr "Invitation désactivée"
@ -443,11 +443,6 @@ msgstr "Type:"
msgid "Users"
msgstr "Utilisateurs"
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr "Utilisations restantes:"
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -736,11 +731,6 @@ msgstr "Exemplaires"
msgid "Added on:"
msgstr "Ajouté le:"
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr "Utilisateur·ice enregistré·e le"
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1155,3 +1145,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Cannery"
msgstr "Logo de Cannery"
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format, fuzzy
msgid "User registered on%{registered_datetime}"
msgstr "Utilisateur·ice enregistré·e le"
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: %{uses_left}"
msgstr "Utilisations restantes:"
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: Unlimited"
msgstr "Utilisations restantes:"

View File

@ -209,7 +209,7 @@ msgstr "Tirs enregistré avec succès"
msgid "Are you sure you want to unstage this ammo?"
msgstr "Êtes-vous certain·e de vouloir désélectionner cette munition?"
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"

View File

@ -190,7 +190,7 @@ msgstr ""
msgid "Instance Information"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:35
#: lib/cannery_web/components/invite_card.ex:41
#, elixir-autogen, elixir-format
msgid "Invite Disabled"
msgstr ""
@ -435,11 +435,6 @@ msgstr ""
msgid "Users"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:30
#, elixir-autogen, elixir-format
msgid "Uses Left:"
msgstr ""
#: lib/cannery_web/live/invite_live/form_component.html.heex:24
#, elixir-autogen, elixir-format
msgid "Uses left"
@ -728,11 +723,6 @@ msgstr ""
msgid "Added on:"
msgstr ""
#: lib/cannery_web/components/user_card.ex:34
#, elixir-autogen, elixir-format
msgid "User registered on"
msgstr ""
#: lib/cannery_web/templates/user_registration/new.html.heex:37
#: lib/cannery_web/templates/user_settings/edit.html.heex:130
#, elixir-autogen, elixir-format
@ -1146,3 +1136,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "Cannery"
msgstr ""
#: lib/cannery_web/components/user_card.ex:33
#, elixir-autogen, elixir-format
msgid "Email unconfirmed"
msgstr ""
#: lib/cannery_web/components/user_card.ex:38
#, elixir-autogen, elixir-format, fuzzy
msgid "User registered on%{registered_datetime}"
msgstr ""
#: lib/cannery_web/components/user_card.ex:27
#, elixir-autogen, elixir-format
msgid "User was confirmed at%{confirmed_datetime}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:31
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: %{uses_left}"
msgstr ""
#: lib/cannery_web/components/invite_card.ex:36
#, elixir-autogen, elixir-format, fuzzy
msgid "Uses Left: Unlimited"
msgstr ""

View File

@ -198,7 +198,7 @@ msgstr ""
msgid "Are you sure you want to unstage this ammo?"
msgstr ""
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"

View File

@ -187,7 +187,7 @@ msgstr ""
msgid "Are you sure you want to unstage this ammo?"
msgstr ""
#: lib/cannery_web/live/ammo_group_live/show.ex:137
#: lib/cannery_web/live/ammo_group_live/show.ex:142
#: lib/cannery_web/live/range_live/index.html.heex:118
#, elixir-autogen, elixir-format
msgid "Are you sure you want to delete this shot record?"