Default single_thread's thread_page to last_page instead of the first page

This commit is contained in:
swagg boi 2023-06-26 22:10:20 -04:00
parent f1ebc492e5
commit 93f0689d1b
3 changed files with 5 additions and 5 deletions

View file

@ -136,7 +136,7 @@ sub startup($self) {
->name('post_thread');
$thread->any('/single/:thread_id', [thread_id => qr/\d+/])
->get('/:thread_page', [thread_page => qr/\d+/], {thread_page => 1})
->get('/:thread_page', [thread_page => qr/\d+/], {thread_page => 0})
->to('thread#by_id')
->name('single_thread');

View file

@ -43,8 +43,8 @@ sub by_id($self) {
my $thread_id = $self->param('thread_id');
my $thread = $self->thread->by_id($thread_id);
my $base_path = $self->match->path_for(thread_page => undef)->{'path'};
my $this_page = $self->param('thread_page');
my $last_page = $self->remark->last_page_for($thread_id);
my $last_page = $self->remark->last_page_for($thread_id) || 1;
my $this_page = $self->param('thread_page') || $last_page;
my $remarks = $self->remark->by_page_for($thread_id, $this_page);
$self->stash(
@ -61,7 +61,7 @@ sub by_id($self) {
# Check for remarks or thread page number to make sure
# remark->by_page_for did its job
$self->stash(status => 404, error => 'Page not found 🕵️')
unless 1 >= $this_page || scalar @{$remarks};
unless scalar @{$remarks} || $this_page == $last_page;
$self->render;
}

View file

@ -76,7 +76,7 @@
<% } =%>
<% if ($last_page && $last_page != 1) { =%>
<nav class="pager__nav">
<%= pagination $this_page, $last_page, ($base_path . '/{page}') %>
<%= pagination $this_page, $last_page, ($base_path . '/{page}#remarks') %>
</nav>
<% } =%>
</section>