Implement form for remarking to threads

This commit is contained in:
swagg boi 2022-08-23 19:06:33 -04:00
parent e0b7ab4a7d
commit e73170c1f2
4 changed files with 88 additions and 24 deletions

View file

@ -62,7 +62,10 @@ group {
}; };
# Post # Post
any [qw{GET POST}], '/post', sub ($c) { group {
under '/post';
any [qw{GET POST}], '/', sub ($c) {
my $v; my $v;
$v = $c->validation() if $c->req->method eq 'POST'; $v = $c->validation() if $c->req->method eq 'POST';
@ -90,7 +93,42 @@ any [qw{GET POST}], '/post', sub ($c) {
} }
} }
return $c->render(); return $c->render(template => 'post_thread');
};
any [qw{GET POST}], '/:thread_id', [thread_id => qr/[0-9]+/], sub ($c) {
my $v;
$v = $c->validation() if $c->req->method eq 'POST';
if ($v && $v->has_data) {
my $thread_id = $c->param('thread_id');
my $remark_name = $c->param('name');
my $remark_body = $c->param('post');
$v->required('name' )->size(1, 63 );
$v->required('post' )->size(2, 4000);
if ($v->has_error) {
$c->stash(status => 400)
}
else {
$c->remark->create_remark(
$thread_id,
$remark_name,
$remark_body
);
# Gotta be a better way to name this route...
return $c->redirect_to(
'thread_idremark_page',
{thread_id => $thread_id}
);
}
}
return $c->render(template => 'post_remark');
};
}; };
# Thread # Thread

View file

@ -12,7 +12,7 @@ Install dependencies
Run it in development mode Run it in development mode
morbo PostText.pl morbo -w assets/css/ -w lib/ -w migrations/ -w t/ -w templates/ PostText.pl
Now try requesting http://localhost:3000 Now try requesting http://localhost:3000
@ -24,10 +24,11 @@ Run the tests locally (against development environment)
## TODOs ## TODOs
1. Form to create new remarks 1. Hyperlink to remarks form
1. Is there something I can do about route names?
1. I'm kinda hardcoding the single-thread view `link_to` in the 1. I'm kinda hardcoding the single-thread view `link_to` in the
templates because I cannot for the life of me figure out how to use templates because I cannot for the life of me figure out how to use
`url_for` to populate the `thread_id` placeholder. Probably need to `url_for` to populate the `thread_id` placeholder. Probably need to
clean-up the HTML too, just used `<span>` cuz I didn't know what clean-up the HTML too, just used `<span>` cuz I didn't know what
else to use else to use
1. Just clean stuff up in general lol 1. Tests for remark form

View file

@ -0,0 +1,25 @@
% layout 'main';
% title 'New Remark';
<h2><%= title %></h2>
<form method="post">
<div class="name field">
<%= label_for name => 'Author' %>
<%= text_field name =>'Anonymous', maxlength => 63, minlength => 1 %>
<% if (my $error = validation->error('name')) { =%>
<p class="field-with-error">Invalid name: 1 to 63 characters please.</p>
<% } =%>
</div>
<div class="text field">
<%= label_for post => 'Text' %>
<%= text_area 'post', (
maxlength => 4000,
minlength => 2,
required => 'true',
rows => 6
) %>
<% if (my $error = validation->error('post')) { =%>
<p class="field-with-error">Invalid post: Up to 4,000 characters only.</p>
<% } =%>
</div>
<%= submit_button 'Post', class => 'post button' %>
</form>