From 94f521e99c2d0b81266fbcf701657a9a3be1f960 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Tue, 8 Oct 2019 19:30:51 -0400 Subject: [PATCH] forums pagination --- lib/philomena_web/controllers/forum_controller.ex | 3 +-- lib/philomena_web/controllers/topic_controller.ex | 3 +-- lib/philomena_web/plugs/pagination.ex | 1 + lib/philomena_web/templates/forum/show.html.slime | 10 +++++----- lib/philomena_web/templates/topic/show.html.slime | 10 +++++++--- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/philomena_web/controllers/forum_controller.ex b/lib/philomena_web/controllers/forum_controller.ex index a11e60e9..717bc1c2 100644 --- a/lib/philomena_web/controllers/forum_controller.ex +++ b/lib/philomena_web/controllers/forum_controller.ex @@ -27,8 +27,7 @@ defmodule PhilomenaWeb.ForumController do |> where(hidden_from_users: false) |> order_by(desc: :sticky, desc: :last_replied_to_at) |> preload([:poll, :forum, :user, last_post: :user]) - |> limit(25) - |> Repo.all() + |> Repo.paginate(page: conn.assigns.scrivener) render(conn, "show.html", forum: conn.assigns.forum, topics: topics) end diff --git a/lib/philomena_web/controllers/topic_controller.ex b/lib/philomena_web/controllers/topic_controller.ex index 8c03b178..9ab89ee0 100644 --- a/lib/philomena_web/controllers/topic_controller.ex +++ b/lib/philomena_web/controllers/topic_controller.ex @@ -22,8 +22,7 @@ defmodule PhilomenaWeb.TopicController do |> where(topic_id: ^conn.assigns.topic.id) |> order_by(asc: :created_at) |> preload([:user, topic: :forum]) - |> limit(25) - |> Repo.all() + |> Repo.paginate(conn.assigns.scrivener) render(conn, "show.html", posts: posts) end diff --git a/lib/philomena_web/plugs/pagination.ex b/lib/philomena_web/plugs/pagination.ex index 6efe3b89..3389fcf4 100644 --- a/lib/philomena_web/plugs/pagination.ex +++ b/lib/philomena_web/plugs/pagination.ex @@ -31,5 +31,6 @@ defmodule PhilomenaWeb.Plugs.Pagination do conn |> assign(:pagination, %{page_number: page_number, page_size: page_size}) + |> assign(:scrivener, [page: page_number, page_size: page_size]) end end diff --git a/lib/philomena_web/templates/forum/show.html.slime b/lib/philomena_web/templates/forum/show.html.slime index 3de8d63b..84e7a7c4 100644 --- a/lib/philomena_web/templates/forum/show.html.slime +++ b/lib/philomena_web/templates/forum/show.html.slime @@ -1,3 +1,5 @@ +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @topics, route: fn p -> Routes.forum_path(@conn, :show, @forum, p) end + h1 = @forum.name .block .block__header @@ -10,8 +12,7 @@ h1 = @forum.name => @forum.topic_count ' topics .block__header--sub.block__header--light - /- if @forum.topic_count >= Topic.topics_per_page do - / = paginate @topics + = pagination span.block__header__title = @forum.description /- if current_user / = subscription_link(@forum, current_user) @@ -50,9 +51,8 @@ h1 = @forum.name = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post br => pretty_time(topic.last_post.created_at) - /= if @forum.topic_count >= Topic.topics_per_page do - / .block__header.block__header--light - / = paginate @topics + .block__header.block__header--light + = pagination /- if current_user / = render partial: 'topics/form' diff --git a/lib/philomena_web/templates/topic/show.html.slime b/lib/philomena_web/templates/topic/show.html.slime index d57143dd..6e72dbcf 100644 --- a/lib/philomena_web/templates/topic/show.html.slime +++ b/lib/philomena_web/templates/topic/show.html.slime @@ -1,3 +1,5 @@ +- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @posts, route: fn p -> Routes.forum_topic_path(@conn, :show, @forum, @topic, p) end + h1 = @topic.title / Header section .block @@ -11,8 +13,8 @@ h1 = @topic.title / i.fa.fa-fw.fa-search> / | Search Posts .flex.flex--wrap.block__header.block__header--light - /.flex--fixed - / = paginate @posts + .flex--fixed + = pagination .flex--fixed.block__header__item ' Started by => render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @topic @@ -42,7 +44,9 @@ h1 = @topic.title /.js-editable-posts data-editable=editable_communications(@posts).to_json / Footer section - /.block: .block__header.block__header--light = paginate @posts + .block + .block__header.block__header--light + = pagination / Post form = if @topic.post_count < 200_000 do