work on contexts

This commit is contained in:
2022-11-24 12:44:34 -05:00
parent a0a0697f2d
commit cc11491106
18 changed files with 771 additions and 249 deletions

View File

@ -9,13 +9,33 @@ defmodule MemexWeb.ContextLive.Show do
end
@impl true
def handle_params(%{"id" => id}, _, socket) do
def handle_params(
%{"id" => id},
_,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:context, Contexts.get_context!(id))}
|> assign(:page_title, page_title(live_action))
|> assign(:context, Contexts.get_context!(id, current_user))}
end
defp page_title(:show), do: "show context"
defp page_title(:edit), do: "edit context"
@impl true
def handle_event(
"delete",
_params,
%{assigns: %{context: context, current_user: current_user}} = socket
) do
{:ok, %{title: title}} = Contexts.delete_context(context, current_user)
socket =
socket
|> put_flash(:info, gettext("%{title} deleted", title: title))
|> push_navigate(to: Routes.context_index_path(Endpoint, :index))
{:noreply, socket}
end
defp page_title(:show), do: gettext("show context")
defp page_title(:edit), do: gettext("edit context")
end