update to liveview 0.18 and use elixir 1.14

This commit is contained in:
2022-11-07 22:36:38 -05:00
parent 239b15a782
commit 6b565abf93
79 changed files with 2410 additions and 2321 deletions

View File

@ -54,7 +54,7 @@ defmodule CanneryWeb.Components.AddShotGroupComponent do
|> case do
{:ok, _shot_group} ->
prompt = dgettext("prompts", "Shots recorded successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Ecto.Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -4,7 +4,7 @@
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="shot-group-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -22,12 +22,11 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
>
<%= live_patch to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group),
class: "mb-2 link" do %>
<.link patch={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)} class="mb-2 link">
<h1 class="title text-xl title-primary-500">
<%= @ammo_group.ammo_type.name %>
</h1>
<% end %>
</.link>
<div class="flex flex-col justify-center items-center">
<span class="rounded-lg title text-lg">
@ -67,10 +66,12 @@ defmodule CanneryWeb.Components.AmmoGroupCard do
<span class="rounded-lg title text-lg">
<%= gettext("Container:") %>
<%= live_patch to: Routes.container_show_path(Endpoint, :show, @ammo_group.container),
class: "link" do %>
<.link
patch={Routes.container_show_path(Endpoint, :show, @ammo_group.container)}
class="link"
>
<%= @ammo_group.container.name %>
<% end %>
</.link>
</span>
<% end %>
</div>

View File

@ -19,12 +19,11 @@ defmodule CanneryWeb.Components.ContainerCard do
transition-all duration-300 ease-in-out"
>
<div class="max-w-full mb-4 flex flex-col justify-center items-center space-y-2">
<%= live_redirect to: Routes.container_show_path(Endpoint, :show, @container),
class: "link" do %>
<.link navigate={Routes.container_show_path(Endpoint, :show, @container)} class="link">
<h1 class="px-4 py-2 rounded-lg title text-xl">
<%= @container.name %>
</h1>
<% end %>
</.link>
<%= if @container.desc do %>
<span class="rounded-lg title text-lg">

View File

@ -52,7 +52,7 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
{:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo moved to %{name} successfully", name: container_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Ecto.Changeset{} = changeset} ->
socket |> assign(changeset: changeset)
@ -86,10 +86,9 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add another container!"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add another container!") %>
</.link>
<% else %>
<.live_component
module={CanneryWeb.Components.TableComponent}
@ -122,7 +121,7 @@ defmodule CanneryWeb.Components.MoveAmmoGroupComponent do
class="btn btn-primary"
phx-click="move"
phx-target={@myself}
phx-value-container_id={container.id}
phx-value-container_id={@container.id}
>
<%= dgettext("actions", "Select") %>
</button>

View File

@ -16,16 +16,17 @@ defmodule CanneryWeb.Components.Topbar do
<nav role="navigation" class="mb-8 px-8 py-4 w-full bg-primary-400">
<div class="flex flex-col sm:flex-row justify-between items-center">
<div class="mb-4 sm:mb-0 sm:mr-8 flex flex-row justify-start items-center space-x-2">
<%= live_redirect to: Routes.live_path(Endpoint, HomeLive),
class: "inline mx-2 my-1 leading-5 text-xl text-white"
do %>
<.link
patch={Routes.live_path(Endpoint, HomeLive)}
class="inline mx-2 my-1 leading-5 text-xl text-white"
>
<img
src={Routes.static_path(Endpoint, "/images/cannery.svg")}
alt={gettext("Cannery logo")}
class="inline-block h-8 mx-1"
/>
<h1 class="inline hover:underline">Cannery</h1>
<% end %>
</.link>
<%= if @title_content do %>
<span class="mx-2 my-1">
@ -41,78 +42,100 @@ defmodule CanneryWeb.Components.Topbar do
text-lg text-white text-ellipsis">
<%= if @current_user do %>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Tags"),
to: Routes.tag_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.tag_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Tags") %>
</.link>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Containers"),
to: Routes.container_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.container_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Containers") %>
</.link>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Catalog"),
to: Routes.ammo_type_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.ammo_type_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Catalog") %>
</.link>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Ammo"),
to: Routes.ammo_group_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Ammo") %>
</.link>
</li>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Range"),
to: Routes.range_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.range_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Range") %>
</.link>
</li>
<%= if @current_user.role == :admin do %>
<li class="mx-2 my-1">
<%= live_redirect(gettext("Invites"),
to: Routes.invite_index_path(Endpoint, :index),
class: "text-primary-600 text-white hover:underline"
) %>
<.link
patch={Routes.invite_index_path(Endpoint, :index)}
class="text-primary-600 text-white hover:underline"
>
<%= gettext("Invites") %>
</.link>
</li>
<% end %>
<li class="mx-2 my-1">
<%= live_redirect(@current_user.email,
to: Routes.user_settings_path(Endpoint, :edit),
class: "text-primary-600 text-white hover:underline truncate"
) %>
<.link
patch={Routes.user_settings_path(Endpoint, :edit)}
class="text-primary-600 text-white hover:underline truncate"
>
<%= @current_user.email %>
</.link>
</li>
<li class="mx-2 my-1">
<%= link to: Routes.user_session_path(Endpoint, :delete),
method: :delete,
data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
<.link
href={Routes.user_session_path(Endpoint, :delete)}
method="delete"
data-confirm={dgettext("prompts", "Are you sure you want to log out?")}
>
<i class="fas fa-sign-out-alt"></i>
<% end %>
</.link>
</li>
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
<li class="mx-2 my-1">
<%= live_redirect to: Routes.live_dashboard_path(Endpoint, :home),
class: "text-primary-600 text-white hover:underline" do %>
<.link
patch={Routes.live_dashboard_path(Endpoint, :home)}
class="text-primary-600 text-white hover:underline"
>
<i class="fas fa-gauge"></i>
<% end %>
</.link>
</li>
<% end %>
<% else %>
<%= if Accounts.allow_registration?() do %>
<li class="mx-2 my-1">
<%= live_redirect(dgettext("actions", "Register"),
to: Routes.user_registration_path(Endpoint, :new),
class: "text-primary-600 text-white hover:underline truncate"
) %>
<.link
patch={Routes.user_registration_path(Endpoint, :new)}
class="text-primary-600 text-white hover:underline truncate"
>
<%= dgettext("actions", "Register") %>
</.link>
</li>
<% end %>
<li class="mx-2 my-1">
<%= live_redirect(dgettext("actions", "Log in"),
to: Routes.user_session_path(Endpoint, :new),
class: "text-primary-600 text-white hover:underline truncate"
) %>
<.link
patch={Routes.user_session_path(Endpoint, :new)}
class="text-primary-600 text-white hover:underline truncate"
>
<%= dgettext("actions", "Log in") %>
</.link>
</li>
<% end %>
</ul>

