From 7151ed9f9d37a46b19309e3ab7cd9d7f91927981 Mon Sep 17 00:00:00 2001 From: Inhji Date: Tue, 25 Jul 2023 06:33:46 +0200 Subject: [PATCH 1/4] link tags, channels, linked notes in note_show_live --- lib/chiya/notes/note.ex | 4 ++++ lib/chiya_web/live/note_show_live.ex | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/chiya/notes/note.ex b/lib/chiya/notes/note.ex index 63cc753..8ce6c4a 100644 --- a/lib/chiya/notes/note.ex +++ b/lib/chiya/notes/note.ex @@ -55,6 +55,10 @@ defmodule Chiya.Notes.Note do ~p"/note/#{note.slug}" end + def note_path_admin(note) do + ~p"/admin/note/#{note.slug}" + end + def note_url(note) do Phoenix.VerifiedRoutes.url(~p"/note/#{note.slug}") end diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index 8027d88..0a75f5c 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -3,14 +3,12 @@ defmodule ChiyaWeb.NoteShowLive do alias Chiya.Notes alias Chiya.Notes.NoteImage + import Phoenix.HTML.Tag @accepted_extensions ~w(.jpg .jpeg .gif .png .webp) @impl true def render(assigns) do - channels = Enum.map_join(assigns.note.channels, ", ", fn c -> c.name end) - assigns = assign(assigns, :channels, channels) - ~H""" <.header> <%= @note.name %> @@ -43,7 +41,7 @@ defmodule ChiyaWeb.NoteShowLive do <:item title="Published at"> <%= pretty_date(@note.published_at) %> (<%= from_now(@note.published_at) %>) - <:item title="Channels"><%= @channels %> + <:item title="Channels"><%= note_channels(@note.channels) %> <:item title="Kind"><%= @note.kind %> <:item title="Url"><%= @note.url %> <:item title="Tags"><%= note_tags(@note.tags) %> @@ -187,6 +185,20 @@ defmodule ChiyaWeb.NoteShowLive do {:noreply, assign(socket, :note, Notes.get_note_preloaded!(socket.assigns.note.id))} end - defp note_links(notes), do: Enum.map_join(notes, ", ", fn n -> n.name end) - defp note_tags(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end) + defp note_links(notes), do: content_tag(:ul, do: Enum.map(notes, ¬e_link/1)) + + defp note_link(note) do + content_tag(:li, do: content_tag(:a, note.name, href: Chiya.Notes.Note.note_path_admin(note))) + end + + defp note_tags(tags), do: content_tag(:ul, do: Enum.map(tags, ¬e_tag/1)) + + defp note_tag(tag), + do: content_tag(:li, do: content_tag(:a, tag.name, href: ~p"/tagged-with/#{tag.slug}")) + + defp note_channels(channels), do: content_tag(:ul, do: Enum.map(channels, ¬e_channel/1)) + + defp note_channel(channel), + do: + content_tag(:li, do: content_tag(:a, channel.name, href: ~p"/admin/channels/#{channel.id}")) end From 23dba2b0fd7f7dbdd1ba00ecc9aa0222be4457cd Mon Sep 17 00:00:00 2001 From: Inhji Date: Tue, 25 Jul 2023 06:54:53 +0200 Subject: [PATCH 2/4] add images to note page --- lib/chiya_web/controllers/page_html/note.html.heex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index 0185eaf..a63539a 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -16,6 +16,10 @@ <% end %> + + <%= if has_outline?(@note) do %>