Clean up on thread->by_id

This commit is contained in:
swag 2023-05-29 00:27:16 -04:00
parent a220c233fa
commit e8d3e716ce
2 changed files with 15 additions and 26 deletions

View File

@ -51,32 +51,21 @@ sub by_id($self) {
$last_page = $self->remark->last_page_for($thread_id); $last_page = $self->remark->last_page_for($thread_id);
$remarks = $self->remark->by_page_for($thread_id, $this_page); $remarks = $self->remark->by_page_for($thread_id, $this_page);
if (my $thread_body = $thread->{'body'}) { $self->stash(
$self->stash( thread => $thread,
thread => $thread, base_path => $base_path,
base_path => $base_path, this_page => $this_page,
this_page => $this_page, last_page => $last_page,
last_page => $last_page, remarks => $remarks
remarks => $remarks );
)
} $self->stash(status => 404, error => 'Thread not found 🤷')
else { unless keys %{$thread};
$self->stash(
thread => {},
remarks => [],
status => 404,
error => 'Thread not found 🤷'
)
}
# Check for remarks or thread page number to make sure # Check for remarks or thread page number to make sure
# remark->by_page_for did its job # 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( unless 1 >= $this_page || scalar @{$remarks};
status => 404,
error => 'Page not found 🕵️'
)
}
$self->render; $self->render;
} }

View File

@ -1,12 +1,12 @@
% layout 'default'; % layout 'default';
% title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?'; % title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?';
<h2 class="page-title"><%= title %></h2> <h2 class="page-title"><%= title %></h2>
<% if (my $thread_id = $thread->{'id'}) { =%> <% if (keys %{$thread}) { =%>
<main class="pager"> <main class="pager">
<article class="post"> <article class="post">
<h3 class="post__title"> <h3 class="post__title">
<%= $thread->{'title'} %> <%= $thread->{'title'} %>
<span class="post__id">#<%= $thread_id %></span> <span class="post__id">#<%= $thread->{'id'} %></span>
</h3> </h3>
<h4 class="post__date"><%= $thread->{'date'} %></h4> <h4 class="post__date"><%= $thread->{'date'} %></h4>
<h5 class="post__author"><%= $thread->{'author'} %></h5> <h5 class="post__author"><%= $thread->{'author'} %></h5>
@ -38,7 +38,7 @@
</article> </article>
</main> </main>
<% } =%> <% } =%>
<% if (my $first_remark = $remarks->[0]) { =%> <% if (scalar @{$remarks}) { =%>
<section class="pager" id="remarks"> <section class="pager" id="remarks">
<h3 class="pager__title">Remarks</h3> <h3 class="pager__title">Remarks</h3>
<% for my $remark (@{$remarks}) { =%> <% for my $remark (@{$remarks}) { =%>