diff --git a/lib/philomena_web/controllers/profile_controller.ex b/lib/philomena_web/controllers/profile_controller.ex index 7a6e1302..e222c649 100644 --- a/lib/philomena_web/controllers/profile_controller.ex +++ b/lib/philomena_web/controllers/profile_controller.ex @@ -34,6 +34,9 @@ defmodule PhilomenaWeb.ProfileController do pagination: %{page_number: 1, page_size: 6} ) + tags = tags(conn.assigns.user.public_links) + recent_artwork = recent_artwork(conn, tags) + recent_comments = Comment.search_records( %{ @@ -102,6 +105,7 @@ defmodule PhilomenaWeb.ProfileController do user: user, interactions: interactions, commission_information: commission_information, + recent_artwork: recent_artwork, recent_uploads: recent_uploads, recent_faves: recent_faves, recent_comments: recent_comments, @@ -109,6 +113,7 @@ defmodule PhilomenaWeb.ProfileController do recent_galleries: recent_galleries, statistics: statistics, about_me: about_me, + tags: tags, layout_class: "layout--medium" ) end @@ -146,4 +151,19 @@ defmodule PhilomenaWeb.ProfileController do defp commission_info(%{information: info}, conn) when info not in [nil, ""], do: Renderer.render_one(%{body: info}, conn) defp commission_info(_commission, _conn), do: "" + + defp tags([]), do: [] + defp tags(links), do: Enum.map(& &1.tag) |> Enum.reject(&is_nil/1) + + defp recent_artwork(_conn, []), do: [] + defp recent_artwork(conn, tags) do + {images, _tags} = + ImageLoader.query( + conn, + %{terms: %{tag_ids: Enum.map(tags, & &1.id)}}, + pagination: %{page_number: 1, page_size: 6} + ) + + images + end end diff --git a/lib/philomena_web/templates/profile/show.html.slime b/lib/philomena_web/templates/profile/show.html.slime index 8077732d..2aa8eb64 100644 --- a/lib/philomena_web/templates/profile/show.html.slime +++ b/lib/philomena_web/templates/profile/show.html.slime @@ -75,6 +75,7 @@ .column-layout__main = render PhilomenaWeb.ProfileView, "_statistics.html", user: @user, statistics: @statistics, conn: @conn + = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Artwork", images: @recent_artwork, view_all_path: Routes.search_path(@conn, :index, q: tag_disjunction(@tags)), conn: @conn = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Uploads", images: @recent_uploads, view_all_path: Routes.search_path(@conn, :index, q: "uploader_id:#{@user.id}"), conn: @conn = render PhilomenaWeb.ProfileView, "_recent_images.html", title: "Recent Favorites", images: @recent_faves, view_all_path: Routes.search_path(@conn, :index, q: "faved_by_id:#{@user.id}"), conn: @conn = render PhilomenaWeb.ProfileView, "_recent_galleries.html", galleries: @recent_galleries, user: @user, conn: @conn diff --git a/lib/philomena_web/views/profile_view.ex b/lib/philomena_web/views/profile_view.ex index 05cff902..5344e755 100644 --- a/lib/philomena_web/views/profile_view.ex +++ b/lib/philomena_web/views/profile_view.ex @@ -46,6 +46,10 @@ defmodule PhilomenaWeb.ProfileView do end end + def tag_disjunction(tags) do + Enum.map_join(tags, " || ", & &1.name) + end + defp zero_div(_num, 0), do: 0 defp zero_div(num, den), do: div(num, den)