1
0
mirror of https://github.com/krawieck/lemmur/ synced 2024-12-25 15:42:28 +01:00

ability to collapse a comment

This commit is contained in:
shilangyu 2020-09-19 12:01:12 +02:00
parent e938224df0
commit 016537d8d2

View File

@ -96,6 +96,7 @@ class Comment extends HookWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final selectable = useState(false); final selectable = useState(false);
final showRaw = useState(false); final showRaw = useState(false);
final collapsed = useState(false);
final comment = commentTree.comment; final comment = commentTree.comment;
@ -185,11 +186,25 @@ class Comment extends HookWidget {
)); ));
} else if (comment.removed) { } else if (comment.removed) {
return Flexible( return Flexible(
child: Text(
'comment deleted by moderator',
style: TextStyle(fontStyle: FontStyle.italic),
),
);
} else if (collapsed.value) {
return Flexible(
child: Opacity(
opacity: 0.3,
child: Text( child: Text(
'comment deleted by moderator', commentTree.comment.content,
style: TextStyle(fontStyle: FontStyle.italic), maxLines: 1,
)); overflow: TextOverflow.ellipsis,
),
),
);
} else { } else {
// TODO: bug, the text is selectable even when disabled after following these steps:
// make selectable > show raw > show fancy > make unselectable
return Flexible( return Flexible(
child: showRaw.value child: showRaw.value
? selectable.value ? selectable.value
@ -203,117 +218,123 @@ class Comment extends HookWidget {
} }
}(); }();
final actions = Row(children: [ final actions = collapsed.value
if (selectable.value && !comment.deleted && !comment.removed) ? Container()
_CommentAction( : Row(children: [
icon: Icons.content_copy, if (selectable.value && !comment.deleted && !comment.removed)
tooltip: 'copy', _CommentAction(
onPressed: () { icon: Icons.content_copy,
Clipboard.setData( tooltip: 'copy',
ClipboardData(text: commentTree.comment.content)) onPressed: () {
.then((_) => Scaffold.of(context).showSnackBar( Clipboard.setData(
SnackBar(content: Text('comment copied to clipboard')))); ClipboardData(text: commentTree.comment.content))
}), .then((_) => Scaffold.of(context).showSnackBar(SnackBar(
Spacer(), content: Text('comment copied to clipboard'))));
_CommentAction( }),
icon: Icons.more_horiz, Spacer(),
onPressed: () => _openMoreMenu(context), _CommentAction(
tooltip: 'more', icon: Icons.more_horiz,
), onPressed: () => _openMoreMenu(context),
_SaveComment(commentTree.comment), tooltip: 'more',
_CommentAction( ),
icon: Icons.reply, _SaveComment(commentTree.comment),
onPressed: _reply, _CommentAction(
tooltip: 'reply', icon: Icons.reply,
), onPressed: _reply,
_CommentAction( tooltip: 'reply',
icon: Icons.arrow_upward, ),
onPressed: () => _vote(VoteType.up), _CommentAction(
tooltip: 'upvote', icon: Icons.arrow_upward,
), onPressed: () => _vote(VoteType.up),
_CommentAction( tooltip: 'upvote',
icon: Icons.arrow_downward, ),
onPressed: () => _vote(VoteType.down), _CommentAction(
tooltip: 'downvote', icon: Icons.arrow_downward,
), onPressed: () => _vote(VoteType.down),
]); tooltip: 'downvote',
),
]);
return Column( return GestureDetector(
children: [ onLongPress: () => collapsed.value = !collapsed.value,
Container( child: Column(
child: Column( children: [
children: [ Container(
Row(children: [ child: Column(
if (comment.creatorAvatar != null) children: [
Padding( Row(children: [
padding: const EdgeInsets.only(right: 5), if (comment.creatorAvatar != null)
child: InkWell( Padding(
onTap: () => goToUser.byId( padding: const EdgeInsets.only(right: 5),
context, comment.instanceUrl, comment.creatorId), child: InkWell(
child: CachedNetworkImage( onTap: () => goToUser.byId(
imageUrl: comment.creatorAvatar, context, comment.instanceUrl, comment.creatorId),
height: 20, child: CachedNetworkImage(
width: 20, imageUrl: comment.creatorAvatar,
imageBuilder: (context, imageProvider) => Container( height: 20,
decoration: BoxDecoration( width: 20,
shape: BoxShape.circle, imageBuilder: (context, imageProvider) => Container(
image: DecorationImage( decoration: BoxDecoration(
fit: BoxFit.cover, shape: BoxShape.circle,
image: imageProvider, image: DecorationImage(
fit: BoxFit.cover,
image: imageProvider,
),
), ),
), ),
errorWidget: (_, __, ___) => Container(),
), ),
errorWidget: (_, __, ___) => Container(),
), ),
), ),
InkWell(
child: Text(username,
style: TextStyle(
color: Theme.of(context).accentColor,
)),
onTap: () => goToUser.byId(
context, comment.instanceUrl, comment.creatorId),
), ),
InkWell( if (isOP) _CommentTag('OP', Theme.of(context).accentColor),
child: Text(username, if (comment.banned) _CommentTag('BANNED', Colors.red),
style: TextStyle( if (comment.bannedFromCommunity)
color: Theme.of(context).accentColor, _CommentTag('BANNED FROM COMMUNITY', Colors.red),
)), Spacer(),
onTap: () => goToUser.byId( InkWell(
context, comment.instanceUrl, comment.creatorId), onTap: () => _showCommentInfo(context),
), child: Row(
if (isOP) _CommentTag('OP', Theme.of(context).accentColor), children: [
if (comment.banned) _CommentTag('BANNED', Colors.red), Text(comment.score.toString()),
if (comment.bannedFromCommunity) Text(' · '),
_CommentTag('BANNED FROM COMMUNITY', Colors.red), Text(timeago.format(comment.published)),
Spacer(), ],
InkWell( ),
onTap: () => _showCommentInfo(context), )
child: Row( ]),
children: [ SizedBox(height: 10),
Text(comment.score.toString()), Row(children: [body]),
Text(' · '), SizedBox(height: 5),
Text(timeago.format(comment.published)), actions,
], ],
), ),
) padding: EdgeInsets.all(10),
]), margin: EdgeInsets.only(left: indent > 1 ? (indent - 1) * 5.0 : 0),
SizedBox(height: 10), decoration: BoxDecoration(
Row(children: [body]), border: Border(
SizedBox(height: 5), left: indent > 0
actions, ? BorderSide(
], color: colors[indent % colors.length], width: 5)
: BorderSide.none,
top: BorderSide(width: 0.2))),
), ),
padding: EdgeInsets.all(10), if (!collapsed.value)
margin: EdgeInsets.only(left: indent > 1 ? (indent - 1) * 5.0 : 0), for (final c in commentTree.children)
decoration: BoxDecoration( Comment(
border: Border( c,
left: indent > 0 indent: indent + 1,
? BorderSide( postCreatorId: postCreatorId,
color: colors[indent % colors.length], width: 5) ),
: BorderSide.none, ],
top: BorderSide(width: 0.2))), ),
),
for (final c in commentTree.children)
Comment(
c,
indent: indent + 1,
postCreatorId: postCreatorId,
),
],
); );
} }
} }