summaryrefslogtreecommitdiff
path: root/lib/VNWeb/Discussions/Thread.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-12-05 19:26:39 +0100
committerYorhel <git@yorhel.nl>2019-12-05 19:27:15 +0100
commit6487d1e89b14a4c85bb47c03fbe4d7e2f37e73d3 (patch)
treecd010ce4994048c379abf6ef256543b63f8c9f3a /lib/VNWeb/Discussions/Thread.pm
parent0c97101f1de3025de06a5f516811b9b7844a2abc (diff)
v2rw: Convert thread reply form to Elm
So we can apply the new preview functionality. I got rid of the "Go advanced" button, because there's really nothing advanced about it.
Diffstat (limited to 'lib/VNWeb/Discussions/Thread.pm')
-rw-r--r--lib/VNWeb/Discussions/Thread.pm50
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm
index 30827aaa..c81e02a9 100644
--- a/lib/VNWeb/Discussions/Thread.pm
+++ b/lib/VNWeb/Discussions/Thread.pm
@@ -29,6 +29,23 @@ my $POLL_IN = form_compile any => {
elm_form 'DiscussionsPoll' => $POLL_OUT, $POLL_IN;
+
+my $REPLY_OUT = form_compile any => {
+ tid => { id => 1 },
+ newurl => { },
+};
+
+
+my $REPLY_IN = form_compile any => {
+ tid => { id => 1 },
+ msg => { maxlength => 32768 }
+};
+
+
+elm_form 'DiscussionsReply' => $REPLY_OUT, $REPLY_IN;
+
+
+
sub metabox_ {
my($t) = @_;
div_ class => 'mainbox', sub {
@@ -96,22 +113,7 @@ sub reply_ {
my($t, $page) = @_;
return if $t->{count} > $page*25;
if(can_edit t => $t) {
- # TODO: Elmify
- form_ action => "/t$t->{id}/reply", method => 'post', 'accept-charset' => 'UTF-8', sub {
- div_ class => 'mainbox', sub {
- fieldset_ class => 'submit', sub {
- input_ type => 'hidden', class => 'hidden', name => 'formcode', value => auth->csrftoken;
- h2_ sub {
- txt_ 'Quick reply';
- b_ class => 'standout', ' (English please!)';
- };
- textarea_ name => 'msg', id => 'msg', rows => 4, cols => 50, '';
- br_;
- input_ type => 'submit', value => 'Reply', class => 'submit';
- input_ type => 'submit', value => 'Go advanced...', class => 'submit', name => 'fullreply';
- }
- }
- }
+ elm_ 'Discussions.Reply' => $REPLY_OUT, { tid => $t->{id}, newurl => post_url($t->{id}, $t->{count}+1) };
} else {
div_ class => 'mainbox', sub {
h1_ 'Reply';
@@ -183,7 +185,7 @@ json_api qr{/t/pollvote.json}, $POLL_IN, sub {
my($data) = @_;
return elm_Unauth if !auth;
- my $t = tuwf->dbRowi('SELECT poll_question, poll_max_options FROM threads WHERE id =', \$data->{tid});
+ my $t = tuwf->dbRowi('SELECT poll_question, poll_max_options FROM threads t WHERE id =', \$data->{tid}, 'AND', sql_visible_threads());
return tuwf->resNotFound if !$t->{poll_question};
die 'Too many options' if $data->{options}->@* > $t->{poll_max_options};
@@ -194,4 +196,18 @@ json_api qr{/t/pollvote.json}, $POLL_IN, sub {
elm_Success
};
+
+json_api qr{/t/reply.json}, $REPLY_IN, sub {
+ my($data) = @_;
+ my $t = tuwf->dbRowi('SELECT id, locked, count FROM threads t WHERE id =', \$data->{tid}, 'AND', sql_visible_threads());
+ return tuwf->resNotFound if !$t->{id};
+ return elm_Unauth if !can_edit t => $t;
+
+ my $num = $t->{count}+1;
+ my $msg = bb_subst_links $data->{msg};
+ tuwf->dbExeci('INSERT INTO threads_posts (tid, num, uid, msg) VALUES (', sql_comma(\$t->{id}, \$num, \auth->uid, \$msg), ')');
+ tuwf->dbExeci('UPDATE threads SET count =', \$num, 'WHERE id =', \$t->{id});
+ elm_Success
+};
+
1;