From e8d3e716ce3732fb08919fa00b1c7a2adace9905 Mon Sep 17 00:00:00 2001 From: swag Date: Mon, 29 May 2023 00:27:16 -0400 Subject: [PATCH] Clean up on thread->by_id --- lib/PostText/Controller/Thread.pm | 35 +++++++++++-------------------- templates/thread/by_id.html.ep | 6 +++--- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index f1ae968..aa87afd 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -51,32 +51,21 @@ sub by_id($self) { $last_page = $self->remark->last_page_for($thread_id); $remarks = $self->remark->by_page_for($thread_id, $this_page); - if (my $thread_body = $thread->{'body'}) { - $self->stash( - thread => $thread, - base_path => $base_path, - this_page => $this_page, - last_page => $last_page, - remarks => $remarks - ) - } - else { - $self->stash( - thread => {}, - remarks => [], - status => 404, - error => 'Thread not found 🤷' - ) - } + $self->stash( + thread => $thread, + base_path => $base_path, + this_page => $this_page, + last_page => $last_page, + remarks => $remarks + ); + + $self->stash(status => 404, error => 'Thread not found 🤷') + unless keys %{$thread}; # Check for remarks or thread page number to make sure # remark->by_page_for did its job - unless ((my $first_remark = $remarks->[0]) || 1 >= $this_page) { - $self->stash( - status => 404, - error => 'Page not found 🕵️' - ) - } + $self->stash(status => 404, error => 'Page not found 🕵️') + unless 1 >= $this_page || scalar @{$remarks}; $self->render; } diff --git a/templates/thread/by_id.html.ep b/templates/thread/by_id.html.ep index cdbf912..73e8f42 100644 --- a/templates/thread/by_id.html.ep +++ b/templates/thread/by_id.html.ep @@ -1,12 +1,12 @@ % layout 'default'; % title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?';

<%= title %>

-<% if (my $thread_id = $thread->{'id'}) { =%> +<% if (keys %{$thread}) { =%>

<%= $thread->{'title'} %> - #<%= $thread_id %> + #<%= $thread->{'id'} %>

@@ -38,7 +38,7 @@
<% } =%> -<% if (my $first_remark = $remarks->[0]) { =%> +<% if (scalar @{$remarks}) { =%>

Remarks

<% for my $remark (@{$remarks}) { =%>