diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index 7059f37..34f7e38 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -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; } diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 2d22a80..9564910 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -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) { diff --git a/public/robots.txt b/public/robots.txt index d8e68f5..55a3c64 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -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/ diff --git a/t/preview.t b/t/preview.t index a542331..70e248e 100644 --- a/t/preview.t +++ b/t/preview.t @@ -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; diff --git a/templates/thread/create.html.ep b/templates/thread/create.html.ep index 5d4bfba..734d194 100644 --- a/templates/thread/create.html.ep +++ b/templates/thread/create.html.ep @@ -11,6 +11,11 @@ % end

<%= title %>

+ <% if ($draft) { =%> +
+ <%== markdown $draft =%> +
+ <% } =%>
<% if (my $error = validation->error('author')) { =%>

Must be between <%= $error->[2] %> @@ -52,5 +57,9 @@ rows => 6 ) %>

+
+ <%= check_box preview => 1, id => 'preview' %> + <%= label_for preview => 'Preview' %> +