pagination for follow/follower lists

This commit is contained in:
Kyle Drake 2024-08-26 22:41:23 -05:00
parent a67588a1c0
commit 2625e1328a
5 changed files with 21 additions and 9 deletions

View file

@ -343,7 +343,7 @@ GEM
ffi-compiler (>= 0.1.2) ffi-compiler (>= 0.1.2)
webrick (1.8.1) webrick (1.8.1)
websocket (1.2.10) websocket (1.2.10)
will_paginate (4.0.0) will_paginate (4.0.1)
xmlrpc (0.3.3) xmlrpc (0.3.3)
webrick webrick
xpath (3.2.0) xpath (3.2.0)

View file

@ -127,16 +127,22 @@ end
get '/site/:username/follows' do |username| get '/site/:username/follows' do |username|
@title = "Sites #{username} follows" @title = "Sites #{username} follows"
@site = Site[username: username] @site = Site[username: username]
not_found if @site.nil? || @site.is_banned || @site.is_deleted || (current_site && (@site.is_blocking?(current_site) || current_site.is_blocking?(@site))) not_found if @site.nil? || @site.is_deleted || (current_site && (@site.is_blocking?(current_site) || current_site.is_blocking?(@site)))
@sites = @site.followings.collect {|f| f.site}
params[:page] ||= "1"
@pagination_dataset = @site.followings_dataset.paginate(params[:page].to_i, Site::FOLLOW_PAGINATION_LIMIT)
erb :'site/follows' erb :'site/follows'
end end
get '/site/:username/followers' do |username| get '/site/:username/followers' do |username|
@title = "Sites that follow #{username}" @title = "Sites that follow #{username}"
@site = Site[username: username] @site = Site[username: username]
not_found if @site.nil? || @site.is_banned || @site.is_deleted || (current_site && (@site.is_blocking?(current_site) || current_site.is_blocking?(@site))) not_found if @site.nil? || @site.is_deleted || (current_site && (@site.is_blocking?(current_site) || current_site.is_blocking?(@site)))
@sites = @site.follows.collect {|f| f.actioning_site}
params[:page] ||= "1"
@pagination_dataset = @site.follows_dataset.paginate(params[:page].to_i, Site::FOLLOW_PAGINATION_LIMIT)
erb :'site/followers' erb :'site/followers'
end end

View file

@ -87,6 +87,8 @@ class Site < Sequel::Model
BROWSE_FOLLOWER_UPDATED_AT_CUTOFF = 9.months BROWSE_FOLLOWER_UPDATED_AT_CUTOFF = 9.months
BROWSE_FOLLOWER_MINIMUM_FOLLOWS = 0 BROWSE_FOLLOWER_MINIMUM_FOLLOWS = 0
FOLLOW_PAGINATION_LIMIT = 100
SCREENSHOT_DELAY_SECONDS = 30 SCREENSHOT_DELAY_SECONDS = 30
SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50'] SCREENSHOT_RESOLUTIONS = ['540x405', '210x158', '100x100', '50x50']
THUMBNAIL_RESOLUTIONS = ['210x158'] THUMBNAIL_RESOLUTIONS = ['210x158']

View file

@ -8,14 +8,14 @@
<div class="browse-page"> <div class="browse-page">
<% if @sites.length == 0 %> <% if @pagination_dataset.length == 0 %>
<div class="row website-Gallery content int-Gall" style="padding-left: 30px;"> <div class="row website-Gallery content int-Gall" style="padding-left: 30px;">
<h3>No followers yet.</h3> <h3>No followers yet.</h3>
<p>Try another search, or <a href="/browse">browse all sites</a>!</p> <p>Try another search, or <a href="/browse">browse all sites</a>!</p>
</div> </div>
<% else %> <% else %>
<ul class="row website-Gallery content int-Gall"> <ul class="row website-Gallery content int-Gall">
<% @sites.each_with_index do |site| %> <% @pagination_dataset.collect {|f| f.actioning_site}.each_with_index do |site| %>
<li> <li>
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>"> <a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>">
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;"> <span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
@ -73,3 +73,5 @@
</ul> </ul>
<% end %> <% end %>
</div> </div>
<%== erb :'_pagination', layout: false %>

View file

@ -7,7 +7,7 @@
</div> </div>
<div class="browse-page"> <div class="browse-page">
<% if @sites.length == 0 %> <% if @pagination_dataset.length == 0 %>
<div class="row website-Gallery content int-Gall" style="padding-left: 30px;"> <div class="row website-Gallery content int-Gall" style="padding-left: 30px;">
<h3>No follows yet.</h3> <h3>No follows yet.</h3>
<% if current_site == @site %> <% if current_site == @site %>
@ -16,7 +16,7 @@
</div> </div>
<% else %> <% else %>
<ul class="row website-Gallery content int-Gall"> <ul class="row website-Gallery content int-Gall">
<% @sites.each_with_index do |site| %> <% @pagination_dataset.collect {|f| f.site}.each_with_index do |site| %>
<li> <li>
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>"> <a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>">
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;"> <span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
@ -74,3 +74,5 @@
</ul> </ul>
<% end %> <% end %>
</div> </div>
<%== erb :'_pagination', layout: false %>