improve table route navigation

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

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()