diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index dde1679..ca87b91 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -103,153 +103,173 @@ defmodule ChiyaWeb.PublicComponents do def note_list(assigns) do case assigns.layout do :gallery -> - ~H""" - - """ + note_list_gallery(assigns) :microblog -> - ~H""" -
- <%= for note <- assigns.notes do %> -
- <% image = main_image(note) %> - <%= if image do %> -
- -
- <% end %> + note_list_microblog(assigns) -
- <%= raw(render(note.content)) %> -
- -
- - <.divider /> - <% end %> -
- """ - - # default, show headings only _ -> - ~H""" -
- <%= for note <- assigns.notes do %> - - - <%= note.name %> - - <%= pretty_date(note.published_at) %> - - <% end %> -
- """ + note_list_headers(assigns) end end - # def comment_form(assigns) do - # ~H""" - # <.simple_form :let={f} for={@changeset} action="" class="bg-theme-background -m-3"> - # <.error :if={@changeset.action}> - # Oops, something went wrong! Please check the errors below. - # - # <.input - # field={f[:author_name]} - # type="text" - # placeholder="Name" - # class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/40 dark:placeholder-theme-base/60 dark:focus:border-theme-base/60 dark:focus:border-theme-base/60" - # /> - # <.input - # field={f[:content]} - # type="textarea" - # placeholder="Content" - # rows="3" - # class="bg-theme-background dark:bg-theme-background border-theme-base/20 dark:border-theme-base/20 text-theme-base dark:text-theme-base placeholder-theme-base/60 dark:placeholder-theme-base/60 focus:border-theme-base/60 dark:focus:border-theme-base/60" - # /> - # <.input field={f[:note_id]} type="hidden" /> - # <:actions> - # <.button>Submit Comment - # - # - # """ - # end + def note_list_headers(assigns) do + ~H""" +
+ <%= for note <- assigns.notes do %> + + + <%= note.name %> + + <%= pretty_date(note.published_at) %> + + <% end %> +
+ """ + end - # def comment_list(assigns) do - # ~H""" - # <%= if not Enum.empty?(assigns.note.comments) do %> - # <.line /> + attr :note, :map, required: true - #

<%= Enum.count(assigns.note.comments) %> Comments

+ def note_list_microblog(assigns) do + ~H""" +
+ <%= for note <- assigns.notes do %> +
+ <.featured_images note={note} /> - # - # <% else %> - # <.line /> +
+ <%= raw(render(note.content)) %> +
+
+ + <.dot /> + Permalink + <%= if not Enum.empty?(note.images) do %> + <.dot /> + <.icon name="hero-photo" /> + <% end %> +
+
- #

No comments yet.

- # <% end %> - # """ - # end + <.divider /> + <% end %> +
+ """ + end + + def note_list_gallery(assigns) do + ~H""" + + """ + end + + def featured_images(assigns) do + images = main_images(assigns.note) + + case Enum.count(images) do + 0 -> + ~H""" +
+ """ + + 1 -> + assigns = assign(assigns, :image, List.first(images)) + + ~H""" +
+ +
+ """ + + 2 -> + assigns = + assigns + |> assign(:first, Enum.at(images, 0)) + |> assign(:second, Enum.at(images, 1)) + + ~H""" +
+ + +
+ """ + + 3 -> + assigns = + assigns + |> assign(:first, Enum.at(images, 0)) + |> assign(:second, Enum.at(images, 1)) + |> assign(:third, Enum.at(images, 2)) + + ~H""" +
+ + + +
+ """ + end + end defp gallery_name(note), do: "gallery-#{note.id}" - defp main_image(note), - do: - note.images - |> Enum.filter(fn image -> image.featured end) - |> List.first() + defp main_images(note), + do: Enum.filter(note.images, fn image -> image.featured end) end