From 34a15d5fff26eca6b55858847badf1a78c84f211 Mon Sep 17 00:00:00 2001 From: Inhji Date: Thu, 13 Apr 2023 23:52:01 +0200 Subject: [PATCH] implement gallery layout for channel, first pass --- lib/chiya/channels.ex | 6 ++-- lib/chiya/notes.ex | 1 + lib/chiya_web.ex | 15 ++++---- lib/chiya_web/components/public_components.ex | 29 ++++++++++++++- .../controllers/page_html/home.html.heex | 35 +++++++++++++++++-- lib/chiya_web/live/note_show_live.ex | 2 +- 6 files changed, 75 insertions(+), 13 deletions(-) diff --git a/lib/chiya/channels.ex b/lib/chiya/channels.ex index c06e0db..f3afefd 100644 --- a/lib/chiya/channels.ex +++ b/lib/chiya/channels.ex @@ -10,11 +10,13 @@ defmodule Chiya.Channels do @preloads [:notes] @public_preloads [ - notes: + notes: { from(n in Note, where: not is_nil(n.published_at), order_by: [desc: n.published_at] - ) + ), + Chiya.Notes.note_preloads() + } ] @doc """ diff --git a/lib/chiya/notes.ex b/lib/chiya/notes.ex index 124ed4c..e4110a4 100644 --- a/lib/chiya/notes.ex +++ b/lib/chiya/notes.ex @@ -8,6 +8,7 @@ defmodule Chiya.Notes do alias Chiya.Notes.{Note, NoteImage, NoteNote, NoteTag} @preloads [:channels, :images, :links_from, :links_to, :tags] + def note_preloads(), do: @preloads @doc """ Returns the list of notes. diff --git a/lib/chiya_web.ex b/lib/chiya_web.ex index 330ed59..6de6716 100644 --- a/lib/chiya_web.ex +++ b/lib/chiya_web.ex @@ -68,6 +68,9 @@ defmodule ChiyaWeb do quote do use Phoenix.LiveComponent + # Import admin components + import ChiyaWeb.AdminComponents + unquote(html_helpers()) end end @@ -80,11 +83,11 @@ defmodule ChiyaWeb do import Phoenix.Controller, only: [get_csrf_token: 0, view_module: 1, view_template: 1] - # Include general helpers for rendering HTML - unquote(html_helpers()) - # Import admin components import ChiyaWeb.AdminComponents + + # Include general helpers for rendering HTML + unquote(html_helpers()) end end @@ -96,11 +99,11 @@ defmodule ChiyaWeb do import Phoenix.Controller, only: [get_csrf_token: 0, view_module: 1, view_template: 1] - # Include general helpers for rendering HTML - unquote(html_helpers()) - # Import public components import ChiyaWeb.PublicComponents + + # Include general helpers for rendering HTML + unquote(html_helpers()) end end diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index ef5689d..b9acf55 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -11,7 +11,34 @@ defmodule ChiyaWeb.PublicComponents do """ def line(assigns) do ~H""" -
+
+ """ + end + + @doc """ + Renders a header with title. + """ + attr :class, :string, default: nil + attr :inline, :boolean, default: false + + slot :inner_block, required: true + slot :subtitle + slot :actions + + def header(assigns) do + ~H""" +
+
+

+ <%= render_slot(@inner_block) %> + <%= render_slot(@subtitle) %> +

+

+ <%= render_slot(@subtitle) %> +

+
+
<%= render_slot(@actions) %>
+
""" end end diff --git a/lib/chiya_web/controllers/page_html/home.html.heex b/lib/chiya_web/controllers/page_html/home.html.heex index 6ae7819..4069e5e 100644 --- a/lib/chiya_web/controllers/page_html/home.html.heex +++ b/lib/chiya_web/controllers/page_html/home.html.heex @@ -23,8 +23,9 @@ <%= if @channel do %> -
- <%= for note <- @channel.notes do %> + <%= if @channel.layout == :default do %> +
+ <%= for note <- @channel.notes do %> <%= pretty_date(note.published_at) %> <% end %> -
+ + <% end %> + + <%= if @channel.layout == :gallery do %> + + <% end %> <% end %> diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index c14909a..7c5f535 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -48,7 +48,7 @@ defmodule ChiyaWeb.NoteShowLive do
<.button phx-click="delete_image" phx-value-id={image.id} data-confirm="Are you sure?">