From 5435678de82920a9f808d6b5412bc66fa59ffd10 Mon Sep 17 00:00:00 2001 From: swag Date: Fri, 16 Sep 2022 21:46:56 -0400 Subject: [PATCH] Implement name persistence instead of anything actually on my TODOs --- README.md | 2 +- lib/PostText.pm | 4 ++++ templates/post.html.ep | 6 +++++- templates/thread_id.html.ep | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd2d3f8..6b14773 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Run the tests locally (against development environment) ## TODOs -1. I think I should revist the Post and Remark routes... +1. Should replace all reference to 'name' to 'author', getting confused 1. Grow into full blown Mojo? 1. More granular tests 1. Document post_text.conf (whoopsie) diff --git a/lib/PostText.pm b/lib/PostText.pm index 067c967..60b3d22 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -94,6 +94,8 @@ sub startup($self) { $thread_body ); + $c->session(author => $thread_author); + return $c->redirect_to('list'); } } @@ -123,6 +125,8 @@ sub startup($self) { $remark_body ); + $c->session(author => $remark_name); + return $c->redirect_to( 'thread_page', {thread_id => $thread_id} diff --git a/templates/post.html.ep b/templates/post.html.ep index aef4b41..32be5c6 100644 --- a/templates/post.html.ep +++ b/templates/post.html.ep @@ -4,7 +4,11 @@
<%= label_for name => 'Author' %> - <%= text_field name =>'Anonymous', maxlength => 63, minlength => 1 %> + <% if (my $previous_name = session->{'author'}) { %> + <%= text_field name => $previous_name, maxlength => 63, minlength => 1 %> + <% } else { %> + <%= text_field name => 'Anonymous', maxlength => 63, minlength => 1 %> + <% } %> <% if (my $error = validation->error('name')) { =%>

Invalid name: 1 to 63 characters please.

<% } =%> diff --git a/templates/thread_id.html.ep b/templates/thread_id.html.ep index 2544146..e959801 100644 --- a/templates/thread_id.html.ep +++ b/templates/thread_id.html.ep @@ -4,7 +4,11 @@
<%= label_for name => 'Author' %> - <%= text_field name =>'Anonymous', maxlength => 63, minlength => 1 %> + <% if (my $previous_name = session->{'author'}) { %> + <%= text_field name => $previous_name, maxlength => 63, minlength => 1 %> + <% } else { %> + <%= text_field name => 'Anonymous', maxlength => 63, minlength => 1 %> + <% } %> <% if (my $error = validation->error('name')) { =%>

Invalid name: 1 to 63 characters please.

<% } =%>