summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-09-07 09:37:47 +0200
committerYorhel <git@yorhel.nl>2020-09-07 09:50:57 +0200
commitb17f2a7ed233b21266609cab8fe523ee2a4ca782 (patch)
tree9d47e0bc358a31ffc92dff1c21c5a69bfcc4c9d0 /lib
parent4d112ace3c9f088aab5c9da6b70b9b4498a36008 (diff)
Reviews: Bunch of minor changes
- Show vote counts on reviews again, but only for mods - Don't expand vndbids when submitting or editing a mini-review, defer that to the displaying part so that the mini-reviews text won't exceed the character length (...though the displayed review can exceed it this way, oh well) - Hide vote button when review is hidden by spoiler button
Diffstat (limited to 'lib')
-rw-r--r--lib/VNWeb/Reviews/Edit.pm2
-rw-r--r--lib/VNWeb/Reviews/Lib.pm21
-rw-r--r--lib/VNWeb/Reviews/Page.pm9
-rw-r--r--lib/VNWeb/Reviews/VNTab.pm7
4 files changed, 31 insertions, 8 deletions
diff --git a/lib/VNWeb/Reviews/Edit.pm b/lib/VNWeb/Reviews/Edit.pm
index 5ff083ce..0f764441 100644
--- a/lib/VNWeb/Reviews/Edit.pm
+++ b/lib/VNWeb/Reviews/Edit.pm
@@ -71,7 +71,7 @@ elm_api ReviewsEdit => $FORM_OUT, $FORM_IN, sub {
validate_dbid 'SELECT id FROM releases WHERE id IN', $data->{rid} if defined $data->{rid};
die "Review too long" if !$data->{isfull} && length $data->{text} > 800;
- $data->{text} = bb_subst_links $data->{text};
+ $data->{text} = bb_subst_links $data->{text} if $data->{isfull};
if($id) {
$data->{lastmod} = sql 'NOW()';
diff --git a/lib/VNWeb/Reviews/Lib.pm b/lib/VNWeb/Reviews/Lib.pm
new file mode 100644
index 00000000..2872966c
--- /dev/null
+++ b/lib/VNWeb/Reviews/Lib.pm
@@ -0,0 +1,21 @@
+package VNWeb::Reviews::Lib;
+
+use VNWeb::Prelude;
+use Exporter 'import';
+our @EXPORT = qw/reviews_vote_ reviews_format/;
+
+sub reviews_vote_ {
+ my($w) = @_;
+ span_ sub {
+ elm_ 'Reviews.Vote' => $VNWeb::Reviews::Elm::VOTE_OUT, {%$w, mod => auth->permBoardmod} if auth && ($w->{can} || auth->permBoardmod);
+ b_ class => 'grayedout', sprintf ' %d/%d', $w->{c_up}, $w->{c_down} if auth->permBoardmod;
+ }
+}
+
+# Mini-reviews don't expand vndbids on submission, so they need an extra bb_subst_links() pass.
+sub reviews_format {
+ my($w, @opt) = @_;
+ bb_format($w->{isfull} ? $w->{text} : bb_subst_links($w->{text}), @opt);
+}
+
+1;
diff --git a/lib/VNWeb/Reviews/Page.pm b/lib/VNWeb/Reviews/Page.pm
index 72bad7b1..8822b2ed 100644
--- a/lib/VNWeb/Reviews/Page.pm
+++ b/lib/VNWeb/Reviews/Page.pm
@@ -2,6 +2,7 @@ package VNWeb::Reviews::Page;
use VNWeb::Prelude;
use VNWeb::Releases::Lib;
+use VNWeb::Reviews::Lib;
my $COMMENT = form_compile any => {
@@ -65,12 +66,12 @@ sub review_ {
} if $w->{spoiler};
tr_ @spoil, sub {
td_ 'Review';
- td_ sub { lit_ bb_format $w->{text} }
+ td_ sub { lit_ reviews_format $w }
};
- tr_ sub {
+ tr_ @spoil, sub {
td_ '';
td_ style => 'text-align: right', sub {
- elm_ 'Reviews.Vote' => $VNWeb::Reviews::Elm::VOTE_OUT, {%$w, mod => auth->permBoardmod} if auth && ($w->{can} || auth->permBoardmod);
+ reviews_vote_ $w;
};
};
}
@@ -80,7 +81,7 @@ sub review_ {
TUWF::get qr{/$RE{wid}(?:(?<sep>[\./])$RE{num})?}, sub {
my($id, $sep, $num) = (tuwf->capture('id'), tuwf->capture('sep')||'', tuwf->capture('num'));
my $w = tuwf->dbRowi(
- 'SELECT r.id, r.vid, r.rid, r.isfull, r.text, r.spoiler, COALESCE(c.count,0) AS count, r.c_flagged, uv.vote, rm.id IS NULL AS can
+ 'SELECT r.id, r.vid, r.rid, r.isfull, r.text, r.spoiler, COALESCE(c.count,0) AS count, r.c_flagged, r.c_up, r.c_down, uv.vote, rm.id IS NULL AS can
, v.title, rel.title AS rtitle, rel.original AS roriginal, rel.type AS rtype, rv.vote AS my, COALESCE(rv.overrule,false) AS overrule
, ', sql_user(), ',', sql_totime('r.date'), 'AS date,', sql_totime('r.lastmod'), 'AS lastmod
FROM reviews r
diff --git a/lib/VNWeb/Reviews/VNTab.pm b/lib/VNWeb/Reviews/VNTab.pm
index 20304315..92d36a40 100644
--- a/lib/VNWeb/Reviews/VNTab.pm
+++ b/lib/VNWeb/Reviews/VNTab.pm
@@ -1,6 +1,7 @@
package VNWeb::Reviews::VNTab;
use VNWeb::Prelude;
+use VNWeb::Reviews::Lib;
sub reviews_ {
@@ -8,7 +9,7 @@ sub reviews_ {
# TODO: Better order, pagination, option to show flagged reviews
my $lst = tuwf->dbAlli(
- 'SELECT r.id, r.rid, r.text, r.spoiler, r.c_count, uv.vote, rv.vote AS my, COALESCE(rv.overrule,false) AS overrule, NOT r.isfull AND rm.id IS NULL AS can
+ 'SELECT r.id, r.rid, r.text, r.spoiler, r.c_count, r.c_up, r.c_down, uv.vote, rv.vote AS my, COALESCE(rv.overrule,false) AS overrule, NOT r.isfull AND rm.id IS NULL AS can
, ', sql_totime('r.date'), 'AS date, ', sql_user(), '
FROM reviews r
LEFT JOIN users u ON r.uid = u.id
@@ -40,7 +41,7 @@ sub reviews_ {
a_ href => "/report/$r->{id}", 'report';
txt_ '>';
};
- my $html = bb_format $r->{text}, maxlength => $mini ? undef : 700;
+ my $html = reviews_format $r, maxlength => $mini ? undef : 700;
$html .= '...' if !$mini;
if($r->{spoiler}) {
label_ class => 'review_spoil', sub {
@@ -55,7 +56,7 @@ sub reviews_ {
div_ sub {
a_ href => "/$r->{id}#review", 'Full review ยป' if !$mini;
a_ href => "/$r->{id}#threadstart", $r->{c_count} == 1 ? '1 comment' : "$r->{c_count} comments";
- elm_ 'Reviews.Vote' => $VNWeb::Reviews::Elm::VOTE_OUT, {%$r, mod => auth->permBoardmod} if auth && ($r->{can} || auth->permBoardmod);
+ reviews_vote_ $r;
};
} for @$lst;
}