fix page titles

This commit is contained in:
shibao 2022-11-24 17:44:01 -05:00
parent 44c8cf77bb
commit e9360fb3d5
7 changed files with 39 additions and 54 deletions

View File

@ -14,10 +14,14 @@ defmodule MemexWeb.ContextLive.Show do
_, _,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket %{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do ) do
{:noreply, context = Contexts.get_context!(id, current_user)
socket
|> assign(:page_title, page_title(live_action)) socket =
|> assign(:context, Contexts.get_context!(id, current_user))} socket
|> assign(:page_title, page_title(live_action, context))
|> assign(:context, context)
{:noreply, socket}
end end
@impl true @impl true
@ -36,8 +40,8 @@ defmodule MemexWeb.ContextLive.Show do
{:noreply, socket} {:noreply, socket}
end end
defp page_title(:show), do: gettext("show context") defp page_title(:show, %{title: title}), do: title
defp page_title(:edit), do: gettext("edit context") defp page_title(:edit, %{title: title}), do: gettext("edit %{title}", title: title)
@spec is_owner_or_admin?(Context.t(), User.t()) :: boolean() @spec is_owner_or_admin?(Context.t(), User.t()) :: boolean()
defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -14,10 +14,14 @@ defmodule MemexWeb.NoteLive.Show do
_, _,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket %{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do ) do
{:noreply, note = Notes.get_note!(id, current_user)
socket
|> assign(:page_title, page_title(live_action)) socket =
|> assign(:note, Notes.get_note!(id, current_user))} socket
|> assign(:page_title, page_title(live_action, note))
|> assign(:note, note)
{:noreply, socket}
end end
@impl true @impl true
@ -36,8 +40,8 @@ defmodule MemexWeb.NoteLive.Show do
{:noreply, socket} {:noreply, socket}
end end
defp page_title(:show), do: gettext("show note") defp page_title(:show, %{title: title}), do: title
defp page_title(:edit), do: gettext("edit note") defp page_title(:edit, %{title: title}), do: gettext("edit %{title}", title: title)
@spec is_owner_or_admin?(Note.t(), User.t()) :: boolean() @spec is_owner_or_admin?(Note.t(), User.t()) :: boolean()
defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -14,10 +14,14 @@ defmodule MemexWeb.PipelineLive.Show do
_, _,
%{assigns: %{live_action: live_action, current_user: current_user}} = socket %{assigns: %{live_action: live_action, current_user: current_user}} = socket
) do ) do
{:noreply, pipeline = Pipelines.get_pipeline!(id, current_user)
socket
|> assign(:page_title, page_title(live_action)) socket =
|> assign(:pipeline, Pipelines.get_pipeline!(id, current_user))} socket
|> assign(:page_title, page_title(live_action, pipeline))
|> assign(:pipeline, pipeline)
{:noreply, socket}
end end
@impl true @impl true
@ -36,8 +40,8 @@ defmodule MemexWeb.PipelineLive.Show do
{:noreply, socket} {:noreply, socket}
end end
defp page_title(:show), do: gettext("show pipeline") defp page_title(:show, %{title: title}), do: title
defp page_title(:edit), do: gettext("edit pipeline") defp page_title(:edit, %{title: title}), do: gettext("edit %{title}", title: title)
@spec is_owner_or_admin?(Pipeline.t(), User.t()) :: boolean() @spec is_owner_or_admin?(Pipeline.t(), User.t()) :: boolean()
defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true defp is_owner_or_admin?(%{user_id: user_id}, %{id: user_id}), do: true

View File

