add recent artwork to profile page

This commit is contained in:
byte[] 2019-12-07 17:07:53 -05:00
parent a4197ee8c3
commit 823e44495d
3 changed files with 25 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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)