Implement single remark view

This commit is contained in:
swagg boi 2022-09-02 22:45:41 -04:00
parent cbc44b2bc8
commit 8069a255a6
7 changed files with 63 additions and 9 deletions

View file

@ -122,7 +122,7 @@ group {
);
return $c->redirect_to(
'remark_page',
'thread_page',
{thread_id => $thread_id}
);
}
@ -144,13 +144,13 @@ group {
group {
under '/thread/:thread_id', [thread_id => qr/[0-9]+/];
get '/:remark_page',
[remark_page => qr/[0-9]+/],
{remark_page => 1}, sub ($c) { # My editor is so confused by this lol
get '/:thread_page',
[thread_page => qr/[0-9]+/],
{thread_page => 1}, sub ($c) { # My editor is so confused by this lol
my $thread_id = $c->param('thread_id');
my $thread = $c->thread->by_id($thread_id);
my $base_path = $c->match->path_for(remark_page => undef)->{'path'};
my $this_page = $c->param('remark_page');
my $base_path = $c->match->path_for(thread_page => undef)->{'path'};
my $this_page = $c->param('thread_page');
my $last_page = $c->remark->last_page_for($thread_id);
my $remarks = $c->remark->by_page_for($thread_id, $this_page);
@ -177,6 +177,22 @@ group {
};
};
# Remark
group {
under '/remark';
get '/:remark_id', [remark_id => qr/[0-9]+/], sub ($c) {
my $remark_id = $c->param('remark_id');
my $remark = $c->remark->by_id($remark_id);
$c->stash(status => 404) unless $remark->{'id'};
$c->stash(remark => $remark);
$c->render;
};
};
# Configure things
app->secrets(app->config->{'secrets'}) || die $@;

View file

@ -24,7 +24,9 @@ Run the tests locally (against development environment)
## TODOs
1. Single remark view
1. Add hyperlink to single remarks
1. More tests (single remark view at least... maybe more)
1. Grow into Mojo hybrid
## Crazy future ideas

View file

@ -86,4 +86,26 @@ sub last_for($self, $thread_id) {
END_SQL
}
sub by_id($self, $remark_id) {
my $date_format = $self->{'date_format'};
$self->pg->db->query(<<~'END_SQL', $date_format, $remark_id)->hash;
SELECT remark_id AS id,
TO_CHAR(remark_date, ?) AS date,
remark_author AS author,
remark_body AS body,
thread_id
FROM remarks
WHERE remark_id = ?;
END_SQL
}
sub thread_id_for($self, $remark_id) {
$self->pg->db->query(<<~'END_SQL', $remark_id)->hash->{'thread_id'}
SELECT thread_id
FROM remarks
WHERE remark_id = ?;
END_SQL
}
1;

View file

@ -6,7 +6,7 @@
<article class="thread">
<span class="id">
<%= link_to "#$thread->{'id'}",
remark_page => {thread_id => $thread->{'id'}} %>
thread_page => {thread_id => $thread->{'id'}} %>
</span>
<h3 class="title"><%= %$thread{'title'} %></h3>
<h4 class="date"><%= %$thread{'date'} %></h4>

View file

@ -0,0 +1,14 @@
% layout 'main';
% title "Remark - #$remark->{'id'}";
<h2><%= title %></h2>
<div class="remarks">
<article class="remark">
<span class="id">#<%= %$remark{'id'} %></span>
<h4 class="date"><%= %$remark{'date'} %></h4>
<h5 class="author"><%= %$remark{'author'} %></h5>
<p class="body"><%= %$remark{'body'} %></p>
</article>
</div>
<nav>
<%= link_to Thread => thread_page => {thread_id => $remark->{'thread_id'}} %>
</nav>

View file

@ -28,7 +28,7 @@
<article class="thread">
<span class="id">
<%= link_to "#$thread->{'id'}",
remark_page => {thread_id => $thread->{'id'}} %>
thread_page => {thread_id => $thread->{'id'}} %>
</span>
<h3 class="title"><%= %$thread{'title'} %></h3>
<h4 class="date"><%= %$thread{'date'} %></h4>