@ -18,11 +18,11 @@ msgid "%{title} created"
msgstr "" msgstr ""
#: lib/memex_web/live/context_live/index.ex:57 #: lib/memex_web/live/context_live/index.ex:57
#: lib/memex_web/live/context_live/show.ex:33 #: lib/memex_web/live/context_live/show.ex:37
#: lib/memex_web/live/note_live/index.ex:57 #: lib/memex_web/live/note_live/index.ex:57
#: lib/memex_web/live/note_live/show.ex:33 #: lib/memex_web/live/note_live/show.ex:37
#: lib/memex_web/live/pipeline_live/index.ex:57 #: lib/memex_web/live/pipeline_live/index.ex:57
#: lib/memex_web/live/pipeline_live/show.ex:33 #: lib/memex_web/live/pipeline_live/show.ex:37
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "%{title} deleted" msgid "%{title} deleted"
msgstr "" msgstr ""
@ -184,8 +184,11 @@ msgid "document your processes, attaching contexts to each step"
msgstr "" msgstr ""
#: lib/memex_web/live/context_live/index.ex:23 #: lib/memex_web/live/context_live/index.ex:23
#: lib/memex_web/live/context_live/show.ex:44
#: lib/memex_web/live/note_live/index.ex:23 #: lib/memex_web/live/note_live/index.ex:23
#: lib/memex_web/live/note_live/show.ex:44
#: lib/memex_web/live/pipeline_live/index.ex:23 #: lib/memex_web/live/pipeline_live/index.ex:23
#: lib/memex_web/live/pipeline_live/show.ex:44
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "edit %{title}" msgid "edit %{title}"
msgstr "" msgstr ""
@ -436,11 +439,6 @@ msgstr ""
msgid "visibility: %{visibility}" msgid "visibility: %{visibility}"
msgstr "" msgstr ""
#: lib/memex_web/live/note_live/show.ex:40
#, elixir-autogen, elixir-format
msgid "edit note"
msgstr ""
#: lib/memex_web/live/note_live/index.ex:29 #: lib/memex_web/live/note_live/index.ex:29
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "new note" msgid "new note"
@ -453,16 +451,6 @@ msgstr ""
msgid "search" msgid "search"
msgstr "" msgstr ""
#: lib/memex_web/live/note_live/show.ex:39
#, elixir-autogen, elixir-format
msgid "show note"
msgstr ""
#: lib/memex_web/live/context_live/show.ex:40
#, elixir-autogen, elixir-format
msgid "edit context"
msgstr ""
#: lib/memex_web/live/context_live/index.ex:29 #: lib/memex_web/live/context_live/index.ex:29
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "new context" msgid "new context"
@ -473,22 +461,12 @@ msgstr ""
msgid "no contexts found" msgid "no contexts found"
msgstr "" msgstr ""
#: lib/memex_web/live/context_live/show.ex:39
#, elixir-autogen, elixir-format
msgid "show context"
msgstr ""
#: lib/memex_web/components/pipelines_table_component.ex:48 #: lib/memex_web/components/pipelines_table_component.ex:48
#: lib/memex_web/live/pipeline_live/form_component.html.heex:23 #: lib/memex_web/live/pipeline_live/form_component.html.heex:23
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "description" msgid "description"
msgstr "" msgstr ""
#: lib/memex_web/live/pipeline_live/show.ex:40
#, elixir-autogen, elixir-format
msgid "edit pipeline"
msgstr ""
#: lib/memex_web/live/pipeline_live/index.ex:29 #: lib/memex_web/live/pipeline_live/index.ex:29
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "new pipeline" msgid "new pipeline"
@ -498,8 +476,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "no pipelines found" msgid "no pipelines found"
msgstr "" msgstr ""
#: lib/memex_web/live/pipeline_live/show.ex:39
#, elixir-autogen, elixir-format
msgid "show pipeline"
msgstr ""

View File

@ -95,7 +95,7 @@ defmodule MemexWeb.ContextLiveTest do
test "displays context", %{conn: conn, context: context} do test "displays context", %{conn: conn, context: context} do
{:ok, _show_live, html} = live(conn, Routes.context_show_path(conn, :show, context)) {:ok, _show_live, html} = live(conn, Routes.context_show_path(conn, :show, context))
assert html =~ "show context" assert html =~ "context"
assert html =~ context.content assert html =~ context.content
end end

View File

@ -95,7 +95,7 @@ defmodule MemexWeb.NoteLiveTest do
test "displays note", %{conn: conn, note: note} do test "displays note", %{conn: conn, note: note} do
{:ok, _show_live, html} = live(conn, Routes.note_show_path(conn, :show, note)) {:ok, _show_live, html} = live(conn, Routes.note_show_path(conn, :show, note))
assert html =~ "show note" assert html =~ "note"
assert html =~ note.content assert html =~ note.content
end end

View File

@ -98,7 +98,7 @@ defmodule MemexWeb.PipelineLiveTest do
test "displays pipeline", %{conn: conn, pipeline: pipeline} do test "displays pipeline", %{conn: conn, pipeline: pipeline} do
{:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline)) {:ok, _show_live, html} = live(conn, Routes.pipeline_show_path(conn, :show, pipeline))
assert html =~ "show pipeline" assert html =~ "pipeline"
assert html =~ pipeline.description assert html =~ pipeline.description
end end