Change pager behavior to make more sense

This commit is contained in:
swagg boi 2021-12-19 17:20:58 -05:00
parent 8a4c5eab44
commit 627fe02bda
3 changed files with 7 additions and 3 deletions

View file

@ -45,7 +45,7 @@ under sub ($c) {
get '/' => sub ($c) { get '/' => sub ($c) {
my $posts = $c->message->get_posts(); my $posts = $c->message->get_posts();
my $last_page = $c->message->get_last_page(@$posts); my $last_page = $c->message->get_last_page(@$posts);
my $this_page = $c->param('page') || $last_page; my $this_page = $c->param('page') || 1;
my @view_posts = $c->message->view_posts($this_page, $last_page, @$posts); my @view_posts = $c->message->view_posts($this_page, $last_page, @$posts);
$c->stash( $c->stash(

View file

@ -14,7 +14,11 @@ sub new($class, $pg, $pg_object) {
} }
sub get_posts($self) { sub get_posts($self) {
$self->pg->db->query('SELECT date, name, msg FROM messages;')->arrays() $self->pg->db
->query('SELECT to_char(date, \'Dy Mon DD HH:MI:SS AM TZ YYYY\'),
name, msg
FROM messages
ORDER BY date DESC;')->arrays()
} }
sub send_post($self, $name, $msg) { sub send_post($self, $name, $msg) {

View file

@ -2,7 +2,7 @@
% title 'Home'; % title 'Home';
<h2>Messages from the World Wide Web</h2> <h2>Messages from the World Wide Web</h2>
<table> <table>
<% for my $row (reverse @$view_posts) { %> <% for my $row (@$view_posts) { %>
<tr> <tr>
<th>Date:</th> <th>Date:</th>
<td><%= @$row[0] %></td> <td><%= @$row[0] %></td>