Implement /view route w/ page_number placeholder

This commit is contained in:
swagg boi 2022-04-07 21:04:41 -04:00
parent 222d9e8a74
commit 8f95b616cf
2 changed files with 65 additions and 13 deletions

View file

@ -58,19 +58,23 @@ under sub ($c) {
1;
};
#get '/' => sub ($c) {
# my $this_page = $c->param('page') || 1;
# my $last_page = $c->message->get_last_page();
# my $view_posts = $c->message->get_posts($this_page);
#
# $c->stash(
# view_posts => $view_posts,
# this_page => $this_page,
# last_page => $last_page
# );
#
# $c->render();
#} => 'index';
get '/' => sub ($c) {
my $this_page = $c->param('page') || 1;
my $last_page = $c->message->get_last_page();
my $view_posts = $c->message->get_posts($this_page);
$c->stash(
view_posts => $view_posts,
this_page => $this_page,
last_page => $last_page
);
$c->render();
} => 'index';
$c->redirect_to('view');
};
get '/spam' => sub ($c) {
my $this_page = $c->param('page') || 1;
@ -143,7 +147,26 @@ group {
$c->stash(view_post => @view_post);
#$c->render(text => "You've requested message number: $message_id");
$c->render();
};
};
group {
under '/view';
get '/:page_number', {page_number => 1} => sub ($c) {
my $this_page = $c->param('page_number');
my $last_page = $c->message->get_last_page('spam');
my $view_posts = $c->message->get_spam($this_page);
my $base_path = $c->url_for(page_number => undef);
$c->stash(
view_posts => $view_posts,
this_page => $this_page,
last_page => $last_page,
base_path => $base_path
);
$c->render();
};
};

View file

@ -0,0 +1,29 @@
% layout 'default';
% title 'View';
<h2>Messages from the World Wide Web</h2>
<div class="articles">
<% for my $view_post (@$view_posts) { =%>
<article>
<span class="message_id field">
<%= link_to "#@$view_post[4]" => "/message/@$view_post[4]" %>
</span>
<h3><%= @$view_post[0] %></h3>
<div class="message field">
<blockquote><p><%= @$view_post[2] %></p></blockquote>
</div>
<div class="name field">
<p style="margin: 0 0 0 0;">
- <%= @$view_post[1] %>
<% if (@$view_post[3]) { =%>
(<%= link_to Homepage => @$view_post[3] %>)
<% } =%>
</p>
</div>
</article>
<% } =%>
</div>
<% if ($last_page && $last_page != 1) { =%>
<nav>
<%= pagination $this_page, $last_page, $base_path . '/{page}' %>
</nav>
<% } =%>