View File

@ -116,7 +116,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
case Ammo.update_ammo_group(ammo_group, ammo_group_params, current_user) do
{:ok, _ammo_group} ->
prompt = dgettext("prompts", "Ammo updated successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -181,7 +181,7 @@ defmodule CanneryWeb.AmmoGroupLive.FormComponent do
count
)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -4,7 +4,7 @@
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="ammo_group-form"
phx-target={@myself}

View File

@ -129,11 +129,14 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
@spec get_value_for_key(atom(), AmmoGroup.t()) :: any()
defp get_value_for_key(:ammo_type, %{ammo_type: ammo_type}) do
assigns = %{ammo_type: ammo_type}
{ammo_type.name,
live_patch(ammo_type.name,
to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "link"
)}
~H"""
<.link patch={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)} class="link">
<%= @ammo_type.name %>
</.link>
"""}
end
defp get_value_for_key(:price_paid, %{price_paid: nil}), do: {"a", nil}
@ -175,15 +178,17 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
type="button"
class="mx-2 my-1 text-sm btn btn-primary"
phx-click="toggle_staged"
phx-value-ammo_group_id={ammo_group.id}
phx-value-ammo_group_id={@ammo_group.id}
>
<%= if ammo_group.staged, do: gettext("Unstage"), else: gettext("Stage") %>
<%= if @ammo_group.staged, do: gettext("Unstage"), else: gettext("Stage") %>
</button>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.ammo_group_index_path(Endpoint, :add_shot_group, ammo_group),
class: "mx-2 my-1 text-sm btn btn-primary"
) %>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :add_shot_group, @ammo_group)}
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</div>
"""}
end
@ -196,28 +201,32 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
~H"""
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, ammo_group),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_group.id}"] do %>
<.link
patch={Routes.ammo_group_show_path(Endpoint, :show, @ammo_group)}
class="text-primary-600 link"
data-qa={"view-#{@ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
</.link>
<%= live_patch to: Routes.ammo_group_index_path(Endpoint, :edit, ammo_group),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_group.id}"] do %>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :edit, @ammo_group)}
class="text-primary-600 link"
data-qa={"edit-#{@ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_group.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={@ammo_group.id}
data-confirm={dgettext("prompts", "Are you sure you want to delete this ammo?")}
data-qa={"delete-#{@ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
"""
end
@ -230,17 +239,19 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
{container_name,
~H"""
<div class="min-w-20 py-2 px-4 h-full flex flew-wrap justify-center items-center">
<%= live_patch(
@ammo_group.container.name,
to: Routes.container_show_path(Endpoint, :show, @ammo_group.container),
class: "mx-2 my-1 link"
) %>
<.link
patch={Routes.container_show_path(Endpoint, :show, @ammo_group.container)}
class="mx-2 my-1 link"
>
<%= @ammo_group.container.name %>
</.link>
<%= live_patch(
gettext("Move ammo"),
to: Routes.ammo_group_index_path(Endpoint, :move, @ammo_group),
class: "mx-2 my-1 text-sm btn btn-primary"
) %>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :move, @ammo_group)}
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= gettext("Move ammo") %>
</.link>
</div>
"""}
end

View File

@ -17,10 +17,9 @@
<%= dgettext("prompts", "You'll need to") %>
</h2>
<%= live_patch(dgettext("actions", "add a container first"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add a container first") %>
</.link>
</div>
<% @ammo_types_count == 0 -> %>
<div class="flex justify-center items-center">
@ -28,21 +27,18 @@
<%= dgettext("prompts", "You'll need to") %>
</h2>
<%= live_patch(dgettext("actions", "add an ammo type first"),
to: Routes.ammo_type_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_type_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add an ammo type first") %>
</.link>
</div>
<% @ammo_groups |> Enum.empty?() -> %>
<%= live_patch(dgettext("actions", "Add your first box!"),
to: Routes.ammo_group_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add your first box!") %>
</.link>
<% true -> %>
<%= live_patch(dgettext("actions", "Add Ammo"),
to: Routes.ammo_group_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add Ammo") %>
</.link>
<% end %>
<%= unless @ammo_groups |> Enum.empty?() do %>

View File

@ -50,7 +50,7 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
prompt = dgettext("prompts", "Ammo deleted succesfully")
redirect_to = Routes.ammo_group_index_path(socket, :index)
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
{:noreply, socket |> put_flash(:info, prompt) |> push_navigate(to: redirect_to)}
end
@impl true
@ -116,22 +116,24 @@ defmodule CanneryWeb.AmmoGroupLive.Show do
:actions ->
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_patch to: Routes.ammo_group_show_path(Endpoint, :edit_shot_group, @ammo_group, shot_group),
class: "text-primary-600 link",
data: [qa: "edit-#{shot_group.id}"] do %>
<.link
patch={Routes.ammo_group_show_path(Endpoint, :edit_shot_group, @ammo_group, @shot_group)}
class="text-primary-600 link"
data-qa={"edit-#{@shot_group.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_shot_group",
phx_value_id: shot_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"),
qa: "delete-#{shot_group.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete_shot_group"
phx-value-id={@shot_group.id}
data-confirm={dgettext("prompts", "Are you sure you want to delete this shot record?")}
data-qa={"delete-#{@shot_group.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
"""

