Thread preview; fix robots.txt; comment something that confused myself

This commit is contained in:
swagg boi 2023-08-13 21:09:44 -05:00
parent 91588bd816
commit 1f75b4a47e
5 changed files with 48 additions and 31 deletions

View file

@ -5,37 +5,45 @@ use Date::Format;
use XML::RSS;
sub create($self) {
my $v;
my ($v, $draft);
$v = $self->validation if $self->req->method eq 'POST';
if ($v && $v->has_data) {
$v->required('author')->size(1, 63);
$v->required('title' )->size(1, 127);
$v->required('body' )->size(2, 4000);
$v->required('author' )->size(1, 63);
$v->required('title' )->size(1, 127);
$v->required('body' )->size(2, 4000);
$v->optional('preview');
if ($v->has_error) {
$self->stash(status => 400)
}
else {
my $thread_author = $v->param('author');
my $thread_title = $v->param('title' );
my $thread_body = $v->param('body' );
my $new_thread_id = $self->thread->create(
$thread_author,
$thread_title,
$thread_body
);
my $thread_author = $v->param('author' );
my $thread_title = $v->param('title' );
my $thread_body = $v->param('body' );
my $preview = $v->param('preview');
$self->session(author => $thread_author);
return $self->redirect_to(
single_thread => {thread_id => $new_thread_id}
);
unless ($preview) {
my $new_thread_id = $self->thread->create(
$thread_author,
$thread_title,
$thread_body
);
return $self->redirect_to(
single_thread => {thread_id => $new_thread_id}
);
}
$draft = $thread_body;
}
}
$self->stash(draft => $draft);
return $self->render;
}

View file

@ -22,7 +22,8 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) {
)
VALUES (?, ?, ?, ?, ?)
RETURNING thread_id;
END_SQL
END_SQL
# The indented heredoc got a little confused by this one...
}
sub by_page($self, $this_page = 1) {

View file

@ -3,8 +3,6 @@ Disallow: /cursors/
Disallow: /images/
Disallow: /fonts/
Disallow: /moderator/
Disallow: /thread/bump/
Disallow: /thread/flag/
Disallow: /remark/flag/
Disallow: /login
Disallow: /logout
Disallow: /human/

View file

@ -4,12 +4,13 @@ use Test::Mojo;
my $t = Test::Mojo->new('PostText');
#my %preview_thread = (
# author => 'Anonymous',
# title => 'hi',
# body => 'ayy... lmao',
# preview => 1
# );
my %preview_thread = (
author => 'Anonymous',
title => 'hi',
body => 'ayy... lmao',
preview => 1
);
my %preview_remark = (
author => 'Anonymous',
body => 'ayy... lmao',
@ -20,8 +21,8 @@ subtest 'Check the form + button', sub {
$t->get_ok('/remark/post/1')->status_is(200)
->element_exists('input[id="preview"]');
#$t->get_ok('/thread/post')->status_is(200)
# ->element_exists('input[id="preview"]');
$t->get_ok('/thread/post')->status_is(200)
->element_exists('input[id="preview"]');
};
subtest 'Submit input', sub {
@ -29,9 +30,9 @@ subtest 'Submit input', sub {
->status_is(200)
->text_like(p => qr/ayy\.\.\. lmao/);
#$t->post_ok('/thread/post', form => \%preview_thread)
# ->status_is(200)
# ->text_like(p => qr/ayy\.\.\. lmao/);
$t->post_ok('/thread/post', form => \%preview_thread)
->status_is(200)
->text_like(p => qr/ayy\.\.\. lmao/);
};
done_testing;

View file

@ -11,6 +11,11 @@
% end
<h2 class="page-title"><%= title %></h2>
<form method="post" class="form-body">
<% if ($draft) { =%>
<div class="form-preview">
<%== markdown $draft =%>
</div>
<% } =%>
<div class="form-field">
<% if (my $error = validation->error('author')) { =%>
<p class="field-with-error">Must be between <%= $error->[2] %>
@ -52,5 +57,9 @@
rows => 6
) %>
</div>
<div class="form-checkbox">
<%= check_box preview => 1, id => 'preview' %>
<%= label_for preview => 'Preview' %>
</div>
<button type="submit" class="form-button">Post</button>
</form>