add recent comments

This commit is contained in:
byte[] 2019-11-11 22:10:41 -05:00
parent 5b35b75b1d
commit 0f6e94d1a9
4 changed files with 51 additions and 1 deletions

View file

@ -0,0 +1,35 @@
defmodule PhilomenaWeb.CommentController do
use PhilomenaWeb, :controller
alias Philomena.{Images.Image, Comments.Comment, Textile.Renderer}
alias Philomena.Repo
import Ecto.Query
def index(conn, _params) do
comments =
Comment.search_records(
%{
query: %{
bool: %{
must: [
%{range: %{posted_at: %{gt: "now-1w"}}},
%{term: %{hidden_from_users: false}}
]
}
},
sort: %{posted_at: :desc}
},
conn.assigns.pagination,
Comment |> preload([:image, user: [awards: :badge]])
)
rendered =
comments.entries
|> Renderer.render_collection()
comments =
%{comments | entries: Enum.zip(comments.entries, rendered)}
render(conn, "index.html", comments: comments)
end
end

View file

@ -36,6 +36,7 @@ defmodule PhilomenaWeb.Router do
resources "/forums", ForumController, only: [:index, :show] do
resources "/topics", TopicController, only: [:show]
end
resources "/comments", CommentController, only: [:index]
scope "/filters", Filter, as: :filter do
resources "/current", CurrentController, only: [:update], singular: true

View file

@ -0,0 +1,14 @@
elixir:
route = fn p -> Routes.comment_path(@conn, :index, p) end
pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @comments, route: route
.block
.block__header
= pagination
= for {comment, body} <- @comments do
= render PhilomenaWeb.CommentView, "_comment.html", comment: comment, body: body, conn: @conn
.block
.block__header.block__header--light
= pagination

View file

@ -7,7 +7,7 @@
span data-click-preventdefault="true"
i.fa.fa-caret-down<
.dropdown__content
a.header__link href="/lists/recent_comments"
a.header__link href="/comments"
| Comments
.dropdown.header__dropdown
a.header__link href="/forums"