use live navigation to update state
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
shibao 2023-03-16 17:49:45 -04:00
parent 3acecb9a93
commit ce07cc2569
15 changed files with 57 additions and 36 deletions

View File

@ -4,25 +4,40 @@ defmodule CanneryWeb.ContainerLive.EditTagsComponent do
"""
use CanneryWeb, :live_component
alias Cannery.{Accounts.User, Containers, Containers.Container, Repo, Tags, Tags.Tag}
alias Cannery.{Accounts.User, Containers, Containers.Container, Tags, Tags.Tag}
alias Phoenix.LiveView.Socket
@impl true
@spec update(
%{:container => Container.t(), :current_user => User.t(), optional(any) => any},
%{
:container => Container.t(),
:current_path => String.t(),
:current_user => User.t(),
optional(any) => any
},
Socket.t()
) :: {:ok, Socket.t()}
def update(%{container: container, current_user: current_user} = assigns, socket) do
def update(
%{container: _container, current_path: _current_path, current_user: current_user} =
assigns,
socket
) do
tags = Tags.list_tags(current_user)
container = container |> Repo.preload(:tags)
{:ok, socket |> assign(assigns) |> assign(tags: tags, container: container)}
{:ok, socket |> assign(assigns) |> assign(:tags, tags)}
end
@impl true
def handle_event(
"save",
%{"tag" => %{"tag_id" => tag_id}},
%{assigns: %{tags: tags, container: container, current_user: current_user}} = socket
%{
assigns: %{
tags: tags,
container: container,
current_user: current_user,
current_path: current_path
}
} = socket
) do
socket =
case tags |> Enum.find(fn %{id: id} -> tag_id == id end) do
@ -32,19 +47,24 @@ defmodule CanneryWeb.ContainerLive.EditTagsComponent do
%{name: tag_name} = tag ->
_container_tag = Containers.add_tag!(container, tag, current_user)
container = container |> Repo.preload(:tags, force: true)
prompt = dgettext("prompts", "%{name} added successfully", name: tag_name)
socket |> put_flash(:info, prompt) |> assign(container: container)
socket |> put_flash(:info, prompt) |> push_patch(to: current_path)
end
{:noreply, socket}
end
@impl true
def handle_event(
"delete",
%{"tag-id" => tag_id},
%{assigns: %{tags: tags, container: container, current_user: current_user}} = socket
%{
assigns: %{
tags: tags,
container: container,
current_user: current_user,
current_path: current_path
}
} = socket
) do
socket =
case tags |> Enum.find(fn %{id: id} -> tag_id == id end) do
@ -54,9 +74,8 @@ defmodule CanneryWeb.ContainerLive.EditTagsComponent do
%{name: tag_name} = tag ->
_container_tag = Containers.remove_tag!(container, tag, current_user)
container = container |> Repo.preload(:tags, force: true)
prompt = dgettext("prompts", "%{name} removed successfully", name: tag_name)
socket |> put_flash(:info, prompt) |> assign(container: container)
socket |> put_flash(:info, prompt) |> push_patch(to: current_path)
end
{:noreply, socket}

View File

@ -167,6 +167,7 @@
title={@page_title}
action={@live_action}
container={@container}
current_path={Routes.container_index_path(Endpoint, :edit_tags, @container)}
current_user={@current_user}
/>
</.modal>

View File

@ -161,6 +161,7 @@
action={@live_action}
container={@container}
return_to={Routes.container_show_path(Endpoint, :show, @container)}
current_path={Routes.container_show_path(Endpoint, :edit_tags, @container)}
current_user={@current_user}
/>
</.modal>

View File

@ -147,7 +147,7 @@ msgstr "Muss ein @ Zeichen und keine Leerzeichen haben"
msgid "Tag not found"
msgstr "Tag nicht gefunden"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr "Tag konnte nicht hinzugefügt werden"
@ -165,7 +165,7 @@ msgstr ""
"Sie müssen ihr Nutzerkonto bestätigen und einloggen, um diese Seite "
"anzuzeigen."
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format
msgid "Tag could not be removed"
msgstr "Tag konnte nicht gelöscht werden"

View File

@ -151,7 +151,7 @@ msgstr ""
"Sind Sie sicher, dass sie %{tag_name} Tag von %{container_name} entfernen "
"wollen?"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr "%{name} erfolgreich hinzugefügt"
@ -208,7 +208,7 @@ msgstr "Munition erfolgreich zu %{name} verschoben"
msgid "Copied to clipboard"
msgstr "Der Zwischenablage hinzugefügt"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format
msgid "%{name} removed successfully"
msgstr "%{name} erfolgreich entfernt"

View File

@ -134,7 +134,7 @@ msgstr ""
msgid "Tag not found"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr ""
@ -150,7 +150,7 @@ msgstr ""
msgid "You must confirm your account and log in to access this page."
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format, fuzzy
msgid "Tag could not be removed"
msgstr ""

View File

@ -130,7 +130,7 @@ msgstr ""
msgid "Are you sure you want to remove the %{tag_name} tag from %{container_name}?"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr ""
@ -187,7 +187,7 @@ msgstr ""
msgid "Copied to clipboard"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format, fuzzy
msgid "%{name} removed successfully"
msgstr ""

View File

@ -133,7 +133,7 @@ msgstr ""
msgid "Tag not found"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr ""
@ -149,7 +149,7 @@ msgstr ""
msgid "You must confirm your account and log in to access this page."
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format
msgid "Tag could not be removed"
msgstr ""

View File

@ -149,7 +149,7 @@ msgstr "debe tener el signo @ y no contener espacios"
msgid "Tag not found"
msgstr "Etiqueta no encontrada"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr "No se ha podido añadir la etiqueta"
@ -165,7 +165,7 @@ msgstr "El recuento debe dar al menos 1"
msgid "You must confirm your account and log in to access this page."
msgstr "Debe confirmar su cuenta e iniciar sesión para acceder a esta página."
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format
msgid "Tag could not be removed"
msgstr "La etiqueta no pudo ser eliminada"

View File

@ -150,7 +150,7 @@ msgid "Are you sure you want to remove the %{tag_name} tag from %{container_name
msgstr ""
"Está seguro que desea remover la etiqueta %{tag_name} de %{container_name}?"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr "%{name} añadido exitosamente"
@ -207,7 +207,7 @@ msgstr "Munición movida a %{name} exitosamente"
msgid "Copied to clipboard"
msgstr "Copiado al portapapeles"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format
msgid "%{name} removed successfully"
msgstr "%{name} eliminado exitosamente"

View File

@ -148,7 +148,7 @@ msgstr "doit contenir le symbole @ et aucune espace"
msgid "Tag not found"
msgstr "Tag pas trouvé"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr "Le tag na pas pu être ajouté"
@ -166,7 +166,7 @@ msgstr ""
"Vous devez dabord confirmer votre compte et vous connecter pour accéder à "
"cette page."
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format
msgid "Tag could not be removed"
msgstr "Le tag na pas pu être retiré"

View File

@ -152,7 +152,7 @@ msgstr ""
"Êtes-vous certain·e de vouloir retirer le tag %{tag_name} de "
"%{container_name}?"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr "%{name} a été ajouté avec succès"
@ -209,7 +209,7 @@ msgstr "Munition déplacée à %{name} avec succès"
msgid "Copied to clipboard"
msgstr "Copié dans le presse-papier"
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format
msgid "%{name} removed successfully"
msgstr "%{name} retiré avec succès"

View File

@ -149,7 +149,7 @@ msgstr ""
msgid "Tag not found"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:30
#: lib/cannery_web/live/container_live/edit_tags_component.ex:45
#, elixir-autogen, elixir-format
msgid "Tag could not be added"
msgstr ""
@ -165,7 +165,7 @@ msgstr ""
msgid "You must confirm your account and log in to access this page."
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:52
#: lib/cannery_web/live/container_live/edit_tags_component.ex:72
#, elixir-autogen, elixir-format
msgid "Tag could not be removed"
msgstr ""

View File

@ -141,7 +141,7 @@ msgstr ""
msgid "Are you sure you want to remove the %{tag_name} tag from %{container_name}?"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr ""
@ -198,7 +198,7 @@ msgstr ""
msgid "Copied to clipboard"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format
msgid "%{name} removed successfully"
msgstr ""

View File

@ -130,7 +130,7 @@ msgstr ""
msgid "Are you sure you want to remove the %{tag_name} tag from %{container_name}?"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:36
#: lib/cannery_web/live/container_live/edit_tags_component.ex:50
#, elixir-autogen, elixir-format
msgid "%{name} added successfully"
msgstr ""
@ -187,7 +187,7 @@ msgstr ""
msgid "Copied to clipboard"
msgstr ""
#: lib/cannery_web/live/container_live/edit_tags_component.ex:58
#: lib/cannery_web/live/container_live/edit_tags_component.ex:77
#, elixir-autogen, elixir-format
msgid "%{name} removed successfully"
msgstr ""