View File

@ -52,27 +52,31 @@
<div class="flex flex-col justify-center items-center">
<div class="flex flex-wrap justify-center items-center text-primary-600">
<%= live_patch(dgettext("actions", "View in Catalog"),
to: Routes.ammo_type_show_path(Endpoint, :show, @ammo_group.ammo_type),
class: "mx-4 my-2 btn btn-primary",
data: [qa: "details"]
) %>
<.link
patch={Routes.ammo_type_show_path(Endpoint, :show, @ammo_group.ammo_type)}
class="mx-4 my-2 btn btn-primary"
data-qa="details"
>
<%= dgettext("actions", "View in Catalog") %>
</.link>
<%= live_patch to: Routes.ammo_group_show_path(Endpoint, :edit, @ammo_group),
class: "mx-4 my-2 text-primary-600 link",
data: [qa: "edit"] do %>
<.link
patch={Routes.ammo_group_show_path(Endpoint, :edit, @ammo_group)}
class="mx-4 my-2 text-primary-600 link"
data-qa="edit"
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "mx-4 my-2 text-primary-600 link",
phx_click: "delete",
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete"
] do %>
<.link
href="#"
class="mx-4 my-2 text-primary-600 link"
phx-click="delete"
data-confirm={dgettext("prompts", "Are you sure you want to delete this ammo?")}
data-qa="delete"
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
<div class="flex flex-wrap justify-center items-center text-primary-600">
@ -82,16 +86,20 @@
else: gettext("Stage for range") %>
</button>
<%= live_patch(dgettext("actions", "Move containers"),
to: Routes.ammo_group_show_path(Endpoint, :move, @ammo_group),
class: "btn btn-primary",
data: [qa: "move"]
) %>
<.link
patch={Routes.ammo_group_show_path(Endpoint, :move, @ammo_group)}
class="btn btn-primary"
data-qa="move"
>
<%= dgettext("actions", "Move containers") %>
</.link>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.ammo_group_show_path(Endpoint, :add_shot_group, @ammo_group),
class: "mx-4 my-2 btn btn-primary"
) %>
<.link
patch={Routes.ammo_group_show_path(Endpoint, :add_shot_group, @ammo_group)}
class="mx-4 my-2 btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</div>
</div>

View File

