diff --git a/lib/philomena_web/controllers/comment_controller.ex b/lib/philomena_web/controllers/comment_controller.ex new file mode 100644 index 00000000..147ee825 --- /dev/null +++ b/lib/philomena_web/controllers/comment_controller.ex @@ -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 diff --git a/lib/philomena_web/router.ex b/lib/philomena_web/router.ex index 96fe1d74..e5ff64ac 100644 --- a/lib/philomena_web/router.ex +++ b/lib/philomena_web/router.ex @@ -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 diff --git a/lib/philomena_web/templates/comment/index.html.slime b/lib/philomena_web/templates/comment/index.html.slime new file mode 100644 index 00000000..2da87a7f --- /dev/null +++ b/lib/philomena_web/templates/comment/index.html.slime @@ -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 \ No newline at end of file diff --git a/lib/philomena_web/templates/layout/_header_navigation.html.slime b/lib/philomena_web/templates/layout/_header_navigation.html.slime index 8c08ff16..4eed4612 100644 --- a/lib/philomena_web/templates/layout/_header_navigation.html.slime +++ b/lib/philomena_web/templates/layout/_header_navigation.html.slime @@ -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"