From 93f0689d1b0cccfb694b5df0641f670a6d3814e1 Mon Sep 17 00:00:00 2001 From: swag Date: Mon, 26 Jun 2023 22:10:20 -0400 Subject: [PATCH] Default single_thread's thread_page to last_page instead of the first page --- lib/PostText.pm | 2 +- lib/PostText/Controller/Thread.pm | 6 +++--- templates/thread/by_id.html.ep | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/PostText.pm b/lib/PostText.pm index f7baeaa..3700db6 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -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'); diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index 2f0e9a2..7059f37 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -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; } diff --git a/templates/thread/by_id.html.ep b/templates/thread/by_id.html.ep index f0616a4..1b7ec83 100644 --- a/templates/thread/by_id.html.ep +++ b/templates/thread/by_id.html.ep @@ -76,7 +76,7 @@ <% } =%> <% if ($last_page && $last_page != 1) { =%> <% } =%>