Skip to content

Commit 12cf20f

Browse files
author
Matt Swanson
committed
Up story pagination to 20 items per page. Add shortcuts for next/prev page. Closes stringer-rss#147
1 parent 9566adf commit 12cf20f

5 files changed

Lines changed: 57 additions & 6 deletions

File tree

‎app/repositories/story_repository.rb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ def self.unread_since_id(since_id)
3333
end
3434

3535
def self.read(page = 1)
36-
Story.where(is_read: true).order("published desc").page(page).per_page(15)
36+
Story.where(is_read: true)
37+
.order("published desc").page(page).per_page(20)
3738
end
3839

3940
def self.starred(page = 1)
4041
Story.where(is_starred: true)
41-
.order("published desc").page(page).per_page(15)
42+
.order("published desc").page(page).per_page(20)
4243
end
4344

4445
def self.read_count

‎app/views/archive.erb‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,39 @@
1212

1313
<div id="pagination">
1414
<% if @read_stories.previous_page %>
15-
<a href="?page=<%= @read_stories.previous_page %>"><%= t('archive.previous') %></a>
15+
<a id="prev_page" href="?page=<%= @read_stories.previous_page %>"><%= t('archive.previous') %></a>
1616
<% end %>
1717

1818
<% if @read_stories.total_pages > 1 %>
1919
<%= @read_stories.current_page %> <%= t('archive.of') %> <%= @read_stories.total_pages %>
2020
<% end %>
2121

2222
<% if @read_stories.next_page %>
23-
<a href="?page=<%= @read_stories.next_page %>"><%= t('archive.next') %></a>
23+
<a id="next_page" href="?page=<%= @read_stories.next_page %>"><%= t('archive.next') %></a>
2424
<% end %>
2525
</div>
26+
27+
<script>
28+
$(document).ready(function() {
29+
var stripQuerystring = function(full_url) {
30+
return full_url.split("?")[0];
31+
};
32+
33+
Mousetrap.bind("left", function() {
34+
var pageNumber = $("#prev_page").attr("href");
35+
36+
if (pageNumber)
37+
location.href = stripQuerystring(location.href) + pageNumber;
38+
});
39+
40+
Mousetrap.bind("right", function() {
41+
var pageNumber = $("#next_page").attr("href");
42+
43+
if (pageNumber)
44+
location.href = stripQuerystring(location.href) + pageNumber;
45+
});
46+
});
47+
</script>
2648
<% else %>
2749
<div id="sorry">
2850
<p><%= t('archive.sorry') %></p>

‎app/views/partials/_shortcuts.erb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<li class="blank"></li>
1515
<li><kbd>shift</kbd>+<kbd>a</kbd>: <%= t('partials.shortcuts.keys.shifta') %></li>
1616
<li><kbd>r</kbd>: <%= t('partials.shortcuts.keys.r') %></li>
17+
<li class="blank"></li>
18+
<li><kbd>&larr;</kbd>: <%= t('partials.shortcuts.keys.left') %></li>
19+
<li><kbd>&rarr;</kbd>: <%= t('partials.shortcuts.keys.right') %></li>
1720
</ul>
1821
</div>
1922
</div>

‎app/views/starred.erb‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,40 @@
1212

1313
<div id="pagination">
1414
<% if @starred_stories.previous_page %>
15-
<a href="?page=<%= @starred_stories.previous_page %>"><%= t('starred.previous') %></a>
15+
<a id="prev_page" href="?page=<%= @starred_stories.previous_page %>"><%= t('starred.previous') %></a>
1616
<% end %>
1717

1818
<% if @starred_stories.total_pages > 1 %>
1919
<%= @starred_stories.current_page %> <%= t('starred.of') %> <%= @starred_stories.total_pages %>
2020
<% end %>
2121

2222
<% if @starred_stories.next_page %>
23-
<a href="?page=<%= @starred_stories.next_page %>"><%= t('starred.next') %></a>
23+
<a id="next_page" href="?page=<%= @starred_stories.next_page %>"><%= t('starred.next') %></a>
2424
<% end %>
2525
</div>
26+
27+
<script>
28+
$(document).ready(function() {
29+
var stripQuerystring = function(full_url) {
30+
return full_url.split("?")[0];
31+
};
32+
33+
Mousetrap.bind("left", function() {
34+
var pageNumber = $("#prev_page").attr("href");
35+
36+
if (pageNumber)
37+
location.href = stripQuerystring(location.href) + pageNumber;
38+
});
39+
40+
Mousetrap.bind("right", function() {
41+
var pageNumber = $("#next_page").attr("href");
42+
43+
if (pageNumber)
44+
location.href = stripQuerystring(location.href) + pageNumber;
45+
});
46+
});
47+
</script>
48+
2649
<% else %>
2750
<div id="sorry">
2851
<p><%= t('starred.sorry') %></p>

‎config/locales/en.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ en:
101101
r: Refresh
102102
shifta: Mark all as read
103103
v: Go to story URL
104+
left: Previous page
105+
right: Next page
104106
title: Keyboard shortcuts
105107
zen:
106108
archive: view all items

0 commit comments

Comments
 (0)