better code style
This commit is contained in:
@ -69,7 +69,7 @@ defmodule MemexWeb.ContextLive.FormComponent do
|
||||
|> push_navigate(to: return_to)
|
||||
|
||||
{:error, %Changeset{} = changeset} ->
|
||||
assign(socket, changeset: changeset)
|
||||
assign(socket, :changeset, changeset)
|
||||
end
|
||||
|
||||
{:noreply, socket}
|
||||
|
@ -20,29 +20,37 @@ defmodule MemexWeb.ContextLive.Index do
|
||||
%{slug: slug} = context = Contexts.get_context_by_slug(slug, current_user)
|
||||
|
||||
socket
|
||||
|> assign(page_title: gettext("edit %{slug}", slug: slug))
|
||||
|> assign(context: context)
|
||||
|> assign(
|
||||
context: context,
|
||||
page_title: gettext("edit %{slug}", slug: slug)
|
||||
)
|
||||
end
|
||||
|
||||
defp apply_action(%{assigns: %{current_user: %{id: current_user_id}}} = socket, :new, _params) do
|
||||
socket
|
||||
|> assign(page_title: gettext("new context"))
|
||||
|> assign(context: %Context{visibility: :private, user_id: current_user_id})
|
||||
|> assign(
|
||||
context: %Context{visibility: :private, user_id: current_user_id},
|
||||
page_title: gettext("new context")
|
||||
)
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(page_title: gettext("contexts"))
|
||||
|> assign(search: nil)
|
||||
|> assign(context: nil)
|
||||
|> assign(
|
||||
context: nil,
|
||||
page_title: gettext("contexts"),
|
||||
search: nil
|
||||
)
|
||||
|> display_contexts()
|
||||
end
|
||||
|
||||
defp apply_action(socket, :search, %{"search" => search}) do
|
||||
socket
|
||||
|> assign(page_title: gettext("contexts"))
|
||||
|> assign(search: search)
|
||||
|> assign(context: nil)
|
||||
|> assign(
|
||||
context: nil,
|
||||
page_title: gettext("contexts"),
|
||||
search: search
|
||||
)
|
||||
|> display_contexts()
|
||||
end
|
||||
|
||||
@ -68,8 +76,7 @@ defmodule MemexWeb.ContextLive.Index do
|
||||
{:noreply, socket |> push_patch(to: redirect_to)}
|
||||
end
|
||||
|
||||
defp display_contexts(%{assigns: %{current_user: current_user, search: search}} = socket)
|
||||
when not (current_user |> is_nil()) do
|
||||
defp display_contexts(%{assigns: %{current_user: %{} = current_user, search: search}} = socket) do
|
||||
socket |> assign(contexts: Contexts.list_contexts(search, current_user))
|
||||
end
|
||||
|
||||
|
@ -21,8 +21,10 @@ defmodule MemexWeb.ContextLive.Show do
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:page_title, page_title(live_action, context))
|
||||
|> assign(:context, context)
|
||||
|> assign(
|
||||
context: context,
|
||||
page_title: page_title(live_action, context)
|
||||
)
|
||||
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
Reference in New Issue
Block a user