improve table route navigation

This commit is contained in:
shibao 2022-11-19 14:05:29 -05:00
parent 25d4f1916a
commit 5ffa627beb
20 changed files with 63 additions and 58 deletions

View File

@ -5,7 +5,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
use CanneryWeb, :live_view
import CanneryWeb.Components.AmmoGroupCard
alias Cannery.Ammo
alias Cannery.{Ammo, Ammo.AmmoType}
alias CanneryWeb.Endpoint
@fields_list [
@ -31,17 +31,16 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
]
@impl true
def mount(_params, _session, socket),
do: {:ok, socket |> assign(show_used: false, view_table: false)}
def mount(_params, _session, %{assigns: %{live_action: live_action}} = socket),
do: {:ok, socket |> assign(show_used: false, view_table: live_action == :table)}
@impl true
def handle_params(
%{"id" => id},
_params,
%{assigns: %{current_user: current_user, live_action: live_action}} = socket
) do
ammo_type = Ammo.get_ammo_type!(id, current_user)
socket = socket |> assign(view_table: live_action == :table) |> display_ammo_type(ammo_type)
def handle_params(%{"id" => id}, _params, %{assigns: %{live_action: live_action}} = socket) do
socket =
socket
|> assign(view_table: live_action == :table)
|> display_ammo_type(id)
{:noreply, socket}
end
@ -75,13 +74,13 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
do: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
else: Routes.ammo_type_show_path(Endpoint, :table, ammo_type)
{:noreply, socket |> assign(view_table: !view_table) |> push_patch(to: new_path)}
{:noreply, socket |> push_patch(to: new_path)}
end
defp display_ammo_type(
%{assigns: %{live_action: live_action, current_user: current_user, show_used: show_used}} =
socket,
ammo_type
%AmmoType{} = ammo_type
) do
fields_to_display =
@fields_list
@ -106,6 +105,10 @@ defmodule CanneryWeb.AmmoTypeLive.Show do
)
end
defp display_ammo_type(%{assigns: %{current_user: current_user}} = socket, ammo_type_id) do
socket |> display_ammo_type(Ammo.get_ammo_type!(ammo_type_id, current_user))
end
defp display_ammo_type(%{assigns: %{ammo_type: ammo_type}} = socket) do
socket |> display_ammo_type(ammo_type)
end

View File

@ -11,8 +11,8 @@ defmodule CanneryWeb.ContainerLive.Show do
alias Phoenix.LiveView.Socket
@impl true
def mount(_params, _session, socket),
do: {:ok, socket |> assign(show_used: false, view_table: false)}
def mount(_params, _session, %{assigns: %{live_action: live_action}} = socket),
do: {:ok, socket |> assign(show_used: false, view_table: live_action == :table)}
@impl true
def handle_params(
@ -21,7 +21,9 @@ defmodule CanneryWeb.ContainerLive.Show do
%{assigns: %{current_user: current_user, live_action: live_action}} = socket
) do
socket =
socket |> assign(view_table: live_action == :table) |> render_container(id, current_user)
socket
|> assign(view_table: live_action == :table)
|> render_container(id, current_user)
{:noreply, socket}
end
@ -102,7 +104,7 @@ defmodule CanneryWeb.ContainerLive.Show do
do: Routes.container_show_path(Endpoint, :show, container),
else: Routes.container_show_path(Endpoint, :table, container)
{:noreply, socket |> assign(view_table: !view_table) |> push_patch(to: new_path)}
{:noreply, socket |> push_patch(to: new_path)}
end
@spec render_container(Socket.t(), Container.id(), User.t()) :: Socket.t()

View File

@ -663,13 +663,13 @@ msgid "Loading..."
msgstr "Lädt..."
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr "%{name} bearbeiten"
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr "Editiere %{name} Tags"
@ -1077,7 +1077,7 @@ msgstr "UPC"
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}"
msgstr "%{name} bearbeiten"

View File

@ -29,7 +29,7 @@ msgid "Container must be empty before deleting"
msgstr "Behälter muss vor dem Löschen leer sein"
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr "Konnte %{name} nicht löschen: %{error}"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} erfolgreich erstellt"
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -51,7 +51,7 @@ msgid "%{name} enabled succesfully"
msgstr "%{name} erfolgreich aktiviert"
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr "%{name} wurde gelöscht"
@ -193,7 +193,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr "%{name} erfolgreich hinzugefügt"
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr "%{tag_name} wurde von %{container_name} entfernt"

View File

@ -646,13 +646,13 @@ msgid "Loading..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -1060,7 +1060,7 @@ msgstr ""
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format
msgid "Edit %{ammo_type_name}"
msgstr ""

View File

@ -647,13 +647,13 @@ msgid "Loading..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -1061,7 +1061,7 @@ msgstr ""
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}"
msgstr ""

