diff options
author | Yorhel <git@yorhel.nl> | 2019-12-10 10:32:37 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-12-10 10:32:39 +0100 |
commit | 5075f0ef4573fa95252c1a91b62239cc9b6347bb (patch) | |
tree | fcc6be6d5cad66dc1af217a4f6b3fe733df60945 /lib | |
parent | fa7b9e6a14a1597516738a75b6dfb9d326be7d48 (diff) |
Elm: Add Redirect response + fix redirect to last post on reply
Fixes https://vndb.org/t2520/14#334 - I originally had some trouble to
do this because `load` doesn't actually reload the page if you're just
changing the hash. The `reload` following it handles that now.
The Redirect response is just cleanup, there's several places that could
benefit form it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNWeb/Discussions/Thread.pm | 13 | ||||
-rw-r--r-- | lib/VNWeb/Docs/Edit.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/Elm.pm | 2 | ||||
-rw-r--r-- | lib/VNWeb/Staff/Edit.pm | 2 |
4 files changed, 6 insertions, 13 deletions
diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm index 507d8605..d783a4bd 100644 --- a/lib/VNWeb/Discussions/Thread.pm +++ b/lib/VNWeb/Discussions/Thread.pm @@ -30,19 +30,12 @@ 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; +elm_form 'DiscussionsReply' => undef, $REPLY_IN; @@ -113,7 +106,7 @@ sub reply_ { my($t, $page) = @_; return if $t->{count} > $page*25; if(can_edit t => $t) { - elm_ 'Discussions.Reply' => $REPLY_OUT, { tid => $t->{id}, newurl => post_url($t->{id}, $t->{count}+1) }; + elm_ 'Discussions.Reply' => undef, $t->{id}*1; } else { div_ class => 'mainbox', sub { h1_ 'Reply'; @@ -207,7 +200,7 @@ json_api qr{/t/reply\.json}, $REPLY_IN, sub { 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 + elm_Redirect post_url $t->{id}, $num, 'last'; }; 1; diff --git a/lib/VNWeb/Docs/Edit.pm b/lib/VNWeb/Docs/Edit.pm index fd3ce958..65aa6442 100644 --- a/lib/VNWeb/Docs/Edit.pm +++ b/lib/VNWeb/Docs/Edit.pm @@ -42,7 +42,7 @@ json_api qr{/d/edit\.json}, $FORM_IN, sub { return elm_Unchanged if !form_changed $FORM_CMP, $data, $doc; my($id,undef,$rev) = db_edit d => $doc->{id}, $data; - elm_Changed $id, $rev; + elm_Redirect "/d$id.$rev"; }; diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm index 6fa710f9..d8e9a73a 100644 --- a/lib/VNWeb/Elm.pm +++ b/lib/VNWeb/Elm.pm @@ -31,8 +31,8 @@ our @EXPORT = qw/ my %apis = ( Unauth => [], # Not authorized Unchanged => [], # No changes - Changed => [ { id => 1 }, { uint => 1 } ], # [ id, chrev]; DB entry has been successfully changed Success => [], + Redirect => [{}], # Redirect to the given URL CSRF => [], # Invalid CSRF token Invalid => [], # POST data did not validate the schema Content => [{}], # Rendered HTML content (for markdown/bbcode APIs) diff --git a/lib/VNWeb/Staff/Edit.pm b/lib/VNWeb/Staff/Edit.pm index f0fc9d7c..2feb52c1 100644 --- a/lib/VNWeb/Staff/Edit.pm +++ b/lib/VNWeb/Staff/Edit.pm @@ -97,7 +97,7 @@ json_api qr{/s/edit\.json}, $FORM_IN, sub { return elm_Unchanged if !$new && !form_changed $FORM_CMP, $data, $e; my($id,undef,$rev) = db_edit s => $e->{id}, $data; - elm_Changed $id, $rev; + elm_Redirect "/s$id.$rev"; }; 1; |