@ -65,7 +65,7 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
case Ammo.update_ammo_type(ammo_type, ammo_type_params, current_user) do
{:ok, %{name: ammo_type_name}} ->
prompt = dgettext("prompts", "%{name} updated successfully", name: ammo_type_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -83,7 +83,7 @@ defmodule CanneryWeb.AmmoTypeLive.FormComponent do
case Ammo.create_ammo_type(ammo_type_params, current_user) do
{:ok, %{name: ammo_type_name}} ->
prompt = dgettext("prompts", "%{name} created successfully", name: ammo_type_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -3,7 +3,7 @@
<%= @title %>
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="ammo_type-form"
phx-target={@myself}

View File

@ -123,11 +123,13 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
assigns = %{ammo_type: ammo_type}
~H"""
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "link",
data: [qa: "view-name-#{ammo_type.id}"] do %>
<%= ammo_type.name %>
<% end %>
<.link
patch={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)}
class="link"
data-qa={"view-name-#{@ammo_type.id}"}
>
<%= @ammo_type.name %>
</.link>
"""
end
@ -136,28 +138,38 @@ defmodule CanneryWeb.AmmoTypeLive.Index do
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_type.id}"] do %>
<.link
patch={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)}
class="text-primary-600 link"
data-qa={"view-#{@ammo_type.id}"}
>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
</.link>
<%= live_patch to: Routes.ammo_type_index_path(Endpoint, :edit, ammo_type),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_type.id}"] do %>
<.link
patch={Routes.ammo_type_index_path(Endpoint, :edit, @ammo_type)}
class="text-primary-600 link"
data-qa={"edit-#{@ammo_type.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_type.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!", name: ammo_type.name),
qa: "delete-#{ammo_type.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={@ammo_type.id}
data-confirm={
dgettext(
"prompts",
"Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!",
name: @ammo_type.name
)
}
data-qa={"delete-#{@ammo_type.id}"}
>
<i class="fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
"""
end

View File

@ -9,15 +9,13 @@
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add your first type!"),
to: Routes.ammo_type_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_type_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add your first type!") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "New Ammo type"),
to: Routes.ammo_type_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_type_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "New Ammo type") %>
</.link>
<.live_component
module={CanneryWeb.Components.TableComponent}

View File

@ -28,7 +28,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
prompt = dgettext("prompts", "%{name} deleted succesfully", name: ammo_type_name)
redirect_to = Routes.ammo_type_index_path(socket, :index)
{:noreply, socket |> put_flash(:info, prompt) |> push_redirect(to: redirect_to)}
{:noreply, socket |> put_flash(:info, prompt) |> push_navigate(to: redirect_to)}
end
@impl true

View File

@ -12,22 +12,29 @@
<% end %>
<div class="flex space-x-4 justify-center items-center text-primary-600">
<%= live_patch to: Routes.ammo_type_show_path(Endpoint, :edit, @ammo_type),
class: "text-primary-600 link",
data: [qa: "edit"] do %>
<.link
patch={Routes.ammo_type_show_path(Endpoint, :edit, @ammo_type)}
class="text-primary-600 link"
data-qa="edit"
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
data: [
confirm:
dgettext("prompts", "Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!", name: @ammo_type.name),
qa: "delete"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
data-confirm={
dgettext(
"prompts",
"Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!",
name: @ammo_type.name
)
}
data-qa="delete"
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
<hr class="hr" />

View File

@ -5,24 +5,25 @@
<div class="flex flex-wrap justify-center items-center">
<%= for tag <- @container.tags do %>
<%= link to: "#",
class: "mx-2 my-1 px-4 py-2 rounded-lg title text-xl",
style: "color: #{tag.text_color}; background-color: #{tag.bg_color}",
phx_click: "delete",
phx_value_tag_id: tag.id,
phx_target: @myself,
data: [
confirm:
dgettext(
"prompts",
"Are you sure you want to remove the %{tag_name} tag from %{container_name}?",
tag_name: tag.name,
container_name: @container.name
)
] do %>
<.link
href="#"
class="mx-2 my-1 px-4 py-2 rounded-lg title text-xl"
style={"color: #{tag.text_color}; background-color: #{tag.bg_color}"}
phx-click="delete"
phx-value-tag-id={tag.id}
phx-target={@myself}
data-confirm={
dgettext(
"prompts",
"Are you sure you want to remove the %{tag_name} tag from %{container_name}?",
tag_name: tag.name,
container_name: @container.name
)
}
>
<%= tag.name %>
<i class="fa-fw fa-sm fas fa-trash"></i>
<% end %>
</.link>
<% end %>
<%= if @container.tags |> Enum.empty?() do %>
@ -37,7 +38,7 @@
<hr class="hr" />
<.form
let={f}
:let={f}
for={:tag}
id="add-tag-to-container-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -65,7 +65,7 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
case Containers.update_container(container, current_user, container_params) do
{:ok, %{name: container_name}} ->
prompt = dgettext("prompts", "%{name} updated successfully", name: container_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -83,7 +83,7 @@ defmodule CanneryWeb.ContainerLive.FormComponent do
case Containers.create_container(container_params, current_user) do
{:ok, %{name: container_name}} ->
prompt = dgettext("prompts", "%{name} created successfully", name: container_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -3,7 +3,7 @@
<%= @title %>
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="container-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -9,15 +9,13 @@
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add your first container!"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add your first container!") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "New Container"),
to: Routes.container_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "New Container") %>
</.link>
<% end %>
<div class="max-w-full flex flex-row flex-wrap justify-center items-center">
@ -25,29 +23,34 @@
<.container_card container={container}>
<:tag_actions>
<div class="mx-4 my-2">
<%= live_patch to: Routes.container_index_path(Endpoint, :edit_tags, container),
class: "text-primary-600 link" do %>
<.link
patch={Routes.container_index_path(Endpoint, :edit_tags, container)}
class="text-primary-600 link"
>
<i class="fa-fw fa-lg fas fa-tags"></i>
<% end %>
</.link>
</div>
</:tag_actions>
<%= live_patch to: Routes.container_index_path(Endpoint, :edit, container),
class: "text-primary-600 link",
data: [qa: "edit-#{container.id}"] do %>
<.link
patch={Routes.container_index_path(Endpoint, :edit, container)}
class="text-primary-600 link"
data-qa={"edit-#{container.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: container.id,
data: [
confirm:
dgettext("prompts", "Are you sure you want to delete %{name}?", name: container.name),
qa: "delete-#{container.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={container.id}
data-confirm={
dgettext("prompts", "Are you sure you want to delete %{name}?", name: container.name)
}
data-qa={"delete-#{container.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.container_card>
<% end %>
</div>

View File

@ -62,7 +62,7 @@ defmodule CanneryWeb.ContainerLive.Show do
socket
|> put_flash(:info, prompt)
|> push_redirect(to: Routes.container_index_path(socket, :index))
|> push_navigate(to: Routes.container_index_path(socket, :index))
{:error, %{action: :delete, errors: [ammo_groups: _error], valid?: false} = changeset} ->
ammo_groups_error = changeset |> changeset_errors(:ammo_groups) |> Enum.join(", ")

View File

@ -35,22 +35,25 @@
<% end %>
<div class="flex space-x-4 justify-center items-center text-primary-600">
<%= live_patch to: Routes.container_show_path(Endpoint, :edit, @container),
class: "text-primary-600 link",
data: [qa: "edit"] do %>
<.link
patch={Routes.container_show_path(Endpoint, :edit, @container)}
class="text-primary-600 link"
data-qa="edit"
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_container",
data: [
confirm:
dgettext("prompts", "Are you sure you want to delete %{name}?", name: @container.name),
qa: "delete"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete_container"
data-confirm={
dgettext("prompts", "Are you sure you want to delete %{name}?", name: @container.name)
}
data-qa="delete"
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
<hr class="mb-4 hr" />
@ -62,10 +65,12 @@
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Why not add one?"),
to: Routes.container_show_path(Endpoint, :edit_tags, @container),
class: "btn btn-primary"
) %>
<.link
patch={Routes.container_show_path(Endpoint, :edit_tags, @container)}
class="btn btn-primary"
>
<%= dgettext("actions", "Why not add one?") %>
</.link>
</div>
<% else %>
<div class="flex flex-wrap justify-center items-center">
@ -74,10 +79,12 @@
<% end %>
<div class="mx-4 my-2">
<%= live_patch to: Routes.container_show_path(Endpoint, :edit_tags, @container),
class: "text-primary-600 link" do %>
<.link
patch={Routes.container_show_path(Endpoint, :edit_tags, @container)}
class="text-primary-600 link"
>
<i class="fa-fw fa-lg fas fa-tags"></i>
<% end %>
</.link>
</div>
</div>
<% end %>

View File

@ -101,10 +101,12 @@ defmodule CanneryWeb.HomeLive do
</b>
<p>
<%= if @admins |> Enum.empty?() do %>
<%= link(dgettext("prompts", "Register to setup %{name}", name: "Cannery"),
class: "hover:underline",
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
) %>
<.link
href={Routes.user_registration_path(CanneryWeb.Endpoint, :new)}
class="hover:underline"
>
<%= dgettext("prompts", "Register to setup %{name}", name: "Cannery") %>
</.link>
<% else %>
<div class="flex flex-wrap justify-center space-x-2">
<%= for admin <- @admins do %>
@ -130,13 +132,15 @@ defmodule CanneryWeb.HomeLive do
<li class="flex flex-row justify-center items-center space-x-2">
<b>Version:</b>
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery/src/branch/stable/CHANGELOG.md",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
href="https://gitea.bubbletea.dev/shibao/cannery/src/branch/stable/CHANGELOG.md"
class="flex flex-row justify-center items-center space-x-2 hover:underline"
target="_blank"
rel="noopener noreferrer"
>
<p>0.5.5</p>
<i class="fas fa-md fa-info-circle"></i>
<% end %>
</.link>
</li>
</ul>
@ -148,31 +152,37 @@ defmodule CanneryWeb.HomeLive do
</h2>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
class="flex flex-row justify-center items-center space-x-2 hover:underline"
href="https://gitea.bubbletea.dev/shibao/cannery"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("View the source code") %></p>
<i class="fas fa-md fa-code"></i>
<% end %>
</.link>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://weblate.bubbletea.dev/engage/cannery",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
class="flex flex-row justify-center items-center space-x-2 hover:underline"
href="https://weblate.bubbletea.dev/engage/cannery"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("Help translate") %></p>
<i class="fas fa-md fa-language"></i>
<% end %>
</.link>
</li>
<li class="flex flex-col justify-center space-x-2">
<%= link class: "flex flex-row justify-center items-center space-x-2 hover:underline",
to: "https://gitea.bubbletea.dev/shibao/cannery/issues/new",
target: "_blank",
rel: "noopener noreferrer" do %>
<.link
class="flex flex-row justify-center items-center space-x-2 hover:underline"
href="https://gitea.bubbletea.dev/shibao/cannery/issues/new"
target="_blank"
rel="noopener noreferrer"
>
<p><%= gettext("Report bugs or request features") %></p>
<i class="fas fa-md fa-spider"></i>
<% end %>
</.link>
</li>
</ul>
</div>

View File

@ -2,7 +2,7 @@ defmodule CanneryWeb.InitAssigns do
@moduledoc """
Ensures common `assigns` are applied to all LiveViews attaching this hook.
"""
import Phoenix.LiveView
import Phoenix.Component
alias Cannery.Accounts
def on_mount(:default, _params, %{"locale" => locale, "user_token" => user_token}, socket) do

View File

@ -60,7 +60,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
case invite |> Invites.update_invite(invite_params, current_user) do
{:ok, %{name: invite_name}} ->
prompt = dgettext("prompts", "%{name} updated successfully", name: invite_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -78,7 +78,7 @@ defmodule CanneryWeb.InviteLive.FormComponent do
case current_user |> Invites.create_invite(invite_params) do
{:ok, %{name: invite_name}} ->
prompt = dgettext("prompts", "%{name} created successfully", name: invite_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -3,7 +3,7 @@
<%= @title %>
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="invite-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -17,7 +17,7 @@ defmodule CanneryWeb.InviteLive.Index do
else
prompt = dgettext("errors", "You are not authorized to view this page")
return_to = Routes.live_path(Endpoint, HomeLive)
socket |> put_flash(:error, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:error, prompt) |> push_navigate(to: return_to)
end
{:ok, socket}

View File

@ -9,15 +9,13 @@
<%= display_emoji("😔") %>
</h1>
<%= live_patch(dgettext("actions", "Invite someone new!"),
to: Routes.invite_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.invite_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Invite someone new!") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "Create Invite"),
to: Routes.invite_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.invite_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Create Invite") %>
</.link>
<% end %>
<div class="w-full flex flex-row flex-wrap justify-center items-center">
@ -34,25 +32,28 @@
</button>
</form>
</:code_actions>
<%= live_patch to: Routes.invite_index_path(Endpoint, :edit, invite),
class: "text-primary-600 link",
data: [qa: "edit-#{invite.id}"] do %>
<.link
patch={Routes.invite_index_path(Endpoint, :edit, invite)}
class="text-primary-600 link"
data-qa={"edit-#{invite.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_invite",
phx_value_id: invite.id,
data: [
confirm:
dgettext("prompts", "Are you sure you want to delete the invite for %{name}?",
name: invite.name
),
qa: "delete-#{invite.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete_invite"
phx-value-id={invite.id}
data-confirm={
dgettext("prompts", "Are you sure you want to delete the invite for %{name}?",
name: invite.name
)
}
data-qa={"delete-#{invite.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
<%= if invite.disabled_at |> is_nil() do %>
<a href="#" class="btn btn-primary" phx-click="disable_invite" phx-value-id={invite.id}>
@ -93,20 +94,21 @@
<div class="w-full flex flex-row flex-wrap justify-center items-center">
<%= for admin <- @admins do %>
<.user_card user={admin}>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_user",
phx_value_id: admin.id,
data: [
confirm:
dgettext(
"prompts",
"Are you sure you want to delete %{email}? This action is permanent!",
email: admin.email
)
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete_user"
phx-value-id={admin.id}
data-confirm={
dgettext(
"prompts",
"Are you sure you want to delete %{email}? This action is permanent!",
email: admin.email
)
}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.user_card>
<% end %>
</div>
@ -122,20 +124,21 @@
<div class="w-full flex flex-row flex-wrap justify-center items-center">
<%= for user <- @users do %>
<.user_card user={user}>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete_user",
phx_value_id: user.id,
data: [
confirm:
dgettext(
"prompts",
"Are you sure you want to delete %{email}? This action is permanent!",
email: user.email
)
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete_user"
phx-value-id={user.id}
data-confirm={
dgettext(
"prompts",
"Are you sure you want to delete %{email}? This action is permanent!",
email: user.email
)
}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.user_card>
<% end %>
</div>

View File

@ -3,7 +3,7 @@ defmodule CanneryWeb.LiveHelpers do
Contains common helper functions for liveviews
"""
import Phoenix.LiveView.Helpers
import Phoenix.Component
alias Phoenix.LiveView.JS
@doc """
@ -27,17 +27,17 @@ defmodule CanneryWeb.LiveHelpers do
"""
def modal(assigns) do
~H"""
<%= live_patch to: @return_to,
id: "modal-bg",
class:
"fade-in fixed z-10 left-0 top-0
<.link
patch={@return_to}
id="modal-bg"
class="fade-in fixed z-10 left-0 top-0
w-full h-full overflow-hidden
p-8 flex flex-col justify-center items-center cursor-auto",
style: "background-color: rgba(0,0,0,0.4);",
phx_remove: hide_modal()
do %>
p-8 flex flex-col justify-center items-center cursor-auto"
style="background-color: rgba(0,0,0,0.4);"
phx_remove={hide_modal()}
>
<span class="hidden"></span>
<% end %>
</.link>
<div
id="modal"
@ -53,15 +53,16 @@ defmodule CanneryWeb.LiveHelpers do
flex flex-col justify-start items-center
bg-white border-2 rounded-lg"
>
<%= live_patch to: @return_to,
id: "close",
class:
"absolute top-8 right-10
<.link
patch={@return_to}
id="close"
class="absolute top-8 right-10
text-gray-500 hover:text-gray-800
transition-all duration-500 ease-in-out",
phx_remove: hide_modal() do %>
transition-all duration-500 ease-in-out"
phx_remove={hide_modal()}
>
<i class="fa-fw fa-lg fas fa-times"></i>
<% end %>
</.link>
<div class="overflow-x-hidden overflow-y-auto w-full p-8 flex flex-col space-y-4 justify-start items-center">
<%= render_slot(@inner_block) %>

View File

@ -53,7 +53,7 @@ defmodule CanneryWeb.RangeLive.FormComponent do
case ActivityLog.update_shot_group(shot_group, shot_group_params, current_user) do
{:ok, _shot_group} ->
prompt = dgettext("prompts", "Shot records updated successfully")
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Ecto.Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)

View File

@ -4,7 +4,7 @@
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="shot-group-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"

View File

@ -103,10 +103,11 @@ defmodule CanneryWeb.RangeLive.Index do
case key do
:name ->
{shot_group.ammo_group.ammo_type.name,
live_patch(shot_group.ammo_group.ammo_type.name,
to: Routes.ammo_group_show_path(Endpoint, :show, shot_group.ammo_group),
class: "link"
)}
~H"""
<.link patch={Routes.ammo_group_show_path(Endpoint, :show, @shot_group.ammo_group)} class="link">
<%= @shot_group.ammo_group.ammo_type.name %>
</.link>
"""}
:date ->
date |> display_date()
@ -114,22 +115,24 @@ defmodule CanneryWeb.RangeLive.Index do
:actions ->
~H"""
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_patch to: Routes.range_index_path(Endpoint, :edit, shot_group),
class: "text-primary-600 link",
data: [qa: "edit-#{shot_group.id}"] do %>
<.link
patch={Routes.range_index_path(Endpoint, :edit, @shot_group)}
class="text-primary-600 link"
data-qa={"edit-#{@shot_group.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: shot_group.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this shot record?"),
qa: "delete-#{shot_group.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={@shot_group.id}
data-confirm={dgettext("prompts", "Are you sure you want to delete this shot record?")}
data-qa={"delete-#{@shot_group.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</div>
"""

View File

@ -9,15 +9,13 @@
<%= display_emoji("😔") %>
</h1>
<%= live_patch(dgettext("actions", "Why not get some ready to shoot?"),
to: Routes.ammo_group_index_path(Endpoint, :index),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :index)} class="btn btn-primary">
<%= dgettext("actions", "Why not get some ready to shoot?") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "Stage ammo"),
to: Routes.ammo_group_index_path(Endpoint, :index),
class: "btn btn-primary"
) %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :index)} class="btn btn-primary">
<%= dgettext("actions", "Stage ammo") %>
</.link>
<%= for ammo_group <- @ammo_groups do %>
<.ammo_group_card ammo_group={ammo_group}>
@ -33,10 +31,12 @@
else: gettext("Stage for range") %>
</button>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.range_index_path(Endpoint, :add_shot_group, ammo_group),
class: "btn btn-primary"
) %>
<.link
patch={Routes.range_index_path(Endpoint, :add_shot_group, ammo_group)}
class="btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</.ammo_group_card>
<% end %>
<% end %>

View File

@ -58,7 +58,7 @@ defmodule CanneryWeb.TagLive.FormComponent do
<%= @title %>
</h2>
<.form
let={f}
:let={f}
for={@changeset}
id="tag-form"
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
@ -106,7 +106,7 @@ defmodule CanneryWeb.TagLive.FormComponent do
case Tags.update_tag(tag, tag_params, current_user) do
{:ok, %{name: tag_name}} ->
prompt = dgettext("prompts", "%{name} updated successfully", name: tag_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(:changeset, changeset)
@ -124,7 +124,7 @@ defmodule CanneryWeb.TagLive.FormComponent do
case Tags.create_tag(tag_params, current_user) do
{:ok, %{name: tag_name}} ->
prompt = dgettext("prompts", "%{name} created successfully", name: tag_name)
socket |> put_flash(:info, prompt) |> push_redirect(to: return_to)
socket |> put_flash(:info, prompt) |> push_navigate(to: return_to)
{:error, %Changeset{} = changeset} ->
socket |> assign(changeset: changeset)

View File

@ -11,35 +11,37 @@
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Make your first tag!"),
to: Routes.tag_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.tag_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Make your first tag!") %>
</.link>
<% else %>
<%= live_patch(dgettext("actions", "New Tag"),
to: Routes.tag_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<.link patch={Routes.tag_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "New Tag") %>
</.link>
<% end %>
<div class="flex flex-row flex-wrap justify-center items-center">
<%= for tag <- @tags do %>
<.tag_card tag={tag}>
<%= live_patch to: Routes.tag_index_path(Endpoint, :edit, tag),
class: "text-primary-600 link",
data: [qa: "edit-#{tag.id}"] do %>
<.link
patch={Routes.tag_index_path(Endpoint, :edit, tag)}
class="text-primary-600 link"
data-qa={"edit-#{tag.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
</.link>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: tag.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: tag.name),
qa: "delete-#{tag.id}"
] do %>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={tag.id}
data-confirm={
dgettext("prompts", "Are you sure you want to delete %{name}?", name: tag.name)
}
data-qa={"delete-#{tag.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.link>
</.tag_card>
<% end %>
</div>

View File

@ -11,7 +11,7 @@ defmodule CanneryWeb.Router do
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
plug :put_user_locale, default: Application.get_env(:gettext, :default_locale, "en_US")
plug :put_user_locale, default: Application.compile_env(:gettext, :default_locale, "en_US")
end
defp put_user_locale(%{assigns: %{current_user: %{locale: locale}}} = conn, default: default) do

View File

@ -10,8 +10,9 @@
type="image/jpg"
href={Routes.static_path(@conn, "/images/cannery.svg")}
/>
<%= if(assigns |> Map.has_key?(:page_title), do: @page_title, else: "Cannery")
|> live_title_tag(suffix: " | Cannery") %>
<.live_title suffix=" | Cannery">
<%= assigns[:page_title] || "Cannery" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={Routes.static_path(@conn, "/css/app.css")} />
<script
defer

View File

@ -22,14 +22,12 @@
<div class="flex flex-row justify-center items-center space-x-4">
<%= if Accounts.allow_registration?() do %>
<%= link(dgettext("actions", "Register"),
to: Routes.user_registration_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_registration_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Register") %>
</.link>
<% end %>
<%= link(dgettext("actions", "Log in"),
to: Routes.user_session_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Log in") %>
</.link>
</div>
</div>

View File

@ -45,13 +45,11 @@
<hr class="hr" />
<div class="flex flex-row justify-center items-center space-x-4">
<%= link(dgettext("actions", "Log in"),
to: Routes.user_session_path(@conn, :new),
class: "btn btn-primary"
) %>
<%= link(dgettext("actions", "Forgot your password?"),
to: Routes.user_reset_password_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Log in") %>
</.link>
<.link href={Routes.user_reset_password_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Forgot your password?") %>
</.link>
</div>
</div>

View File

@ -40,14 +40,12 @@
<div class="flex flex-row justify-center items-center space-x-4">
<%= if Accounts.allow_registration?() do %>
<%= link(dgettext("actions", "Register"),
to: Routes.user_registration_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_registration_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Register") %>
</.link>
<% end %>
<%= link(dgettext("actions", "Log in"),
to: Routes.user_session_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Log in") %>
</.link>
</div>
</div>

View File

@ -22,14 +22,12 @@
<div class="flex flex-row justify-center items-center space-x-4">
<%= if Accounts.allow_registration?() do %>
<%= link(dgettext("actions", "Register"),
to: Routes.user_registration_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_registration_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Register") %>
</.link>
<% end %>
<%= link(dgettext("actions", "Log in"),
to: Routes.user_session_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_session_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Log in") %>
</.link>
</div>
</div>

View File

@ -37,14 +37,12 @@
<div class="flex flex-row justify-center items-center space-x-4">
<%= if Accounts.allow_registration?() do %>
<%= link(dgettext("actions", "Register"),
to: Routes.user_registration_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_registration_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Register") %>
</.link>
<% end %>
<%= link(dgettext("actions", "Forgot your password?"),
to: Routes.user_reset_password_path(@conn, :new),
class: "btn btn-primary"
) %>
<.link href={Routes.user_reset_password_path(@conn, :new)} class="btn btn-primary">
<%= dgettext("actions", "Forgot your password?") %>
</.link>
</div>
</div>

View File

@ -6,7 +6,7 @@
<hr class="hr" />
<.form
let={f}
:let={f}
for={@email_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
@ -49,7 +49,7 @@
<hr class="hr" />
<.form
let={f}
:let={f}
for={@password_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4 justify-center items-center"
@ -104,7 +104,7 @@
<hr class="hr" />
<.form
let={f}
:let={f}
for={@locale_changeset}
action={Routes.user_settings_path(@conn, :update)}
class="flex flex-col space-y-4 justify-center items-center"
@ -139,10 +139,12 @@
<hr class="hr" />
<%= link(dgettext("actions", "Delete User"),
to: Routes.user_settings_path(@conn, :delete, @current_user),
method: :delete,
class: "btn btn-alert",
data: [confirm: dgettext("prompts", "Are you sure you want to delete your account?")]
) %>
<.link
href={Routes.user_settings_path(@conn, :delete, @current_user)}
method={:delete}
class="btn btn-alert"
data-confirm={dgettext("prompts", "Are you sure you want to delete your account?")}
>
<%= dgettext("actions", "Delete User") %>
</.link>
</div>

View File

@ -4,7 +4,7 @@ defmodule CanneryWeb.ErrorHelpers do
"""
use Phoenix.HTML
import Phoenix.LiveView.Helpers
import Phoenix.Component
alias Ecto.Changeset
alias Phoenix.{HTML.Form, LiveView.Rendered}

View File

@ -5,8 +5,7 @@ defmodule CanneryWeb.ViewHelpers do
:view`
"""
import Phoenix.LiveView
import Phoenix.LiveView.Helpers
import Phoenix.Component
@id_length 16
@ -24,11 +23,16 @@ defmodule CanneryWeb.ViewHelpers do
}
~H"""
<time id={@id} datetime={@datetime} x-data={"{
<time
id={@id}
datetime={@datetime}
x-data={"{
date:
Intl.DateTimeFormat([], {dateStyle: 'short', timeStyle: 'long'})
.format(new Date(\"#{@datetime}\"))
}"} x-text="date">
}"}
x-text="date"
>
<%= @datetime %>
</time>
"""
@ -48,10 +52,15 @@ defmodule CanneryWeb.ViewHelpers do
}
~H"""
<time id={@id} datetime={@date} x-data={"{
<time
id={@id}
datetime={@date}
x-data={"{
date:
Intl.DateTimeFormat([], {timeZone: 'Etc/UTC', dateStyle: 'short'}).format(new Date(\"#{@date}\"))
}"} x-text="date">
}"}
x-text="date"
>
<%= @date %>
</time>
"""