forums pagination

This commit is contained in:
byte[] 2019-10-08 19:30:51 -04:00
parent 3a8176b47a
commit 94f521e99c
5 changed files with 15 additions and 12 deletions

View file

@ -27,8 +27,7 @@ defmodule PhilomenaWeb.ForumController do
|> where(hidden_from_users: false) |> where(hidden_from_users: false)
|> order_by(desc: :sticky, desc: :last_replied_to_at) |> order_by(desc: :sticky, desc: :last_replied_to_at)
|> preload([:poll, :forum, :user, last_post: :user]) |> preload([:poll, :forum, :user, last_post: :user])
|> limit(25) |> Repo.paginate(page: conn.assigns.scrivener)
|> Repo.all()
render(conn, "show.html", forum: conn.assigns.forum, topics: topics) render(conn, "show.html", forum: conn.assigns.forum, topics: topics)
end end

View file

@ -22,8 +22,7 @@ defmodule PhilomenaWeb.TopicController do
|> where(topic_id: ^conn.assigns.topic.id) |> where(topic_id: ^conn.assigns.topic.id)
|> order_by(asc: :created_at) |> order_by(asc: :created_at)
|> preload([:user, topic: :forum]) |> preload([:user, topic: :forum])
|> limit(25) |> Repo.paginate(conn.assigns.scrivener)
|> Repo.all()
render(conn, "show.html", posts: posts) render(conn, "show.html", posts: posts)
end end

View file

@ -31,5 +31,6 @@ defmodule PhilomenaWeb.Plugs.Pagination do
conn conn
|> assign(:pagination, %{page_number: page_number, page_size: page_size}) |> assign(:pagination, %{page_number: page_number, page_size: page_size})
|> assign(:scrivener, [page: page_number, page_size: page_size])
end end
end end

View file

@ -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 h1 = @forum.name
.block .block
.block__header .block__header
@ -10,8 +12,7 @@ h1 = @forum.name
=> @forum.topic_count => @forum.topic_count
' topics ' topics
.block__header--sub.block__header--light .block__header--sub.block__header--light
/- if @forum.topic_count >= Topic.topics_per_page do = pagination
/ = paginate @topics
span.block__header__title = @forum.description span.block__header__title = @forum.description
/- if current_user /- if current_user
/ = subscription_link(@forum, current_user) / = subscription_link(@forum, current_user)
@ -50,9 +51,8 @@ h1 = @forum.name
= render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post = render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: topic.last_post
br br
=> pretty_time(topic.last_post.created_at) => pretty_time(topic.last_post.created_at)
/= if @forum.topic_count >= Topic.topics_per_page do .block__header.block__header--light
/ .block__header.block__header--light = pagination
/ = paginate @topics
/- if current_user /- if current_user
/ = render partial: 'topics/form' / = render partial: 'topics/form'

View file

@ -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 h1 = @topic.title
/ Header section / Header section
.block .block
@ -11,8 +13,8 @@ h1 = @topic.title
/ i.fa.fa-fw.fa-search> / i.fa.fa-fw.fa-search>
/ | Search Posts / | Search Posts
.flex.flex--wrap.block__header.block__header--light .flex.flex--wrap.block__header.block__header--light
/.flex--fixed .flex--fixed
/ = paginate @posts = pagination
.flex--fixed.block__header__item .flex--fixed.block__header__item
' Started by ' Started by
=> render PhilomenaWeb.UserAttributionView, "_anon_user.html", object: @topic => 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 /.js-editable-posts data-editable=editable_communications(@posts).to_json
/ Footer section / Footer section
/.block: .block__header.block__header--light = paginate @posts .block
.block__header.block__header--light
= pagination
/ Post form / Post form
= if @topic.post_count < 200_000 do = if @topic.post_count < 200_000 do