View File

@ -16,7 +16,7 @@ msgid "Container must be empty before deleting"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr ""

View File

@ -20,7 +20,7 @@ msgid "%{name} created successfully"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -39,7 +39,7 @@ msgid "%{name} enabled succesfully"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr ""
@ -173,7 +173,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr ""
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr ""

View File

@ -16,7 +16,7 @@ msgid "Container must be empty before deleting"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr ""

View File

@ -661,13 +661,13 @@ msgid "Loading..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -1075,7 +1075,7 @@ msgstr ""
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}"
msgstr ""

View File

@ -29,7 +29,7 @@ msgid "Container must be empty before deleting"
msgstr "El contenedor debe estar vacío antes de ser borrado"
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr "No se pudo eliminar %{name}: %{error}"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} creado exitosamente"
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -51,7 +51,7 @@ msgid "%{name} enabled succesfully"
msgstr "%{name} activado exitosamente"
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr "%{name} ha sido borrado"
@ -192,7 +192,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr "%{name} añadido exitosamente"
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr "se ha removido %{tag_name} de %{container_name}"

View File

@ -665,13 +665,13 @@ msgid "Loading..."
msgstr "Chargement en cours…"
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr "Éditer %{name}"
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr "Éditer les tags de %{name}"
@ -1080,7 +1080,7 @@ msgstr "UPC"
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}"
msgstr "Éditer %{name}"

View File

@ -29,7 +29,7 @@ msgid "Container must be empty before deleting"
msgstr "Le conteneur doit être vide pour être supprimé"
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr "Impossible de supprimer %{name} : %{error}"

View File

@ -32,7 +32,7 @@ msgid "%{name} created successfully"
msgstr "%{name} créé· avec succès"
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -51,7 +51,7 @@ msgid "%{name} enabled succesfully"
msgstr "%{name} activé·e avec succès"
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr "%{name} a été supprimé·e"
@ -194,7 +194,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr "%{name} a été ajouté avec succès"
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr "%{tag_name} a été retiré de %{container_name}"

View File

@ -657,13 +657,13 @@ msgid "Loading..."
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:27
#: lib/cannery_web/live/container_live/show.ex:124
#: lib/cannery_web/live/container_live/show.ex:126
#, elixir-autogen, elixir-format
msgid "Edit %{name}"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:65
#: lib/cannery_web/live/container_live/show.ex:125
#: lib/cannery_web/live/container_live/show.ex:127
#, elixir-autogen, elixir-format
msgid "Edit %{name} tags"
msgstr ""
@ -1071,7 +1071,7 @@ msgstr ""
msgid "Average CPR"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/show.ex:117
#: lib/cannery_web/live/ammo_type_live/show.ex:120
#, elixir-autogen, elixir-format, fuzzy
msgid "Edit %{ammo_type_name}"
msgstr ""

View File

@ -30,7 +30,7 @@ msgid "Container must be empty before deleting"
msgstr "Caithfidh an coimeádán a bheidh follamh roimh scriosadh"
#: lib/cannery_web/live/container_live/index.ex:88
#: lib/cannery_web/live/container_live/show.ex:75
#: lib/cannery_web/live/container_live/show.ex:77
#, elixir-autogen, elixir-format
msgid "Could not delete %{name}: %{error}"
msgstr "Ní feidir %{name} a scriosadh: %{error}"

View File

@ -30,7 +30,7 @@ msgid "%{name} created successfully"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -49,7 +49,7 @@ msgid "%{name} enabled succesfully"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr ""
@ -183,7 +183,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr ""
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr ""

View File

@ -19,7 +19,7 @@ msgid "%{name} created successfully"
msgstr ""
#: lib/cannery_web/live/ammo_type_live/index.ex:47
#: lib/cannery_web/live/ammo_type_live/show.ex:56
#: lib/cannery_web/live/ammo_type_live/show.ex:55
#: lib/cannery_web/live/invite_live/index.ex:53
#: lib/cannery_web/live/invite_live/index.ex:133
#: lib/cannery_web/live/tag_live/index.ex:38
@ -38,7 +38,7 @@ msgid "%{name} enabled succesfully"
msgstr ""
#: lib/cannery_web/live/container_live/index.ex:81
#: lib/cannery_web/live/container_live/show.ex:65
#: lib/cannery_web/live/container_live/show.ex:67
#, elixir-autogen, elixir-format
msgid "%{name} has been deleted"
msgstr ""
@ -172,7 +172,7 @@ msgstr ""
msgid "%{name} added successfully"
msgstr ""
#: lib/cannery_web/live/container_live/show.ex:41
#: lib/cannery_web/live/container_live/show.ex:43
#, elixir-autogen, elixir-format
msgid "%{tag_name} has been removed from %{container_name}"
msgstr ""