better code style
This commit is contained in:
		| @@ -68,7 +68,7 @@ defmodule MemexWeb.NoteLive.FormComponent do | ||||
|           |> push_navigate(to: return_to) | ||||
|  | ||||
|         {:error, %Changeset{} = changeset} -> | ||||
|           assign(socket, changeset: changeset) | ||||
|           assign(socket, :changeset, changeset) | ||||
|       end | ||||
|  | ||||
|     {:noreply, socket} | ||||
|   | ||||
| @@ -4,11 +4,11 @@ defmodule MemexWeb.NoteLive.Index do | ||||
|  | ||||
|   @impl true | ||||
|   def mount(%{"search" => search}, _session, socket) do | ||||
|     {:ok, socket |> assign(search: search) |> display_notes()} | ||||
|     {:ok, socket |> assign(:search, search) |> display_notes()} | ||||
|   end | ||||
|  | ||||
|   def mount(_params, _session, socket) do | ||||
|     {:ok, socket |> assign(search: nil) |> display_notes()} | ||||
|     {:ok, socket |> assign(:search, nil) |> display_notes()} | ||||
|   end | ||||
|  | ||||
|   @impl true | ||||
| @@ -20,29 +20,37 @@ defmodule MemexWeb.NoteLive.Index do | ||||
|     %{slug: slug} = note = Notes.get_note_by_slug(slug, current_user) | ||||
|  | ||||
|     socket | ||||
|     |> assign(page_title: gettext("edit %{slug}", slug: slug)) | ||||
|     |> assign(note: note) | ||||
|     |> assign( | ||||
|       note: note, | ||||
|       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 note")) | ||||
|     |> assign(note: %Note{visibility: :private, user_id: current_user_id}) | ||||
|     |> assign( | ||||
|       note: %Note{visibility: :private, user_id: current_user_id}, | ||||
|       page_title: gettext("new note") | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   defp apply_action(socket, :index, _params) do | ||||
|     socket | ||||
|     |> assign(page_title: gettext("notes")) | ||||
|     |> assign(search: nil) | ||||
|     |> assign(note: nil) | ||||
|     |> assign( | ||||
|       note: nil, | ||||
|       page_title: gettext("notes"), | ||||
|       search: nil | ||||
|     ) | ||||
|     |> display_notes() | ||||
|   end | ||||
|  | ||||
|   defp apply_action(socket, :search, %{"search" => search}) do | ||||
|     socket | ||||
|     |> assign(page_title: gettext("notes")) | ||||
|     |> assign(search: search) | ||||
|     |> assign(note: nil) | ||||
|     |> assign( | ||||
|       note: nil, | ||||
|       page_title: gettext("notes"), | ||||
|       search: search | ||||
|     ) | ||||
|     |> display_notes() | ||||
|   end | ||||
|  | ||||
| @@ -53,7 +61,7 @@ defmodule MemexWeb.NoteLive.Index do | ||||
|  | ||||
|     socket = | ||||
|       socket | ||||
|       |> assign(notes: Notes.list_notes(current_user)) | ||||
|       |> assign(:notes, Notes.list_notes(current_user)) | ||||
|       |> put_flash(:info, gettext("%{slug} deleted", slug: slug)) | ||||
|  | ||||
|     {:noreply, socket} | ||||
| @@ -67,12 +75,11 @@ defmodule MemexWeb.NoteLive.Index do | ||||
|     {:noreply, socket |> push_patch(to: ~p"/notes/#{search_term}")} | ||||
|   end | ||||
|  | ||||
|   defp display_notes(%{assigns: %{current_user: current_user, search: search}} = socket) | ||||
|        when not (current_user |> is_nil()) do | ||||
|     socket |> assign(notes: Notes.list_notes(search, current_user)) | ||||
|   defp display_notes(%{assigns: %{current_user: %{} = current_user, search: search}} = socket) do | ||||
|     socket |> assign(:notes, Notes.list_notes(search, current_user)) | ||||
|   end | ||||
|  | ||||
|   defp display_notes(%{assigns: %{search: search}} = socket) do | ||||
|     socket |> assign(notes: Notes.list_public_notes(search)) | ||||
|     socket |> assign(:notes, Notes.list_public_notes(search)) | ||||
|   end | ||||
| end | ||||
|   | ||||
| @@ -21,8 +21,10 @@ defmodule MemexWeb.NoteLive.Show do | ||||
|  | ||||
|     socket = | ||||
|       socket | ||||
|       |> assign(:page_title, page_title(live_action, note)) | ||||
|       |> assign(:note, note) | ||||
|       |> assign( | ||||
|         note: note, | ||||
|         page_title: page_title(live_action, note) | ||||
|       ) | ||||
|  | ||||
|     {:noreply, socket} | ||||
|   end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user