Implement remark-to-remark feature; move 'last remark' above 'thread' in the post_remark view

This commit is contained in:
swag 2023-06-25 00:01:13 -04:00
parent a34b82eadb
commit f1ebc492e5
8 changed files with 64 additions and 44 deletions

View File

@ -26,7 +26,10 @@ Now try requesting http://localhost:3000
## Testing ## Testing
Run the tests locally (against development environment): First, create a valid first thread and first remark to the first
thread. The tests rely on the existence of thread #1 and remark #1
being the first remark to that first thread. Then you can run the
tests locally:
prove -l prove -l

View File

@ -156,6 +156,7 @@ sub startup($self) {
my $remark = $r->any('/remark'); my $remark = $r->any('/remark');
$remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/]) $remark->any([qw{GET POST}], '/post/:thread_id', [thread_id => qr/\d+/])
->any('/:remark_id', [remark_id => qr/\d+/], {remark_id => 0})
->to('remark#create') ->to('remark#create')
->name('post_remark'); ->name('post_remark');

View File

@ -15,7 +15,9 @@ sub by_id($self) {
} }
sub create($self) { sub create($self) {
my ($thread_id, $v) = ($self->param('thread_id'), undef); my $thread_id = $self->param('thread_id');
my $remark_id = $self->param('remark_id');
my $v;
$v = $self->validation if $self->req->method eq 'POST'; $v = $self->validation if $self->req->method eq 'POST';
@ -50,7 +52,9 @@ sub create($self) {
} }
my $thread = $self->thread->by_id($thread_id); my $thread = $self->thread->by_id($thread_id);
my $last_remark = $self->remark->last_for($thread_id); my $last_remark = $remark_id
? $self->remark->by_id($remark_id)
: $self->remark->last_for($thread_id);
$self->stash( $self->stash(
thread => $thread, thread => $thread,

View File

@ -16,7 +16,8 @@ my %invalid_remark = (
subtest 'View single remark', sub { subtest 'View single remark', sub {
$t->get_ok('/remark/single/1')->status_is(200) $t->get_ok('/remark/single/1')->status_is(200)
->text_like(h2 => qr/Remark #1/); ->text_like(h2 => qr/Remark #1/)
->element_exists('a[href$="/remark/post/1/1"]')
}; };
$t->ua->max_redirects(1); $t->ua->max_redirects(1);
@ -28,6 +29,13 @@ subtest 'Post new remark', sub {
->element_exists('form textarea[name="body"]') ->element_exists('form textarea[name="body"]')
->element_exists('form button[type="submit"]' ) ->element_exists('form button[type="submit"]' )
->text_like(h2 => qr/Remark on Thread #/); ->text_like(h2 => qr/Remark on Thread #/);
# Test the remark-to-remark thing
$t->get_ok('/remark/post/1/1')->status_is(200)
->element_exists('form input[name="author"]' )
->element_exists('form textarea[name="body"]')
->element_exists('form button[type="submit"]' )
->element_exists('a[href$="/remark/single/1"]')
->text_like(h3 => qr/Last Remark/);
# POST # POST
$t->post_ok('/remark/post/1')->status_is(200) $t->post_ok('/remark/post/1')->status_is(200)

View File

@ -34,8 +34,9 @@ subtest 'View single thread', sub {
$t->get_ok('/thread/single/1')->status_is(200) $t->get_ok('/thread/single/1')->status_is(200)
->text_like(h2 => qr/Thread #1/); ->text_like(h2 => qr/Thread #1/);
# Test the thread_page and remark_id params
$t->get_ok('/thread/single/1/1')->status_is(200) $t->get_ok('/thread/single/1/1')->status_is(200)
->text_like(h2 => qr/Thread #1/); ->element_exists('a[href$="/remark/post/1/1"]');
$t->get_ok('/thread/single/65536')->status_is(404) $t->get_ok('/thread/single/65536')->status_is(404)
->text_like(p => qr/Thread not found/); ->text_like(p => qr/Thread not found/);

View File

@ -29,7 +29,8 @@
<%= link_to Thread => single_thread => <%= link_to Thread => single_thread =>
{thread_id => $remark->{'thread_id'}}, (class => 'click') %> {thread_id => $remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Remark => post_remark => <%= link_to Remark => post_remark =>
{thread_id => $remark->{'thread_id'}}, (class => 'click') %> {thread_id => $remark->{'thread_id'}, remark_id => $remark->{'id'}},
(class => 'click') %>
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}}, <%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}},
(class => 'click') %> (class => 'click') %>
</nav> </nav>

View File

@ -48,6 +48,43 @@
</div> </div>
<button type="submit" class="form-button">Post</button> <button type="submit" class="form-button">Post</button>
</form> </form>
<%# Putting this first above the thread body (nested if, yucky sry) %>
<% if (keys %{$last_remark}) { =%>
<section class="pager">
<h3 class="pager__title">Last Remark</h3>
<article class="post">
<h4 class="post__title">
<span>
<%= $last_remark->{'date'} %>
</span>
<%= link_to "#$last_remark->{'id'}", single_remark =>
{remark_id => $last_remark->{'id'}}, (class => 'post__id') %>
</h4>
<h5 class="post__author"><%= $last_remark->{'author'} %></h5>
<div class="post__body">
<%== markdown $last_remark->{'body'} =%>
</div>
<nav class="post__nav">
<%= link_to Thread => single_thread =>
{thread_id => $last_remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Remark => post_remark =>
{thread_id => $last_remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Flag => flag_remark => {remark_id => $last_remark->{'id'}},
(class => 'click') %>
</nav>
<% if (is_mod) { =%>
<nav class="post__nav">
<%= link_to Hide => hide_remark => {remark_id => $last_remark->{'id'}},
(class => 'click') %>
<%= link_to Unhide => unhide_remark => {remark_id =>
$last_remark->{'id'}}, (class => 'click') %>
<%= link_to Unflag => unflag_remark => {remark_id =>
$last_remark->{'id'}}, (class => 'click') %>
</nav>
<% } =%>
</article>
</section>
<% } =%><%# Close the last_remark 'if' %>
<section class="pager"> <section class="pager">
<h3 class="pager__title">Thread</h3> <h3 class="pager__title">Thread</h3>
<article class="post"> <article class="post">
@ -87,40 +124,4 @@
<% } =%> <% } =%>
</article> </article>
</section> </section>
<% } =%> <% } =%><%# Close the thread 'if' %>
<% if (keys %{$last_remark}) { =%>
<section class="pager">
<h3 class="pager__title">Last Remark</h3>
<article class="post">
<h4 class="post__title">
<span>
<%= $last_remark->{'date'} %>
</span>
<%= link_to "#$last_remark->{'id'}", single_remark =>
{remark_id => $last_remark->{'id'}}, (class => 'post__id') %>
</h4>
<h5 class="post__author"><%= $last_remark->{'author'} %></h5>
<div class="post__body">
<%== markdown $last_remark->{'body'} =%>
</div>
<nav class="post__nav">
<%= link_to Thread => single_thread =>
{thread_id => $last_remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Remark => post_remark =>
{thread_id => $last_remark->{'thread_id'}}, (class => 'click') %>
<%= link_to Flag => flag_remark => {remark_id => $last_remark->{'id'}},
(class => 'click') %>
</nav>
<% if (is_mod) { =%>
<nav class="post__nav">
<%= link_to Hide => hide_remark => {remark_id => $last_remark->{'id'}},
(class => 'click') %>
<%= link_to Unhide => unhide_remark => {remark_id =>
$last_remark->{'id'}}, (class => 'click') %>
<%= link_to Unflag => unflag_remark => {remark_id =>
$last_remark->{'id'}}, (class => 'click') %>
</nav>
<% } =%>
</article>
</section>
<% } =%>

View File

@ -66,7 +66,8 @@
<%== markdown $remark->{'body'} =%> <%== markdown $remark->{'body'} =%>
</div> </div>
<nav class="post__nav"> <nav class="post__nav">
<%= link_to Remark => post_remark => {thread_id => $thread->{'id'}}, <%= link_to Remark => post_remark =>
{thread_id => $thread->{'id'}, remark_id => $remark->{'id'}},
(class => 'click') %> (class => 'click') %>
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}}, <%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}},
(class => 'click') %> (class => 'click') %>